Advertisement
xmd79

mycombo trendlines && pivots

Jan 15th, 2023
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.14 KB | None | 0 0
  1.  
  2.  
  3. //@version=5
  4. indicator('Trend Lines', overlay=true)
  5. lb = input.int(13, title='Left Bars', minval=1)
  6. rb = input.int(21, title='Right Bars', minval=1)
  7. showpivot = input(true, title='Show Pivot Points')
  8. chdashed = input(true, title='Show Old Line as Dashed')
  9.  
  10. mb = lb + rb + 1
  11.  
  12. float top = na
  13. float bot = na
  14. highestbars_1 = ta.highestbars(high, mb) // Pivot High
  15. iff_1 = highestbars_1 == -rb ? high[rb] : na
  16. top := not na(high[mb]) ? iff_1 : na
  17. lowestbars_1 = ta.lowestbars(low, mb) // Pivot Low
  18. iff_2 = lowestbars_1 == -rb ? low[rb] : na
  19. bot := not na(low[mb]) ? iff_2 : na
  20.  
  21. plotshape(top and showpivot, text='[PH]', style=shape.labeldown, color=color.new(color.white, 0), textcolor=color.new(color.black, 0), location=location.abovebar, offset=-rb)
  22. plotshape(bot and showpivot, text='[PL]', style=shape.labeldown, color=color.new(color.white, 0), textcolor=color.new(color.black, 0), location=location.belowbar, offset=-rb)
  23.  
  24. ltop = ta.valuewhen(top, top, 1)
  25. bst = 0
  26. bst := top ? 1 : nz(bst[1]) + 1
  27. float t_angle = 0.0
  28. t_angle := t_angle[1]
  29. if not na(ltop) and not na(top)
  30. line tline = na
  31. if ltop > top
  32. tline := line.new(bar_index - bst[1] - rb, high[bst[1] + rb], bar_index - rb, high[rb], color=color.red, extend=extend.right)
  33. t_angle := (high[bst[1] + rb] - high[rb]) / bst[1]
  34. if t_angle < t_angle[1] and t_angle[1] != 0
  35. line.set_extend(tline[1], extend=extend.none)
  36. if t_angle > t_angle[1] and t_angle[1] != 0
  37. line.set_extend(tline, extend=extend.none)
  38. if ltop <= top
  39. t_angle := 0.0
  40. t_angle
  41. if chdashed
  42. line.set_style(tline[1], style=line.style_dashed)
  43.  
  44. lbot = ta.valuewhen(bot, bot, 1)
  45. bsb = 0
  46. bsb := bot ? 1 : nz(bsb[1]) + 1
  47. float b_angle = 0.0
  48. b_angle := b_angle[1]
  49. if not na(lbot) and not na(bot)
  50. line bline = na
  51. if lbot < bot
  52. bline := line.new(bar_index - bsb[1] - rb, low[bsb[1] + rb], bar_index - rb, low[rb], color=color.blue, extend=extend.right)
  53. b_angle := (low[bsb[1] + rb] - low[rb]) / bsb[1]
  54. if b_angle > b_angle[1] and b_angle[1] != 0
  55. line.set_extend(bline[1], extend=extend.none)
  56. if b_angle < b_angle[1] and b_angle[1] != 0
  57. line.set_extend(bline, extend=extend.none)
  58. if lbot >= bot
  59. b_angle := 0.0
  60. b_angle
  61. if chdashed
  62. line.set_style(bline[1], style=line.style_dashed)
  63.  
  64. //end of this part
  65.  
  66. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  67. //@version=5
  68.  
  69.  
  70. // -----------------------------------
  71. groupTD = ""
  72. // -----------------------------------
  73.  
  74. lastN = input.string("6 to 9", title="Show", options=["6 to 9", "7, 8 and 9", "8 and 9", "Only 9", "None"], inline="TD1", group=groupTD)
  75. showSR = input(false, title="Show Support and Resistance", inline="TD", group=groupTD)
  76.  
  77. Count13 = input(true, title="Countd. 13 |", inline="TD1", group=groupTD)
  78. CountdA13 = input(true, title="Aggr. 13", inline="TD1", group=groupTD)
  79.  
  80. locB = input.string("Below", title="Label: Buy" , options=["Above", "Below"], inline="TD5", group=groupTD)
  81. locA = input.string("Above", title="Sell" , options=["Above", "Below"], inline="TD5", group=groupTD)
  82.  
  83. locBc = locB == "Above" ? location.abovebar : locB == "Below" ? location.belowbar : na
  84. locAc = locA == "Above" ? location.abovebar : locA == "Below" ? location.belowbar : na
  85.  
  86. // -----------------------------------
  87.  
  88. i_style0 = "Label"
  89. i_style1 = "Arrow"
  90. i_style2 = "Triangle"
  91. i_style3 = "Circle"
  92. i_style4 = "Cross"
  93.  
  94. Bstyle = input.string(i_style0, title="Style: Buy" , options=[i_style0, i_style1, i_style2, i_style3, i_style4], inline="TD6", group=groupTD)
  95. Sstyle = input.string(i_style0, title="Sell" , options=[i_style0, i_style1, i_style2, i_style3, i_style4], inline="TD6", group=groupTD)
  96.  
  97. f_getStyleB(_inputStyle) =>
  98. _return = _inputStyle == i_style1 ? shape.arrowup :
  99. _inputStyle == i_style2 ? shape.triangleup :
  100. _inputStyle == i_style3 ? shape.circle :
  101. _inputStyle == i_style4 ? shape.cross : shape.labelup
  102. _return
  103.  
  104. f_getStyleS(_inputStyle) =>
  105. _return = _inputStyle == i_style1 ? shape.arrowdown :
  106. _inputStyle == i_style2 ? shape.triangledown :
  107. _inputStyle == i_style3 ? shape.circle :
  108. _inputStyle == i_style4 ? shape.xcross : shape.labeldown
  109. _return
  110.  
  111. // -----------------------------------
  112.  
  113. sellSet = 0
  114. sellSet := close > close[4] ? sellSet[1] == 9 ? 1 : sellSet[1] + 1 : 0
  115.  
  116. buySet = 0
  117. buySet := close < close[4] ? buySet[1] == 9 ? 1 : buySet[1] + 1 : 0
  118.  
  119. // -----------------------------------
  120.  
  121. highest9 = ta.highest(9)
  122. highTrendLine = 0.0
  123. highTrendLine := buySet == 9 ? highest9 : close > highTrendLine[1] ? 0 : highTrendLine[1]
  124.  
  125. lowest9 = ta.lowest(9)
  126. lowTrendLine = 0.0
  127. lowTrendLine := sellSet == 9 ? lowest9 : close < lowTrendLine[1] ? 0 : lowTrendLine[1]
  128.  
  129. S_color = input.color(color.new(#90EE90, 25), title="|", inline="TD", group=groupTD)
  130. R_color = input.color(color.new(#E21B22, 25), title="", inline="TD", group=groupTD)
  131.  
  132. plot(showSR and lowTrendLine > 0 ? lowTrendLine : na, style=plot.style_circles, linewidth=1, color=S_color, title="Support")
  133. plot(showSR and highTrendLine > 0 ? highTrendLine : na, style=plot.style_circles, linewidth=1, color=R_color, title="Resistance")
  134.  
  135. // -----------------------------------
  136.  
  137. buyCountd = 0.0
  138. buyCountd8Close = 0.0
  139. isBuyCountd = close < low[2]
  140. nonQBuy13 = isBuyCountd and math.abs(buyCountd[1]) == 12 and low > buyCountd8Close[1]
  141. buyCountd := buySet == 9 ? isBuyCountd ? 1 : 0 : sellSet == 9 or highTrendLine == 0 ? 14 : nonQBuy13 ? -12 : isBuyCountd ? math.abs(buyCountd[1]) + 1 : -math.abs(buyCountd[1])
  142. nonQBuy13 := nonQBuy13 and buyCountd == -12
  143. buyCountd8Close := buyCountd == 8 ? close : buyCountd8Close[1]
  144.  
  145. sellCountd = 0.0
  146. sellCountd8Close = 0.0
  147. isSellCountd = close > high[2]
  148. nonQSell13 = isSellCountd and math.abs(sellCountd[1]) == 12 and high < sellCountd8Close[1]
  149. sellCountd := sellSet == 9 ? isSellCountd ? 1 : 0 : buySet == 9 or lowTrendLine == 0 ? 14 : nonQSell13 ? -12 : isSellCountd ? math.abs(sellCountd[1]) + 1 : -math.abs(sellCountd[1])
  150. nonQSell13 := nonQSell13 and sellCountd == -12
  151. sellCountd8Close := sellCountd == 8 ? close : sellCountd8Close[1]
  152.  
  153. isAggressiveBuy = low < low[2]
  154. aggressiveBuy = 0.0
  155. aggressiveBuy := buySet == 9 ? isAggressiveBuy ? 1 : 0 : sellSet == 9 or highTrendLine == 0 ? 14 : isAggressiveBuy ? math.abs(aggressiveBuy[1]) + 1 : -math.abs(aggressiveBuy[1])
  156.  
  157. isAggressiveSell = high > high[2]
  158. aggressiveSell = 0.0
  159. aggressiveSell := sellSet == 9 ? isAggressiveSell ? 1 : 0 : buySet == 9 or lowTrendLine == 0 ? 14 : isAggressiveSell ? math.abs(aggressiveSell[1]) + 1 : -math.abs(aggressiveSell[1])
  160.  
  161. // -----------------------------------
  162.  
  163. color_btext = input.color(color.new(color.white , 0), title="Colors: Buy", inline="C", group=groupTD)
  164. color_stext = input.color(color.new(color.white , 0), title="Sell", inline="C", group=groupTD)
  165.  
  166. color_b6 = input.color(color.new(#77F1B0 , 0), title="6", inline="CB", group=groupTD)
  167. color_b7 = input.color(color.new(#00ADAD , 0), title="7", inline="CB", group=groupTD)
  168. color_b8 = input.color(color.new(#0067FF , 0), title="8", inline="CB", group=groupTD)
  169. color_b9 = input.color(color.new(#0014C4 , 0), title="9", inline="CB", group=groupTD)
  170.  
  171. color_s6 = input.color(color.new(color.yellow , 0), title="6", inline="CS", group=groupTD)
  172. color_s7 = input.color(color.new(color.orange , 0), title="7", inline="CS", group=groupTD)
  173. color_s8 = input.color(color.new(color.red , 0), title="8", inline="CS", group=groupTD)
  174. color_s9 = input.color(color.new(color.maroon , 0), title="9", inline="CS", group=groupTD)
  175.  
  176. color_b13 = input.color(color.new(color.blue , 0), title="13", inline="CB", group=groupTD)
  177. color_s13 = input.color(color.new(#d69d00 , 0), title="13", inline="CS", group=groupTD)
  178. color_bA13 = input.color(color.new(#6400d6 , 0), title="A13", inline="CB", group=groupTD)
  179. color_sA13 = input.color(color.new(#ff8629 , 0), title="A13", inline="CS", group=groupTD)
  180.  
  181. // -----------------------------------
  182.  
  183. plotshape(lastN == "6 to 9" ?
  184. buySet == 6 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b6, text="", title="lb6", textcolor=color_btext)
  185. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" ?
  186. buySet == 7 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b7, text="", title="lb7", textcolor=color_btext)
  187. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" ?
  188. buySet == 8 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b8, text="", title="lb8", textcolor=color_btext)
  189. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" or lastN == "Only 9" ?
  190. buySet == 9 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b9, text="9", title="lb9", textcolor=color_btext)
  191.  
  192. plotshape(lastN == "6 to 9" ?
  193. sellSet == 6 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s6, text="", title="ls6", textcolor=color_stext)
  194. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" ?
  195. sellSet == 7 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s7, text="", title="ls7", textcolor=color_stext)
  196. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" ?
  197. sellSet == 8 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s8, text="", title="ls8", textcolor=color_stext)
  198. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" or lastN == "Only 9" ?
  199. sellSet == 9 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s9, text="9", title="ls9", textcolor=color_stext)
  200.  
  201. plotshape(Count13 ?
  202. sellCountd == 13 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s13, text="13", title="lsc13", textcolor=color_stext)
  203. plotshape(Count13 ?
  204. buyCountd == 13 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b13, text="13", title="lbc13", textcolor=color_btext)
  205.  
  206. plotshape(CountdA13 ?
  207. aggressiveBuy == 13 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_bA13, text="a13", title="lbc13", textcolor=color_btext)
  208. plotshape(CountdA13 ?
  209. aggressiveSell == 13 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_sA13, text="a13", title="lsc13", textcolor=color_stext)
  210.  
  211. // -----------------------------------
  212.  
  213. count9 = buySet == 9 or sellSet == 9
  214. count13 = buyCountd == 13 or sellCountd == 13
  215. counta13 = aggressiveBuy == 13 or aggressiveSell == 13
  216. count913 = count9 or count13
  217.  
  218. alertcondition(count9 , title="TD 9 Alert" , message="TD Seq: 9 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  219. alertcondition(count13 , title="TD 13 Alert" , message="TD Seq: 13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  220. alertcondition(counta13 , title="TD a13 Alert" , message="TD Seq: a13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  221. alertcondition(count913 , title="TD 9 and 13 Alert" , message="TD Seq: 9, 13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  222.  
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement