Advertisement
xmd79

TD lite • Yata

Jan 15th, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. //@version=5
  3.  
  4. indicator("TD lite • Yata",
  5. overlay = true,
  6. timeframe = "")
  7.  
  8. // -----------------------------------
  9. groupTD = ""
  10. // -----------------------------------
  11.  
  12. 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)
  13. showSR = input(false, title="Show Support and Resistance", inline="TD", group=groupTD)
  14.  
  15. Count13 = input(true, title="Countd. 13 |", inline="TD1", group=groupTD)
  16. CountdA13 = input(true, title="Aggr. 13", inline="TD1", group=groupTD)
  17.  
  18. locB = input.string("Below", title="Label: Buy" , options=["Above", "Below"], inline="TD5", group=groupTD)
  19. locA = input.string("Above", title="Sell" , options=["Above", "Below"], inline="TD5", group=groupTD)
  20.  
  21. locBc = locB == "Above" ? location.abovebar : locB == "Below" ? location.belowbar : na
  22. locAc = locA == "Above" ? location.abovebar : locA == "Below" ? location.belowbar : na
  23.  
  24. // -----------------------------------
  25.  
  26. i_style0 = "Label"
  27. i_style1 = "Arrow"
  28. i_style2 = "Triangle"
  29. i_style3 = "Circle"
  30. i_style4 = "Cross"
  31.  
  32. Bstyle = input.string(i_style0, title="Style: Buy" , options=[i_style0, i_style1, i_style2, i_style3, i_style4], inline="TD6", group=groupTD)
  33. Sstyle = input.string(i_style0, title="Sell" , options=[i_style0, i_style1, i_style2, i_style3, i_style4], inline="TD6", group=groupTD)
  34.  
  35. f_getStyleB(_inputStyle) =>
  36. _return = _inputStyle == i_style1 ? shape.arrowup :
  37. _inputStyle == i_style2 ? shape.triangleup :
  38. _inputStyle == i_style3 ? shape.circle :
  39. _inputStyle == i_style4 ? shape.cross : shape.labelup
  40. _return
  41.  
  42. f_getStyleS(_inputStyle) =>
  43. _return = _inputStyle == i_style1 ? shape.arrowdown :
  44. _inputStyle == i_style2 ? shape.triangledown :
  45. _inputStyle == i_style3 ? shape.circle :
  46. _inputStyle == i_style4 ? shape.xcross : shape.labeldown
  47. _return
  48.  
  49. // -----------------------------------
  50.  
  51. sellSet = 0
  52. sellSet := close > close[4] ? sellSet[1] == 9 ? 1 : sellSet[1] + 1 : 0
  53.  
  54. buySet = 0
  55. buySet := close < close[4] ? buySet[1] == 9 ? 1 : buySet[1] + 1 : 0
  56.  
  57. // -----------------------------------
  58.  
  59. highest9 = ta.highest(9)
  60. highTrendLine = 0.0
  61. highTrendLine := buySet == 9 ? highest9 : close > highTrendLine[1] ? 0 : highTrendLine[1]
  62.  
  63. lowest9 = ta.lowest(9)
  64. lowTrendLine = 0.0
  65. lowTrendLine := sellSet == 9 ? lowest9 : close < lowTrendLine[1] ? 0 : lowTrendLine[1]
  66.  
  67. S_color = input.color(color.new(#90EE90, 25), title="|", inline="TD", group=groupTD)
  68. R_color = input.color(color.new(#E21B22, 25), title="", inline="TD", group=groupTD)
  69.  
  70. plot(showSR and lowTrendLine > 0 ? lowTrendLine : na, style=plot.style_circles, linewidth=1, color=S_color, title="Support")
  71. plot(showSR and highTrendLine > 0 ? highTrendLine : na, style=plot.style_circles, linewidth=1, color=R_color, title="Resistance")
  72.  
  73. // -----------------------------------
  74.  
  75. buyCountd = 0.0
  76. buyCountd8Close = 0.0
  77. isBuyCountd = close < low[2]
  78. nonQBuy13 = isBuyCountd and math.abs(buyCountd[1]) == 12 and low > buyCountd8Close[1]
  79. buyCountd := buySet == 9 ? isBuyCountd ? 1 : 0 : sellSet == 9 or highTrendLine == 0 ? 14 : nonQBuy13 ? -12 : isBuyCountd ? math.abs(buyCountd[1]) + 1 : -math.abs(buyCountd[1])
  80. nonQBuy13 := nonQBuy13 and buyCountd == -12
  81. buyCountd8Close := buyCountd == 8 ? close : buyCountd8Close[1]
  82.  
  83. sellCountd = 0.0
  84. sellCountd8Close = 0.0
  85. isSellCountd = close > high[2]
  86. nonQSell13 = isSellCountd and math.abs(sellCountd[1]) == 12 and high < sellCountd8Close[1]
  87. sellCountd := sellSet == 9 ? isSellCountd ? 1 : 0 : buySet == 9 or lowTrendLine == 0 ? 14 : nonQSell13 ? -12 : isSellCountd ? math.abs(sellCountd[1]) + 1 : -math.abs(sellCountd[1])
  88. nonQSell13 := nonQSell13 and sellCountd == -12
  89. sellCountd8Close := sellCountd == 8 ? close : sellCountd8Close[1]
  90.  
  91. isAggressiveBuy = low < low[2]
  92. aggressiveBuy = 0.0
  93. aggressiveBuy := buySet == 9 ? isAggressiveBuy ? 1 : 0 : sellSet == 9 or highTrendLine == 0 ? 14 : isAggressiveBuy ? math.abs(aggressiveBuy[1]) + 1 : -math.abs(aggressiveBuy[1])
  94.  
  95. isAggressiveSell = high > high[2]
  96. aggressiveSell = 0.0
  97. aggressiveSell := sellSet == 9 ? isAggressiveSell ? 1 : 0 : buySet == 9 or lowTrendLine == 0 ? 14 : isAggressiveSell ? math.abs(aggressiveSell[1]) + 1 : -math.abs(aggressiveSell[1])
  98.  
  99. // -----------------------------------
  100.  
  101. color_btext = input.color(color.new(color.white , 0), title="Colors: Buy", inline="C", group=groupTD)
  102. color_stext = input.color(color.new(color.white , 0), title="Sell", inline="C", group=groupTD)
  103.  
  104. color_b6 = input.color(color.new(#77F1B0 , 0), title="6", inline="CB", group=groupTD)
  105. color_b7 = input.color(color.new(#00ADAD , 0), title="7", inline="CB", group=groupTD)
  106. color_b8 = input.color(color.new(#0067FF , 0), title="8", inline="CB", group=groupTD)
  107. color_b9 = input.color(color.new(#0014C4 , 0), title="9", inline="CB", group=groupTD)
  108.  
  109. color_s6 = input.color(color.new(color.yellow , 0), title="6", inline="CS", group=groupTD)
  110. color_s7 = input.color(color.new(color.orange , 0), title="7", inline="CS", group=groupTD)
  111. color_s8 = input.color(color.new(color.red , 0), title="8", inline="CS", group=groupTD)
  112. color_s9 = input.color(color.new(color.maroon , 0), title="9", inline="CS", group=groupTD)
  113.  
  114. color_b13 = input.color(color.new(color.blue , 0), title="13", inline="CB", group=groupTD)
  115. color_s13 = input.color(color.new(#d69d00 , 0), title="13", inline="CS", group=groupTD)
  116. color_bA13 = input.color(color.new(#6400d6 , 0), title="A13", inline="CB", group=groupTD)
  117. color_sA13 = input.color(color.new(#ff8629 , 0), title="A13", inline="CS", group=groupTD)
  118.  
  119. // -----------------------------------
  120.  
  121. plotshape(lastN == "6 to 9" ?
  122. buySet == 6 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b6, text="", title="lb6", textcolor=color_btext)
  123. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" ?
  124. buySet == 7 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b7, text="", title="lb7", textcolor=color_btext)
  125. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" ?
  126. buySet == 8 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b8, text="", title="lb8", textcolor=color_btext)
  127. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" or lastN == "Only 9" ?
  128. buySet == 9 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b9, text="9", title="lb9", textcolor=color_btext)
  129.  
  130. plotshape(lastN == "6 to 9" ?
  131. sellSet == 6 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s6, text="", title="ls6", textcolor=color_stext)
  132. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" ?
  133. sellSet == 7 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s7, text="", title="ls7", textcolor=color_stext)
  134. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" ?
  135. sellSet == 8 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s8, text="", title="ls8", textcolor=color_stext)
  136. plotshape(lastN == "6 to 9" or lastN == "7, 8 and 9" or lastN == "8 and 9" or lastN == "Only 9" ?
  137. sellSet == 9 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s9, text="9", title="ls9", textcolor=color_stext)
  138.  
  139. plotshape(Count13 ?
  140. sellCountd == 13 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_s13, text="13", title="lsc13", textcolor=color_stext)
  141. plotshape(Count13 ?
  142. buyCountd == 13 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_b13, text="13", title="lbc13", textcolor=color_btext)
  143.  
  144. plotshape(CountdA13 ?
  145. aggressiveBuy == 13 : na, location=locBc, style=f_getStyleB(Bstyle), size=size.auto, color=color_bA13, text="a13", title="lbc13", textcolor=color_btext)
  146. plotshape(CountdA13 ?
  147. aggressiveSell == 13 : na, location=locAc, style=f_getStyleS(Sstyle), size=size.auto, color=color_sA13, text="a13", title="lsc13", textcolor=color_stext)
  148.  
  149. // -----------------------------------
  150.  
  151. count9 = buySet == 9 or sellSet == 9
  152. count13 = buyCountd == 13 or sellCountd == 13
  153. counta13 = aggressiveBuy == 13 or aggressiveSell == 13
  154. count913 = count9 or count13
  155.  
  156. alertcondition(count9 , title="TD 9 Alert" , message="TD Seq: 9 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  157. alertcondition(count13 , title="TD 13 Alert" , message="TD Seq: 13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  158. alertcondition(counta13 , title="TD a13 Alert" , message="TD Seq: a13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
  159. alertcondition(count913 , title="TD 9 and 13 Alert" , message="TD Seq: 9, 13 \n\nTicker: {{ticker}}\nTime: {{time}}\nPrice: {{close}}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement