Advertisement
xmd79

chart combo best

Jun 3rd, 2024 (edited)
759
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 105.06 KB | None | 0 0
  1. //@version=5
  2. indicator("Gann medians MA targets", overlay=true, max_bars_back=1500, max_lines_count=500, max_labels_count=500, max_boxes_count = 500)
  3.  
  4. // Inputs
  5. method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  6. length1 = input(56)
  7. mult1 = input.int(1, minval=0, maxval=1)
  8.  
  9. method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  10. length2 = input(100)
  11. mult2 = input.int(1, minval=0, maxval=1)
  12.  
  13. method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  14. length3 = input(200)
  15. mult3 = input.int(1, minval=0, maxval=1)
  16.  
  17. // Calculation of medians
  18. Avg(x, length, method) =>
  19. sma_1 = ta.sma(x, length)
  20. ema_1 = ta.ema(x, length)
  21. percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
  22. method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
  23.  
  24. a1 = ta.highest(length1) - math.max(close, open)
  25. b1 = math.min(close, open) - ta.lowest(length1)
  26. c1 = math.max(close, open) + a1 * mult1
  27. d1 = math.min(close, open) - b1 * mult1
  28.  
  29. a2 = ta.highest(length2) - math.max(close, open)
  30. b2 = math.min(close, open) - ta.lowest(length2)
  31. c2 = math.max(close, open) + a2 * mult2
  32. d2 = math.min(close, open) - b2 * mult2
  33.  
  34. a3 = ta.highest(length3) - math.max(close, open)
  35. b3 = math.min(close, open) - ta.lowest(length3)
  36. c3 = math.max(close, open) + a3 * mult3
  37. d3 = math.min(close, open) - b3 * mult3
  38.  
  39. // Calculation of volume
  40. volLength = input.int(20, minval=1, title='Volume Length')
  41. volMultiplier = input.float(1.0, title='Volume Multiplier')
  42.  
  43. volAvg = ta.sma(volume, volLength) * volMultiplier
  44.  
  45. // Calculation of signals and liquidity levels
  46. e1 = Avg(c1, length1, method1)
  47. f1 = Avg(d1, length1, method1)
  48. gx1 = 0
  49. cross_1 = ta.cross(close, f1)
  50. gx1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(gx1[1])
  51.  
  52. e2 = Avg(c2, length2, method2)
  53. f2 = Avg(d2, length2, method2)
  54. gx2 = 0
  55. cross_2 = ta.cross(close, f2)
  56. gx2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(gx2[1])
  57.  
  58. e3 = Avg(c3, length3, method3)
  59. f3 = Avg(d3, length3, method3)
  60. gx3 = 0
  61. cross_3 = ta.cross(close, f3)
  62. gx3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(gx3[1])
  63.  
  64. // Calculation of liquidity levels with volume
  65. hilo1 = gx1 * f1 + (1 - gx1) * e1
  66. css1 = gx1 == 1 ? color.green : color.red
  67. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  68.  
  69. hilo2 = gx2 * f2 + (1 - gx2) * e2
  70. css2 = gx2 == 1 ? color.green : color.red
  71. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  72.  
  73. hilo3 = gx3 * f3 + (1 - gx3) * e3
  74. css3 = gx3 == 1 ? color.green : color.red
  75. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  76.  
  77.  
  78. //end of the code
  79.  
  80. //@version=5
  81.  
  82. //indicator(title='HiLo Activator', overlay=true)
  83. length = input.int(3, minval=1)
  84. displace = input.int(0, minval=0)
  85. highsma = ta.sma(high, length)
  86. lowsma = ta.sma(low, length)
  87. iff_1 = close < lowsma[displace] ? -1 : 0
  88. swing = close > highsma[displace] ? 1 : iff_1
  89. mah = ta.highest(high, length)
  90. mal = ta.lowest(low, length)
  91. var stop = 0.0
  92. iff_2 = swing == -1 ? mah : stop[1]
  93. stop := swing == 1 ? mal : iff_2
  94.  
  95. linecolor = stop < low ? color.green : color.red
  96. plot(stop, show_last=1, linewidth=1, trackprice=true, transp=0)
  97.  
  98. //end of this part
  99.  
  100. //study(title="TrapTrading (Study)", overlay=true)
  101. // input
  102. counterTrend = input(defval=false, title='Trade Mode (ON: Counter Trend OFF: Trend Following)')
  103. len1 = input.int(defval=20, title='Period (1-200)', minval=1, maxval=200)
  104. multiple = input(defval=0.7, title='Multiple')
  105.  
  106. m1 = close - close[len1]
  107. lowest_1 = ta.lowest(math.abs(m1), len1)
  108. highest_1 = ta.highest(math.abs(m1), len1)
  109. controlPoint = counterTrend ? lowest_1 == math.abs(m1) : highest_1 == math.abs(m1)
  110. baseLine = ta.valuewhen(controlPoint, math.avg(close, close[len1]), 0)
  111.  
  112. // trap line
  113. atr = ta.valuewhen(controlPoint, ta.highest(math.max(math.max(ta.atr(len1), ta.atr(len1 * 2)), ta.atr(len1 * 3)), len1), 0)
  114. line1Up = baseLine + atr * multiple
  115. line2Up = baseLine + atr * 2 * multiple
  116. line3Up = baseLine + atr * 3 * multiple
  117. line4Up = baseLine + atr * 4 * multiple
  118. line5Up = baseLine + atr * 5 * multiple
  119. line6Up = baseLine + atr * 6 * multiple
  120. line7Up = baseLine + atr * 7 * multiple
  121. line8Up = baseLine + atr * 8 * multiple
  122. line9Up = baseLine + atr * 9 * multiple
  123. line10Up = baseLine + atr * 10 * multiple
  124. line1Down = baseLine - atr * multiple
  125. line2Down = baseLine - atr * 2 * multiple
  126. line3Down = baseLine - atr * 3 * multiple
  127. line4Down = baseLine - atr * 4 * multiple
  128. line5Down = baseLine - atr * 5 * multiple
  129. line6Down = baseLine - atr * 6 * multiple
  130. line7Down = baseLine - atr * 7 * multiple
  131. line8Down = baseLine - atr * 8 * multiple
  132. line9Down = baseLine - atr * 9 * multiple
  133. line10Down = baseLine - atr * 10 * multiple
  134.  
  135. // draw
  136. //barcolor(controlPoint ? color.yellow : close >= baseLine ? color.teal : color.red, title="Candle Color")
  137.  
  138.  
  139. // find which bar is 5 days away from the current time
  140. milliseconds_in_5days = 1000 * 60 * 60 * 24 * 1 // millisecs * secs * min * hours * days
  141. leftborder = timenow - time < milliseconds_in_5days // true or na when false
  142. rightborder = barstate.islast
  143.  
  144.  
  145. plot(baseLine, title='Base Line', color=color.new(color.purple, 0), linewidth=1, style=plot.style_stepline, show_last=1, linewidth=1, trackprice=true, transp=0)
  146. //plot(leftborder?line1Up:na, title="1Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  147. //plot(leftborder?line2Up:na, title="2Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  148. //plot(leftborder?line3Up:na, title="3Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  149. //plot(leftborder?line4Up:na, title="4Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  150. //plot(leftborder?line5Up:na, title="5Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  151. //plot(leftborder?line6Up:na, title="6Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  152. //plot(leftborder?line7Up:na, title="7Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  153. //plot(leftborder?line8Up:na, title="8Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  154. //plot(leftborder?line9Up:na, title="9Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  155. //plot(leftborder?line10Up:na, title="10Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  156. //plot(leftborder?line1Down:na, title="1Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  157. //plot(leftborder?line2Down:na, title="2Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  158. //plot(leftborder?line3Down:na, title="3Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  159. //plot(leftborder?line4Down:na, title="4Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  160. //plot(leftborder?line5Down:na, title="5Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  161. //plot(leftborder?line6Down:na, title="6Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  162. //plot(leftborder?line7Down:na, title="7Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  163. //plot(leftborder?line8Down:na, title="8Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  164. //plot(leftborder?line9Down:na, title="9Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  165. //plot(leftborder?line10Down:na, title="10Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  166.  
  167. //end of this part
  168.  
  169. // © asenski at gmail dot com
  170. //@version=5
  171. //indicator("Opening Range with Fibs", "OR", overlay=true)
  172.  
  173. orSpec = input.session("0930-1000", "Opening Range with Fib Extensions")
  174. refsym = input.symbol("SPX500USD", "Reference for time range (So that it is in EST)")
  175.  
  176. rgColor = input.color(color.rgb(255, 255, 0), "Range color")
  177. // L1Color = input.color(color.rgb(0, 0, 255), "L1 color")
  178. // L2Color = input.color(color.rgb(255, 115, 40), "L2 color")
  179. // L3Color = input.color(color.rgb(255, 0, 255), "L3 color")
  180.  
  181. L1 = input.float(1.272, "L1")
  182. L2 = input.float(1.618, "L2")
  183. // L3 = input.float(2.618, "L3")
  184.  
  185. t = request.security(refsym, timeframe.period, time(timeframe.period, orSpec), gaps=barmerge.gaps_on)
  186.  
  187. var float orh = na
  188. var float orl = na
  189. var int orbars = 0
  190.  
  191. var float extL1up = na
  192. var float extL2up = na
  193. var float extL3up = na
  194. var float extL1dn = na
  195. var float extL2dn = na
  196. var float extL3dn = na
  197.  
  198. newSession = na(t[1]) and not na(t)
  199. inSession = not na(t[1]) and not na(t)
  200. endSession = not na(t[1]) and na(t)
  201.  
  202. if newSession
  203. orh := high
  204. orl := low
  205. orbars := 0
  206. extL1up := na
  207. extL2up := na
  208. extL3up := na
  209. extL1dn := na
  210. extL2dn := na
  211. extL3dn := na
  212.  
  213. if inSession
  214. orh := math.max(high, orh)
  215. orl := math.min(low, orl)
  216. orbars += 1
  217.  
  218. var float vwapsum = na
  219. var float volumesum = na
  220.  
  221. if endSession
  222. extL1up := orl + (orh - orl) * L1
  223. extL2up := orl + (orh - orl) * L2
  224. // extL3up := orl + (orh - orl) * L3
  225.  
  226. extL1dn := orh - (orh - orl) * L1
  227. extL2dn := orh - (orh - orl) * L2
  228. // extL3dn := orh - (orh - orl) * L3
  229.  
  230. b1 = box.new(bar_index - orbars - 1, orh, bar_index - 1, orl, border_color = rgColor, bgcolor = na)
  231. b2 = box.new(bar_index - orbars - 1, extL1up, bar_index - 1, extL2up, border_color = rgColor, bgcolor = na)
  232. b3 = box.new(bar_index - orbars - 1, extL1dn, bar_index - 1, extL2dn, border_color = rgColor, bgcolor = na)
  233. if barstate.islast
  234. box.delete(b1[1])
  235. box.delete(b2[1])
  236. box.delete(b3[1])
  237.  
  238. //plot(newSession ? na : orh, "OR high", color=rgColor,style=plot.style_linebr)
  239. //plot(newSession ? na : orl, "OR low", color=rgColor,style=plot.style_linebr)
  240. //plot(newSession ? na : extL1up, "L1 above", color=L1Color, style=plot.style_linebr)
  241. //plot(newSession ? na : extL2up, "L2 above", color=L2Color, style=plot.style_linebr)
  242. //plot(newSession ? na : extL3up, "L3 above", color=L3Color, style=plot.style_linebr)
  243. //plot(newSession ? na : extL1dn, "L1 below", color=L1Color, style=plot.style_linebr)
  244. //plot(newSession ? na : extL2dn, "L2 below", color=L2Color, style=plot.style_linebr)
  245. //plot(newSession ? na : extL3dn, "L3 below", color=L3Color, style=plot.style_linebr)
  246.  
  247. //end of this part
  248.  
  249. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  250. // © Lenny_Kiruthu
  251.  
  252. //@version=5
  253. //indicator(title = "Multi Timeframe Supply & Demand zones"
  254. //, shorttitle = "MTF SnD"
  255. //, overlay = true
  256. //, max_bars_back = 500
  257. //, max_lines_count = 500
  258. //, max_boxes_count = 500)
  259.  
  260. // Constants
  261. Transparent_Color = color.new(color.white, 100)
  262.  
  263. // Groups
  264. General_Settings_group = "-------General Settings-------"
  265. Timeframe_1_Group = "-------Timeframe 1 Settings--------"
  266. Timeframe_2_Group = "-------Timeframe 2 Settings--------"
  267. Timeframe_3_Group = "-------Timeframe 3 Settings--------"
  268.  
  269. // Tooltips
  270. Timeframe_Tooltip = "If set to chart is true no need to alter these two inputs."
  271. Set_To_Chart_Tooltip = "If set to chart is set to true, there is no need to alter the Timeframe inputs, it will automatically configure itself to the charts timeframe."
  272. Lower_Timeframe_Tooltip = "If set to true and chart timeframe is higher than the choosen timeframe, supply and demand will not display. Note plotting ltf structure on a htf will provide inaccurate plots."
  273. Mitigation_Tooltip = "If set to true supply zones with a high above them or a demand zone with a low below them will be removed since they are considered mitigated if false the close value will be used for both supply and demand."
  274. Alert_Tooltip = "After setting the alert to true or false head over to the alert dialog box and activate the any alert function under the indicator."
  275. Hide_Demand = "Hide or show the demand zones of the specific timeframe."
  276. Hide_Supply = "Hide or show the supply zones of the specific timeframe."
  277. Hide_Timeframe = "Hide or show the entire timeframe."
  278.  
  279. // General Settings
  280. Hide_All_Demand = input.bool(defval = false, title = "Hide all demand zones", group = General_Settings_group)
  281. Hide_All_Supply = input.bool(defval = false, title = "Hide all supply zones", group = General_Settings_group)
  282. Show_Only_On_Lower_Timeframes = input.bool(defval = true, title = "Show Supply and Demand only on Lower Timeframes", group = General_Settings_group, tooltip = Lower_Timeframe_Tooltip)
  283.  
  284. // User Inputs
  285. // Timeframe 1 Settings
  286. TF_1_Chart_Feature = input.bool(defval = false, title = "Set Timeframe to Chart", group = Timeframe_1_Group, tooltip = Set_To_Chart_Tooltip)
  287. TF_1_Use_High_Low = input.bool(defval = false, title = "Use High/Low to mitigates zones", group = Timeframe_1_Group, tooltip = Mitigation_Tooltip)
  288. TF_1_Show_Demand = input.bool(defval = true, title = "Show Demand", group = Timeframe_1_Group, tooltip = Hide_Demand)
  289. TF_1_Show_Supply = input.bool(defval = true, title = "Show Supply", group = Timeframe_1_Group, tooltip = Hide_Supply)
  290. TF_1_Demand_Alert = input.bool(defval = true, title = "Use TF 1 Demand Alert", group = Timeframe_1_Group, tooltip = Alert_Tooltip)
  291. TF_1_Supply_Alert = input.bool(defval = true, title = "Use TF 1 Supply Alert", group = Timeframe_1_Group, tooltip = Alert_Tooltip)
  292. TF_1_Multip = input.int(defval=2, minval=1, maxval=1440, title="Timeframe 1", group=Timeframe_1_Group, inline="T1")
  293. TF_1_Period = input.string(defval="Hour", title="", options=["Minute", "Hour", "Day", "Week", "Month"], group=Timeframe_1_Group, inline="T1", tooltip=Timeframe_Tooltip)
  294. TF_1_Swing_Length = input.int(defval = 7, title = "Swing Length", minval = 1, group = Timeframe_1_Group)
  295. TF_1_Line_Type = input.string(defval = "Solid", title = "Border Type", options = ["Solid", "Dashed", "Dotted"], group = Timeframe_1_Group)
  296. TF_1_Text_Size = input.string(defval = "Small", title = "Text Size", options = ["Normal", "Tiny", "Small", "Large", "Huge", "Auto"], group = Timeframe_1_Group)
  297. TF_1_Line_Width = input.int(defval = 1, title = "Border Width", group = Timeframe_1_Group)
  298. TF_1_Demand_Show_Last = input.int(defval = 2, title = "Show last (Demand)", group = Timeframe_1_Group)
  299. TF_1_Supply_Show_Last = input.int(defval = 2, title = "Show last (Supply)", group = Timeframe_1_Group)
  300. TF_1_Demand_Color = input.color(defval = #c6f89560, title = "Demand Color", group = Timeframe_1_Group, inline = "TF 1 Color")
  301. TF_1_Supply_Color = input.color(defval = #fb726a60, title = "Supply Color", group = Timeframe_1_Group, inline = "TF 1 Color")
  302. TF_1_Text_Color = input.color(defval = color.white, title = "Text Color", group = Timeframe_1_Group)
  303.  
  304. // Timeframe 2 Settings
  305. TF_2_Chart_Feature = input.bool(defval = false, title = "Set Timeframe to Chart", group = Timeframe_2_Group, tooltip = Set_To_Chart_Tooltip)
  306. TF_2_Use_High_Low = input.bool(defval = false, title = "Use High/Low to mitigates zones", group = Timeframe_2_Group, tooltip = Mitigation_Tooltip)
  307. TF_2_Show_Demand = input.bool(defval = true, title = "Show Demand", group = Timeframe_2_Group, tooltip = Hide_Demand)
  308. TF_2_Show_Supply = input.bool(defval = true, title = "Show Supply", group = Timeframe_2_Group, tooltip = Hide_Supply)
  309. TF_2_Demand_Alert = input.bool(defval = true, title = "Use TF 2 Demand Alert", group = Timeframe_2_Group, tooltip = Alert_Tooltip)
  310. TF_2_Supply_Alert = input.bool(defval = true, title = "Use TF 2 Supply Alert", group = Timeframe_2_Group, tooltip = Alert_Tooltip)
  311. TF_2_Multip = input.int(defval=30, minval=1, maxval=1440, title="Timeframe 2", group=Timeframe_2_Group, inline="T2")
  312. TF_2_Period = input.string(defval="Minute", title="", options=["Minute", "Hour", "Day", "Week", "Month"], group=Timeframe_2_Group, inline="T2", tooltip=Timeframe_Tooltip)
  313. TF_2_Swing_Length = input.int(defval = 7, title = "Swing Length", minval = 1, group = Timeframe_2_Group)
  314. TF_2_Line_Type = input.string(defval = "Solid", title = "Border Type", options = ["Solid", "Dashed", "Dotted"], group = Timeframe_2_Group)
  315. TF_2_Text_Size = input.string(defval = "Small", title = "Text Size", options = ["Normal", "Tiny", "Small", "Large", "Huge", "Auto"], group = Timeframe_2_Group)
  316. TF_2_Line_Width = input.int(defval = 1, title = "Border Width", group = Timeframe_2_Group)
  317. TF_2_Demand_Show_Last = input.int(defval = 2, title = "Show last (Demand)", group = Timeframe_2_Group)
  318. TF_2_Supply_Show_Last = input.int(defval = 2, title = "Show last (Supply)", group = Timeframe_2_Group)
  319. TF_2_Demand_Color = input.color(defval = #5794f860, title = "Demand Color", group = Timeframe_2_Group, inline = "TF 2 Color")
  320. TF_2_Supply_Color = input.color(defval = #f9c9fe60, title = "Supply Color", group = Timeframe_2_Group, inline = "TF 2 Color")
  321. TF_2_Text_Color = input.color(defval = color.white, title = "Text Color", group = Timeframe_2_Group)
  322.  
  323. // General functions
  324. // Getting the line type from the user.
  325. Line_Type_Control(Type) =>
  326. Line_Functionality = switch Type
  327. "Solid" => line.style_solid
  328. "Dashed" => line.style_dashed
  329. "Dotted" => line.style_dotted
  330.  
  331. Line_Functionality
  332.  
  333. // Text size from the user
  334. Text_Size_Switch(Text_Size) =>
  335. Text_Type = switch Text_Size
  336. "Normal" => size.normal
  337. "Tiny" => size.tiny
  338. "Small" => size.small
  339. "Large" => size.large
  340. "Huge" => size.huge
  341. "Auto" => size.auto
  342. Text_Type
  343.  
  344. // Timeframe functionality
  345. // Timeframe for security functions
  346. TF(TF_Period, TF_Multip) =>
  347. switch TF_Period
  348. "Minute" => str.tostring(TF_Multip)
  349. "Hour" => str.tostring(TF_Multip*60)
  350. "Day" => str.tostring(TF_Multip) + "D"
  351. "Week" => str.tostring(TF_Multip) + "W"
  352. "Month" => str.tostring(TF_Multip) + "M"
  353. => timeframe.period
  354.  
  355. // Timeframe shortcut form
  356. TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip) =>
  357. if Chart_as_Timeframe == false
  358. switch TF_Period
  359. "Minute" => str.tostring(TF_Multip) + "Min"
  360. "Hour" => str.tostring(TF_Multip) + "H"
  361. "Day" => str.tostring(TF_Multip) + "D"
  362. "Week" => str.tostring(TF_Multip) + "W"
  363. "Month" => str.tostring(TF_Multip) + "M"
  364.  
  365. else if Chart_as_Timeframe == true
  366. switch
  367. timeframe.isminutes and timeframe.multiplier % 60 != 0
  368. => str.tostring(timeframe.multiplier) + "Min"
  369.  
  370. timeframe.isminutes and timeframe.multiplier % 60 == 0
  371. => str.tostring(timeframe.multiplier/60) + "H"
  372.  
  373. timeframe.isdaily => str.tostring(timeframe.multiplier) + "D"
  374. timeframe.isweekly => str.tostring(timeframe.multiplier) + "W"
  375. timeframe.ismonthly => str.tostring(timeframe.multiplier) + "M"
  376.  
  377. MTF_MS_Display(Chart_as_Timeframe, TF_Period, TF_Multip, Swing_Length) =>
  378. if Chart_as_Timeframe == true
  379. Swing_Length
  380. else
  381. switch
  382. TF_Period == "Month" and timeframe.isminutes and timeframe.multiplier % 60 == 0 and
  383. (24*5*5/((TF_Multip * 1440*5*5)/timeframe.multiplier)) * 60 == timeframe.multiplier => ((TF_Multip * 1440)*5*5/ timeframe.multiplier)*Swing_Length
  384.  
  385. TF_Period == "Month" and timeframe.isweekly and
  386. (5/((TF_Multip * 1440 * 5)/timeframe.multiplier)) * 1440 == timeframe.multiplier => ((TF_Multip * 1440)*5/ 1440)*Swing_Length
  387.  
  388. TF_Period == "Month" and timeframe.isdaily and
  389. (5*5/((TF_Multip * 1440 * 5*5)/timeframe.multiplier)) * 1440 == timeframe.multiplier => ((TF_Multip * 1440)*5*5/ 1440)*Swing_Length
  390.  
  391. timeframe.ismonthly and timeframe.multiplier == TF_Multip and
  392. TF_Period == "Month" => Swing_Length
  393.  
  394. TF_Period == "Week" and timeframe.isminutes and timeframe.multiplier % 60 == 0 and
  395. (24*5/((TF_Multip * 1440*5)/timeframe.multiplier)) * 60 == timeframe.multiplier => ((TF_Multip * 1440)*5/ timeframe.multiplier)*Swing_Length
  396.  
  397. TF_Period == "Week" and timeframe.isdaily and
  398. (5/((TF_Multip * 1440 * 5)/timeframe.multiplier)) * 1440 == timeframe.multiplier => ((TF_Multip * 1440)*5/ 1440)*Swing_Length
  399.  
  400. timeframe.isweekly and timeframe.multiplier == TF_Multip and
  401. TF_Period == "Week" => Swing_Length
  402.  
  403. TF_Period == "Day" and timeframe.isminutes and timeframe.multiplier % 60 == 0 and
  404. (24/((TF_Multip * 1440)/timeframe.multiplier)) * 60 == timeframe.multiplier => (TF_Multip * 1440/ timeframe.multiplier)*Swing_Length
  405.  
  406. timeframe.isdaily and timeframe.multiplier == TF_Multip and
  407. TF_Period == "Day" => Swing_Length
  408.  
  409. timeframe.isminutes and timeframe.multiplier % 60 != 0 and
  410. TF_Period == "Minute" and TF_Multip == timeframe.multiplier => Swing_Length
  411.  
  412. timeframe.isminutes and timeframe.multiplier % 60 != 0 and
  413. TF_Period == "Minute" and TF_Multip != timeframe.multiplier => ((TF_Multip/60) * 60/timeframe.multiplier)*Swing_Length
  414.  
  415. timeframe.isminutes and timeframe.multiplier % 60 != 0 and
  416. TF_Period == "Hour" and TF_Multip != timeframe.multiplier => ((TF_Multip * 60 /60) * 60/timeframe.multiplier)*Swing_Length
  417.  
  418. timeframe.isminutes and timeframe.multiplier % 60 != 0 and
  419. TF_Period == "Hour" and TF_Multip == timeframe.multiplier and timeframe.multiplier * 60 == 60 => ((TF_Multip * 60 /60) * 60/timeframe.multiplier)*Swing_Length
  420.  
  421. timeframe.isminutes and timeframe.multiplier % 60 != 0 and
  422. TF_Period == "Day" and TF_Multip != timeframe.multiplier => ((TF_Multip * 1440 /60) * 60/timeframe.multiplier)*Swing_Length
  423.  
  424. timeframe.isminutes and timeframe.multiplier % 60 == 0 and
  425. TF_Period == "Hour" and TF_Multip * 60 == timeframe.multiplier => Swing_Length
  426.  
  427. timeframe.isminutes and timeframe.multiplier % 60 == 0 and
  428. TF_Period == "Hour" and TF_Multip * 60 != timeframe.multiplier => (TF_Multip * 60/timeframe.multiplier)*Swing_Length
  429.  
  430. HTF_Structure_Control(Chart_as_Timeframe, TF_Period, TF_Multip) =>
  431. if Chart_as_Timeframe == true
  432. true
  433. else if Show_Only_On_Lower_Timeframes == false
  434. true
  435. else
  436. switch
  437. TF_Period == "Minute" and TF_Multip < timeframe.multiplier and timeframe.isminutes
  438. => false
  439. TF_Period == "Minute" and TF_Multip >= timeframe.multiplier and timeframe.isminutes
  440. => true
  441. TF_Period == "Minute" and timeframe.isdaily
  442. => false
  443. TF_Period == "Minute" and timeframe.isweekly
  444. => false
  445. TF_Period == "Minute" and timeframe.ismonthly
  446. => false
  447. TF_Period == "Hour" and TF_Multip * 60 < timeframe.multiplier and timeframe.isminutes
  448. => false
  449. TF_Period == "Hour" and TF_Multip * 60 >= timeframe.multiplier and timeframe.isminutes
  450. => true
  451. TF_Period == "Hour" and timeframe.isdaily
  452. => false
  453. TF_Period == "Hour" and timeframe.isweekly
  454. => false
  455. TF_Period == "Hour" and timeframe.ismonthly
  456. => false
  457. TF_Period == "Day" and timeframe.isdaily or timeframe.isminutes
  458. => true
  459. TF_Period == "Week" and timeframe.isweekly or timeframe.isdaily or timeframe.isminutes
  460. => true
  461. TF_Period == "Month" and timeframe.ismonthly or timeframe.isweekly or timeframe.isdaily or timeframe.isminutes
  462. => true
  463.  
  464.  
  465. // Arrays
  466. var Bullish_SnD_Top_TF_1 = array.new_float(0)
  467. var Bullish_SnD_Btm_TF_1 = array.new_float(0)
  468. var Bullish_SnD_Left_TF_1 = array.new_int(0)
  469. var Bullish_SnD_Type_TF_1 = array.new_int(0)
  470. var Bearish_SnD_Top_TF_1 = array.new_float(0)
  471. var Bearish_SnD_Btm_TF_1 = array.new_float(0)
  472. var Bearish_SnD_Left_TF_1 = array.new_int(0)
  473. var Bearish_SnD_Type_TF_1 = array.new_int(0)
  474.  
  475. var Bullish_SnD_Top_TF_2 = array.new_float(0)
  476. var Bullish_SnD_Btm_TF_2 = array.new_float(0)
  477. var Bullish_SnD_Left_TF_2 = array.new_int(0)
  478. var Bullish_SnD_Type_TF_2 = array.new_int(0)
  479. var Bearish_SnD_Top_TF_2 = array.new_float(0)
  480. var Bearish_SnD_Btm_TF_2 = array.new_float(0)
  481. var Bearish_SnD_Left_TF_2 = array.new_int(0)
  482. var Bearish_SnD_Type_TF_2 = array.new_int(0)
  483.  
  484. // TF Pivot values
  485. // TF_1_Calc_High = ta.pivothigh(high, TF_1_Swing_Length, TF_1_Swing_Length)
  486.  
  487. // Getting the high and low values
  488. [TF_1_SH, TF_1_SL, TF_1_SH_Low, TF_1_SL_High, TF_1_Atr] = request.security(symbol = syminfo.tickerid, timeframe = (TF_1_Chart_Feature ? timeframe.period : TF(TF_1_Period, TF_1_Multip))
  489. , expression = [ta.pivothigh(high, TF_1_Swing_Length, TF_1_Swing_Length)
  490. , ta.pivotlow(low, TF_1_Swing_Length, TF_1_Swing_Length)
  491. , not na(ta.pivothigh(high, TF_1_Swing_Length, TF_1_Swing_Length)) ? low[TF_1_Swing_Length] : 0
  492. , not na(ta.pivotlow(low, TF_1_Swing_Length, TF_1_Swing_Length)) ? high[TF_1_Swing_Length] : 0
  493. , ta.atr(200)]
  494. , gaps = barmerge.gaps_on)
  495.  
  496. [TF_2_SH, TF_2_SL, TF_2_SH_Low, TF_2_SL_High, TF_2_Atr] = request.security(symbol = syminfo.tickerid, timeframe = (TF_2_Chart_Feature ? timeframe.period : TF(TF_2_Period, TF_2_Multip))
  497. , expression = [ta.pivothigh(high, TF_2_Swing_Length, TF_2_Swing_Length)
  498. , ta.pivotlow(low, TF_2_Swing_Length, TF_2_Swing_Length)
  499. , not na(ta.pivothigh(high, TF_2_Swing_Length, TF_2_Swing_Length)) ? low[TF_2_Swing_Length] : 0
  500. , not na(ta.pivotlow(low, TF_2_Swing_Length, TF_2_Swing_Length)) ? high[TF_2_Swing_Length] : 0
  501. , ta.atr(200)]
  502. , gaps = barmerge.gaps_on)
  503. // [TF_3_SH, TF_3_SL] = request.security(symbol = syminfo.ticker, timeframe = (TF_3_Chart_Feature ? timeframe.period : TF(TF_3_Period, TF_3_Multip))
  504. // , expression = [ta.pivothigh(high, TF_3_Swing_Length, TF_3_Swing_Length), ta.pivotlow(low, TF_3_Swing_Length, TF_3_Swing_Length)], gaps = barmerge.gaps_on)
  505.  
  506. // Functions //
  507. // The function below is designed to loop through the arrays holding the box plot values for supply and demand box plots
  508. // and remove the mitigated (unnecessary plots) on the chart.
  509.  
  510. Supply_and_Demand_Mitigation(SnD_Top, SnD_Btm, SnD_Left, SnD_Type, SnD_Dir, TF_Use_High_Low) =>
  511. if SnD_Dir == "Bearish"
  512. for i in SnD_Type
  513. index = array.indexof(SnD_Type, i)
  514.  
  515. if (TF_Use_High_Low ? high : close) > array.get(SnD_Top, index)
  516. array.remove(SnD_Top, index)
  517. array.remove(SnD_Btm, index)
  518. array.remove(SnD_Left, index)
  519. array.remove(SnD_Type, index)
  520.  
  521. // array.set()
  522.  
  523. else if SnD_Dir == "Bullish"
  524. for i in SnD_Type
  525. index = array.indexof(SnD_Type, i)
  526.  
  527. if (TF_Use_High_Low ? low : close) < array.get(SnD_Btm, index)
  528. array.remove(SnD_Top, index)
  529. array.remove(SnD_Btm, index)
  530. array.remove(SnD_Left, index)
  531. array.remove(SnD_Type, index)
  532.  
  533. // The function below is designed to find the necessary swing points in our chart that fit the description
  534. // of demand and supply zones
  535.  
  536. Supply_and_Demand_Functionality(TF_SH, TF_SL, TF_SH_Low, TF_SL_High, TF_Atr
  537. , Swing_Length, Chart_as_Timeframe, TF_Period, TF_Multip
  538. , Bullish_SnD_Top, Bullish_SnD_Btm, Bullish_SnD_Left, Bullish_SnD_Type
  539. , Bearish_SnD_Top, Bearish_SnD_Btm, Bearish_SnD_Left, Bearish_SnD_Type
  540. , Use_Demand_Alert, Use_Supply_Alert) =>
  541.  
  542. // Variables to identify HH, HL, LH, LL
  543. var float TF_Prev_High = na
  544. var float TF_Prev_Low = na
  545. TF_Prev_High_Time = 0
  546. TF_Prev_Low_Time = 0
  547.  
  548. //Tracking whether previous levels have been broken
  549. var bool TF_High_Present = false
  550. var bool TF_Low_Present = false
  551.  
  552. // Variables for creating supply and demand boxes
  553. bool HH = false
  554. bool LH = false
  555. bool HL = false
  556. bool LL = false
  557.  
  558.  
  559. // Identify new pivot highs and lows
  560. if not na(TF_SH)
  561. if TF_SH >= TF_Prev_High
  562. HH := true
  563. else
  564. LH := true
  565. TF_Prev_High := TF_SH
  566. TF_Prev_High_Time := TF_Prev_High != TF_Prev_High[1] ? time[MTF_MS_Display(Chart_as_Timeframe, TF_Period, TF_Multip, Swing_Length)] : TF_Prev_High_Time[1]
  567. TF_High_Present := true
  568.  
  569. if not na(TF_SL)
  570. if TF_SL >= TF_Prev_Low
  571. HL := true
  572. else
  573. LL := true
  574. TF_Prev_Low := TF_SL
  575. TF_Prev_Low_Time := TF_Prev_Low != TF_Prev_Low[1] ? time[MTF_MS_Display(Chart_as_Timeframe, TF_Period, TF_Multip, Swing_Length)] : TF_Prev_Low_Time[1]
  576. TF_Low_Present := true
  577.  
  578.  
  579. // Displaying Swing Level
  580. // Demand zones
  581. if LL and (math.abs(TF_SL_High - TF_Prev_Low) < TF_Atr * 2)
  582. array.unshift(Bullish_SnD_Top, TF_SL_High)
  583. array.unshift(Bullish_SnD_Btm, TF_Prev_Low)
  584. array.unshift(Bullish_SnD_Left, TF_Prev_Low_Time)
  585. array.unshift(Bullish_SnD_Type, 1)
  586. if Use_Demand_Alert
  587. alert(message = "New demand zone formed on " + + TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq = alert.freq_once_per_bar_close)
  588.  
  589. if HL and (math.abs(TF_SL_High - TF_Prev_Low) < TF_Atr * 2)
  590. array.unshift(Bullish_SnD_Top, TF_SL_High)
  591. array.unshift(Bullish_SnD_Btm, TF_Prev_Low)
  592. array.unshift(Bullish_SnD_Left, TF_Prev_Low_Time)
  593. array.unshift(Bullish_SnD_Type, 1)
  594. if Use_Demand_Alert
  595. alert(message = "New demand zone formed on " + + TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq = alert.freq_once_per_bar_close)
  596.  
  597. // Supply zones
  598. if HH and (math.abs(TF_Prev_High - TF_SH_Low) < TF_Atr * 2)
  599. array.unshift(Bearish_SnD_Top, TF_Prev_High)
  600. array.unshift(Bearish_SnD_Btm, TF_SH_Low)
  601. array.unshift(Bearish_SnD_Left, TF_Prev_High_Time)
  602. array.unshift(Bearish_SnD_Type, -1)
  603. if Use_Supply_Alert
  604. alert(message = "New supply zone formed on " + + TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq = alert.freq_once_per_bar_close)
  605.  
  606. if LH and (math.abs(TF_Prev_High - TF_SH_Low) < TF_Atr * 2)
  607. array.unshift(Bearish_SnD_Top, TF_Prev_High)
  608. array.unshift(Bearish_SnD_Btm, TF_SH_Low)
  609. array.unshift(Bearish_SnD_Left, TF_Prev_High_Time)
  610. array.unshift(Bearish_SnD_Type, -1)
  611. if Use_Supply_Alert
  612. alert(message = "New supply zone formed on " + + TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq = alert.freq_once_per_bar_close)
  613.  
  614.  
  615. // The function below is designed to sift through our boxes, plot them on the chart and apply the necessary formatting.
  616.  
  617. Display_SnD_Zones(Box_PLot_Type, Box_Top, Box_Btm, Box_Left, Box_Type, Show_Last, Box_Arr_size
  618. , TF_Demand_Color, TF_Supply_Color, TF_Text_Color, TF_Text_Size, TF_Border_style, TF_Border_width
  619. , Chart_as_Timeframe, TF_Period, TF_Multip)=>
  620. for i = 0 to math.min(Show_Last-1, Box_Arr_size-1)
  621. get_box = array.get(Box_PLot_Type, i)
  622.  
  623. if HTF_Structure_Control(Chart_as_Timeframe, TF_Period, TF_Multip)
  624. box.set_top(get_box, array.get(Box_Top, i))
  625. box.set_bottom(get_box, array.get(Box_Btm, i))
  626. box.set_left(get_box, array.get(Box_Left,i))
  627. box.set_right(get_box, time_close("W"))
  628.  
  629. if Box_Type == "Bullish"
  630. box.set_bgcolor(get_box, TF_Demand_Color)
  631. box.set_border_color(get_box, TF_Demand_Color)
  632. box.set_text(get_box, TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip))
  633. box.set_text_color(get_box, TF_Text_Color)
  634. box.set_text_font_family(get_box, font.family_default)
  635. box.set_text_halign(get_box, text.align_right)
  636. box.set_text_valign(get_box, text.align_top)
  637. box.set_text_size(get_box, TF_Text_Size)
  638. box.set_border_style(get_box, TF_Border_style)
  639. box.set_border_width(get_box, TF_Border_width)
  640. else if Box_Type == "Bearish"
  641. box.set_bgcolor(get_box, TF_Supply_Color)
  642. box.set_border_color(get_box, TF_Supply_Color)
  643. box.set_text(get_box, TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip))
  644. box.set_text_color(get_box, TF_Text_Color)
  645. box.set_text_font_family(get_box, font.family_default)
  646. box.set_text_halign(get_box, text.align_right)
  647. box.set_text_valign(get_box, text.align_bottom)
  648. box.set_text_size(get_box, TF_Text_Size)
  649. box.set_border_style(get_box, TF_Border_style)
  650. box.set_border_width(get_box, TF_Border_width)
  651.  
  652. // Calling functions
  653. Supply_and_Demand_Functionality(TF_1_SH, TF_1_SL, TF_1_SH_Low, TF_1_SL_High, TF_1_Atr
  654. , TF_1_Swing_Length, TF_1_Chart_Feature, TF_1_Period, TF_1_Multip
  655. , Bullish_SnD_Top_TF_1, Bullish_SnD_Btm_TF_1, Bullish_SnD_Left_TF_1 ,Bullish_SnD_Type_TF_1
  656. , Bearish_SnD_Top_TF_1, Bearish_SnD_Btm_TF_1, Bearish_SnD_Left_TF_1, Bearish_SnD_Type_TF_1
  657. , TF_1_Demand_Alert, TF_1_Supply_Alert)
  658.  
  659. Supply_and_Demand_Functionality(TF_2_SH, TF_2_SL, TF_2_SH_Low, TF_2_SL_High, TF_2_Atr
  660. , TF_2_Swing_Length, TF_2_Chart_Feature, TF_2_Period, TF_2_Multip
  661. , Bullish_SnD_Top_TF_2, Bullish_SnD_Btm_TF_2, Bullish_SnD_Left_TF_2 ,Bullish_SnD_Type_TF_2
  662. , Bearish_SnD_Top_TF_2, Bearish_SnD_Btm_TF_2, Bearish_SnD_Left_TF_2, Bearish_SnD_Type_TF_2
  663. , TF_2_Demand_Alert, TF_2_Supply_Alert)
  664.  
  665. var TF_1_Bullish_Box_PLots = array.new_box(0)
  666. var TF_1_Bearish_Box_PLots = array.new_box(0)
  667. var TF_2_Bullish_Box_PLots = array.new_box(0)
  668. var TF_2_Bearish_Box_PLots = array.new_box(0)
  669.  
  670. TF_1_Bullish_Size = array.size(Bullish_SnD_Top_TF_1)
  671. TF_1_Bearish_Size = array.size(Bearish_SnD_Top_TF_1)
  672. TF_2_Bullish_Size = array.size(Bullish_SnD_Top_TF_2)
  673. TF_2_Bearish_Size = array.size(Bearish_SnD_Top_TF_2)
  674.  
  675. Supply_and_Demand_Mitigation(Bullish_SnD_Top_TF_1, Bullish_SnD_Btm_TF_1, Bullish_SnD_Left_TF_1, Bullish_SnD_Type_TF_1, "Bullish", TF_1_Use_High_Low)
  676. Supply_and_Demand_Mitigation(Bearish_SnD_Top_TF_1, Bearish_SnD_Btm_TF_1, Bearish_SnD_Left_TF_1, Bearish_SnD_Type_TF_1, "Bearish", TF_1_Use_High_Low)
  677.  
  678. Supply_and_Demand_Mitigation(Bullish_SnD_Top_TF_2, Bullish_SnD_Btm_TF_2, Bullish_SnD_Left_TF_2, Bullish_SnD_Type_TF_2, "Bullish", TF_2_Use_High_Low)
  679. Supply_and_Demand_Mitigation(Bearish_SnD_Top_TF_2, Bearish_SnD_Btm_TF_2, Bearish_SnD_Left_TF_2, Bearish_SnD_Type_TF_2, "Bearish", TF_2_Use_High_Low)
  680.  
  681. if barstate.isfirst
  682. for i = 0 to 125
  683. array.push(TF_1_Bullish_Box_PLots, box.new(na,na,na,na, xloc = xloc.bar_time))
  684. array.push(TF_1_Bearish_Box_PLots, box.new(na,na,na,na, xloc = xloc.bar_time))
  685. array.push(TF_2_Bullish_Box_PLots, box.new(na,na,na,na, xloc = xloc.bar_time))
  686. array.push(TF_2_Bearish_Box_PLots, box.new(na,na,na,na, xloc = xloc.bar_time))
  687.  
  688. if TF_1_Bullish_Size > 0 and TF_1_Show_Demand and not Hide_All_Demand
  689. if barstate.islast
  690. Display_SnD_Zones(TF_1_Bullish_Box_PLots, Bullish_SnD_Top_TF_1, Bullish_SnD_Btm_TF_1, Bullish_SnD_Left_TF_1, "Bullish", TF_1_Demand_Show_Last, TF_1_Bullish_Size
  691. , TF_1_Demand_Color, TF_1_Supply_Color, TF_1_Text_Color, Text_Size_Switch(TF_1_Text_Size), Line_Type_Control(TF_1_Line_Type), TF_1_Line_Width
  692. , TF_1_Chart_Feature, TF_1_Period, TF_1_Multip)
  693.  
  694. if TF_1_Bearish_Size > 0 and TF_1_Show_Supply and not Hide_All_Supply
  695. if barstate.islast
  696. Display_SnD_Zones(TF_1_Bearish_Box_PLots, Bearish_SnD_Top_TF_1, Bearish_SnD_Btm_TF_1, Bearish_SnD_Left_TF_1, "Bearish", TF_1_Supply_Show_Last, TF_1_Bearish_Size
  697. , TF_1_Demand_Color, TF_1_Supply_Color, TF_1_Text_Color, Text_Size_Switch(TF_1_Text_Size), Line_Type_Control(TF_1_Line_Type), TF_1_Line_Width
  698. , TF_1_Chart_Feature, TF_1_Period, TF_1_Multip)
  699.  
  700. if TF_2_Bullish_Size > 0 and TF_2_Show_Demand and not Hide_All_Demand
  701. if barstate.islast
  702. Display_SnD_Zones(TF_2_Bullish_Box_PLots, Bullish_SnD_Top_TF_2, Bullish_SnD_Btm_TF_2, Bullish_SnD_Left_TF_2, "Bullish", TF_2_Demand_Show_Last, TF_2_Bullish_Size
  703. , TF_2_Demand_Color, TF_2_Supply_Color, TF_2_Text_Color, Text_Size_Switch(TF_2_Text_Size), Line_Type_Control(TF_2_Line_Type), TF_2_Line_Width
  704. , TF_2_Chart_Feature, TF_2_Period, TF_2_Multip)
  705.  
  706. if TF_2_Bearish_Size > 0 and TF_2_Show_Supply and not Hide_All_Supply
  707. if barstate.islast
  708. Display_SnD_Zones(TF_2_Bearish_Box_PLots, Bearish_SnD_Top_TF_2, Bearish_SnD_Btm_TF_2, Bearish_SnD_Left_TF_2, "Bearish", TF_2_Supply_Show_Last, TF_2_Bearish_Size
  709. , TF_2_Demand_Color, TF_2_Supply_Color, TF_2_Text_Color, Text_Size_Switch(TF_2_Text_Size), Line_Type_Control(TF_2_Line_Type), TF_2_Line_Width
  710. , TF_2_Chart_Feature, TF_2_Period, TF_2_Multip)
  711.  
  712.  
  713. //end of this part
  714.  
  715. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  716. // © LuxAlgo
  717.  
  718. //@version=5
  719. //indicator("Predictive Ranges [LuxAlgo]", "LuxAlgo - Predictive Ranges", overlay = true)
  720. //------------------------------------------------------------------------------
  721. //Settings
  722. //-----------------------------------------------------------------------------{
  723. lengthd = input.int(200, 'Length', minval = 2)
  724. mult = input.float(6., 'Factor', minval = 0, step = .5)
  725. tf = input.timeframe('', 'Timeframe')
  726. src = input(close, 'Source')
  727.  
  728. //-----------------------------------------------------------------------------}
  729. //Function
  730. //-----------------------------------------------------------------------------{
  731. pred_ranges(lengthd, mult)=>
  732. var avg = src
  733. var hold_atr = 0.
  734.  
  735. atr = nz(ta.atr(lengthd)) * mult
  736.  
  737. avg := src - avg > atr ? avg + atr :
  738. avg - src > atr ? avg - atr :
  739. avg
  740.  
  741. hold_atr := avg != avg[1] ? atr / 2 : hold_atr
  742.  
  743. [avg + hold_atr * 2, avg + hold_atr, avg, avg - hold_atr, avg - hold_atr * 2]
  744.  
  745. //-----------------------------------------------------------------------------}
  746. //Calculation
  747. //-----------------------------------------------------------------------------{
  748. [prR2
  749. , prR1
  750. , avg
  751. , prS1
  752. , prS2] = request.security(syminfo.tickerid, tf, pred_ranges(lengthd, mult))
  753.  
  754. //-----------------------------------------------------------------------------}
  755. //Plots
  756. //-----------------------------------------------------------------------------{
  757. plot_pru2 = plot(prR2, 'PR Upper 2', avg != avg[1] ? na : #f23645)
  758. plot_pru1 = plot(prR1, 'PR Upper 1', avg != avg[1] ? na : #f23645)
  759. plot_pravg = plot(avg , 'PR Average', avg != avg[1] ? na : #5b9cf6)
  760. plot_prl1 = plot(prS1, 'PR Lower 1', avg != avg[1] ? na : #089981)
  761. plot_prl2 = plot(prS2, 'PR Lower 2', avg != avg[1] ? na : #089981)
  762.  
  763. //Fills
  764. fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645, 95))
  765. fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 95))
  766.  
  767. //-----------------------------------------------------------------------------}
  768.  
  769. //end of this part
  770.  
  771. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  772. // © RozaniGhani-RG
  773.  
  774. //@version=5
  775. //indicator('Linear Regression Channel 200', 'LRC200', true)
  776.  
  777. // 0. Inputs
  778. // 1. Custom function
  779. // 2. Variables
  780. // 3. Contructs
  781. // 4. Alerts
  782.  
  783. //#region ———————————————————— 0. Inputs
  784. devLen = input.float(2.0, 'Deviation')
  785. regLen = input.int( 200, 'Length', minval = 1, maxval = 5000)
  786. //#endregion
  787.  
  788. //#region ———————————————————— 1. Custom function
  789. calculateRegression(int len = 200) =>
  790. max_bars_back(close, 1500)
  791. mid = math.sum( close, len) / len
  792. slope = ta.linreg(close, len, 0) - ta.linreg(close, len, 1)
  793. price1 = mid - slope * math.floor(len / 2) + (1 - len % 2) / 2 * slope
  794. price2 = price1 + slope * (len - 1)
  795. dev = 0.0
  796. for x = 0 to len - 1
  797. dev += math.pow(close[x] - (slope * (len - x) + price1), 2)
  798. dev
  799. dev := math.sqrt(dev / len)
  800. [price1, price2, dev, slope]
  801. //#endregion
  802.  
  803. //#region ———————————————————— 2. Variables
  804. [price1, price2, stdDev, slope] = calculateRegression(regLen)
  805.  
  806. mid1 = chart.point.new(na, bar_index - regLen + 1, price1)
  807. up1 = chart.point.new(na, bar_index - regLen + 1, price1 + (devLen * stdDev))
  808. dn1 = chart.point.new(na, bar_index - regLen + 1, price1 - (devLen * stdDev))
  809.  
  810. mid2 = chart.point.new(na, bar_index, price2)
  811. up2 = chart.point.new(na, bar_index, price2 + (devLen * stdDev))
  812. dn2 = chart.point.new(na, bar_index, price2 - (devLen * stdDev))
  813.  
  814. col = price1 > price2 ? color.red : color.teal
  815. //#endregion
  816.  
  817. //#region ———————————————————— 3. Contructs
  818. if barstate.islast
  819. var line midLine = na, midLine.delete(), midLine := line.new(mid1, mid2, xloc.bar_index, extend.right, chart.fg_color, line.style_dashed, 1)
  820. var line upLine = na, upLine.delete(), upLine := line.new( up1, up2, xloc.bar_index, extend.right, chart.fg_color, line.style_solid, 2)
  821. var line dnLine = na, dnLine.delete(), dnLine := line.new( dn1, dn2, xloc.bar_index, extend.right, chart.fg_color, line.style_solid, 2)
  822. //#endregion
  823.  
  824. //#region ———————————————————— 4. Alerts
  825. float trend = math.sign(price1 - price2)
  826. alertcondition(trend[1] >= 0 and trend < 0, 'Uptrend', 'Regression Channel change to Uptrend')
  827. alertcondition(trend[1] <= 0 and trend > 0, 'Downtrend', 'Regression Channel change to Downtrend')
  828. //#endregion
  829.  
  830.  
  831. //end of this part
  832.  
  833. //@version=5
  834. //@author Eugene
  835. //
  836. // HOLP (High of the low period) and LOHP (Low of the high period)
  837. // Catching Trend Reversals by shorting tops and buying bottoms
  838. // using this Swing High/Low Indicator
  839. //
  840. // Trading Strategy comes from Mastering the Trade, by John Carter pg 300.
  841. // Trading Rules for Sells, Buys are reversed
  842. //
  843. // 1. Identifying a trending market, where today's price is making a 20-day high (17-18 day highs are also fine)
  844. // Note this is configurable by setting the trending period variable (defaults to 20)
  845. // For example if price is making a 20 period high or 20 period low, it will show a triangle up/down above the candle.
  846. // 2. Identify the high bar in the uptrend
  847. // 3. Go short once the price action closes below the low of this high bar
  848. // 4. The intial stop is the high of the high bar.
  849. // 5. If you are in the trade on the third day or period, use a 2 bar trailing stop.
  850. // You can check 2-bar trailing stop to draw the line, defaults to off.
  851. // Stop is indicated by the white dot.
  852. //
  853. // Code Converted from TradeStation EasyLanguage
  854. // I can't find the original source anymore for the swing high/low plots, but if someone knows,
  855. // let me know and I'll credit here.
  856. //
  857. //indicator(shorttitle='HOLP/LOHP', title='Catching Trend Reversals by shorting tops and buying bottoms', overlay=true)
  858.  
  859. bartype() =>
  860. if timeframe.period == "D"
  861. 2
  862. else if timeframe.period == "W"
  863. 3
  864. else if timeframe.period == "M"
  865. 4
  866. else
  867. 1
  868.  
  869. barinterval() =>
  870. timeframe.multiplier
  871.  
  872. fPushPeriods(iInterval) =>
  873. if iInterval < 5
  874. 60
  875. else if iInterval < 10
  876. 45
  877. else if iInterval == 10
  878. 6
  879. else if iInterval == 15
  880. 12
  881. else if iInterval == 30
  882. 4
  883. else if iInterval == 60
  884. 6
  885. else if iInterval > 60
  886. 10
  887.  
  888. var iMode = "Yes"
  889. var iPeriods = input.int(5, 'Periods')
  890. var highColor = input.color(color.red, 'high color')
  891. var lowColor = input.color( color.blue, 'low color')
  892. var trendingPeriod = input.int(20, 'Trending Period (shows triangleup or triangledown if price is making this period high/low)')
  893. var showShortStop = input.bool(false, '2 bar trailing stop when shorting')
  894. var showLongStop = input.bool(false, '2 bar trailing stop when buying (going long)')
  895.  
  896. var xPeriods = 60
  897. var xInterval = 0
  898. var sFirstPass = true
  899. var havePrevLines = false
  900. var tLHigh = 0.0
  901. var tLLow = 0.0
  902. var pushHigh = 0.0
  903. var pushHighBar = 0
  904. var pushLow = 0.0
  905. var pushLowBar = 0
  906. var oldPushHigh = 0.0
  907. var oldPushLow = 0.0
  908. var prevPushHigh = 0.0
  909. var prevPushLow = 0.0
  910.  
  911.  
  912. var K = 0.0
  913. var R = 0.0
  914. var H0C1 = 0.0
  915. var L0C1 = 0.0
  916. var H0L0 = 0.0
  917. var C1O1 = 0.0
  918. var DL = 1.0
  919. var SI =0.0
  920. var ASI = 0.0
  921. var SLOW_K =0.0
  922. var SLOW_D = 0.0
  923. var SWING_HIGH = 0.0
  924. var SWING_LOW = 0.0
  925.  
  926. H0C1 := math.abs(high - close[1] )
  927. L0C1 := math.abs( low - close[1] )
  928. H0L0 := high - low
  929. C1O1 := math.abs(close[1] - open[1] )
  930.  
  931. if H0C1 >= L0C1
  932. K := H0C1
  933.  
  934. if H0C1 >= H0L0
  935. R := H0C1 - 0.5 * L0C1 + 0.25 * C1O1
  936. else
  937. R := H0L0 + 0.25 * C1O1
  938. else
  939. K := L0C1
  940.  
  941. if L0C1 >= H0L0
  942. R := L0C1 - 0.5 * H0C1 + 0.25 * C1O1
  943. else
  944. R := H0L0 + 0.25 * C1O1
  945.  
  946. if R != 0
  947. SI := 50 * ( ( ( close - close[1] ) + 0.50 * ( close - open ) + 0.25 * ( close[1] - open[1] ) ) / R ) * K / DL
  948. else
  949. SI := 0
  950.  
  951.  
  952. ASI := ASI + SI
  953.  
  954. if sFirstPass
  955. sFirstPass := false
  956.  
  957. if bartype() == 4 // monthly
  958. xInterval := 94
  959. else if bartype() == 3 // weekly
  960. xInterval := 93
  961. else if bartype() == 2 // daily
  962. xInterval := 92
  963. else if bartype() == 1 // minute
  964. xInterval := barinterval()
  965.  
  966. if iMode != "Auto" and iMode != "auto" and iMode != "AUTO"
  967. xPeriods := iPeriods
  968. else
  969. xPeriods := fPushPeriods(xInterval)
  970.  
  971. if pushHigh != prevPushHigh
  972. oldPushHigh := prevPushHigh
  973.  
  974. if pushLow != prevPushLow
  975. oldPushLow := prevPushLow
  976.  
  977. oldPushHigh := prevPushHigh
  978. oldPushLow := prevPushLow
  979.  
  980. prevPushHigh := pushHigh
  981. prevPushLow := pushLow
  982.  
  983. pushHigh := ta.highest(high, xPeriods)
  984. pushLow := ta.lowest(low, xPeriods)
  985.  
  986. var lowBreakout = 0.0
  987. var highBreakout = 0.0
  988. var pushBar = 0
  989.  
  990. if pushHigh != high and pushHigh < prevPushHigh
  991. pushHigh := prevPushHigh
  992.  
  993. if pushLow != low and pushLow > prevPushLow
  994. pushLow := prevPushLow
  995.  
  996. if pushHigh != pushHigh[1]
  997. lowBreakout := low
  998.  
  999. if pushLow != pushLow[1]
  1000. highBreakout := high
  1001.  
  1002. var stopz = 0.0
  1003. var prevHighBreakout = 0.0
  1004. var entry = 0.0
  1005.  
  1006. plot(pushHigh, "PushHigh", color.yellow, style=plot.style_circles)
  1007. plot(pushLow, "PushLow", color.blue, style=plot.style_circles)
  1008. plotshape(close >= ta.highest(trendingPeriod)[1] ? close : na, style=shape.triangledown, location=location.abovebar, color=color.red)
  1009. plotshape(close <= ta.lowest(trendingPeriod)[1] ? close : na, style=shape.triangleup, location=location.abovebar, color=color.green)
  1010. plot(showShortStop ? ta.highest(2)[1] : na, color=color.white, style=plot.style_cross)
  1011. plot(showLongStop ? ta.lowest(2)[1] : na, color=color.white, style=plot.style_cross)
  1012.  
  1013. //end of this part
  1014.  
  1015. // This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  1016. // © Trendoscope Pty Ltd
  1017. // ░▒
  1018. // ▒▒▒ ▒▒
  1019. // ▒▒▒▒▒ ▒▒
  1020. // ▒▒▒▒▒▒▒░ ▒ ▒▒
  1021. // ▒▒▒▒▒▒ ▒ ▒▒
  1022. // ▓▒▒▒ ▒ ▒▒▒▒▒▒▒▒▒▒▒
  1023. // ▒▒▒▒▒▒▒▒▒▒▒ ▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  1024. // ▒ ▒ ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░
  1025. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒
  1026. // ▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒
  1027. // ▒▒▒▒▒ ▒▒▒▒▒▒▒
  1028. // ▒▒▒▒▒▒▒▒▒
  1029. // ▒▒▒▒▒ ▒▒▒▒▒
  1030. // ░▒▒▒▒ ▒▒▒▒▓ ████████╗██████╗ ███████╗███╗ ██╗██████╗ ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
  1031. // ▓▒▒▒▒ ▒▒▒▒ ╚══██╔══╝██╔══██╗██╔════╝████╗ ██║██╔══██╗██╔═══██╗██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝
  1032. // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ██║ ██████╔╝█████╗ ██╔██╗ ██║██║ ██║██║ ██║███████╗██║ ██║ ██║██████╔╝█████╗
  1033. // ▒▒▒▒▒ ▒▒▒▒▒ ██║ ██╔══██╗██╔══╝ ██║╚██╗██║██║ ██║██║ ██║╚════██║██║ ██║ ██║██╔═══╝ ██╔══╝
  1034. // ▒▒▒▒▒ ▒▒▒▒▒ ██║ ██║ ██║███████╗██║ ╚████║██████╔╝╚██████╔╝███████║╚██████╗╚██████╔╝██║ ███████╗
  1035. // ▒▒ ▒
  1036. //@version=5
  1037. import HeWhoMustNotBeNamed/DrawingTypes/2 as dr
  1038. import HeWhoMustNotBeNamed/DrawingMethods/2
  1039. import HeWhoMustNotBeNamed/ZigzagTypes/5 as zg
  1040. import HeWhoMustNotBeNamed/ZigzagMethods/6
  1041.  
  1042. import HeWhoMustNotBeNamed/utils/1 as ut
  1043.  
  1044. import HeWhoMustNotBeNamed/FibRatios/1 as fibs
  1045.  
  1046. //indicator("ABC on Recursive Zigzag [Trendoscope]", "ABC-RZ[Trendoscope]", overlay = true, max_lines_count=500, max_labels_count=500, max_bars_back = 1000)
  1047. theme = input.string('Dark', title='Theme', options=['Light', 'Dark'], group='Generic Settings',
  1048. tooltip='Chart theme settings. Line and label colors are generted based on the theme settings. If dark theme is selected, '+
  1049. 'lighter colors are used and if light theme is selected, darker colors are used.', display=display.none)
  1050.  
  1051. zigzagLength = input.int(13, step=5, minval=3, title='Length', group='Zigzag', tooltip='Zigzag length for level 0 zigzag', display = display.none)
  1052. depth = input.int(200, "Depth", step=25, maxval=500, group='Zigzag', tooltip='Zigzag depth refers to max number of pivots to show on chart', display = display.none)
  1053. minimumZigZagLevel = input.int(0, "Minimum Zigzag Level", group='Zigzag', minval = 0, tooltip = 'Minimum zigzag level to consider for pattern scanning', display=display.none)
  1054.  
  1055. indicators = matrix.new<float>()
  1056. indicatorNames = array.new<string>()
  1057.  
  1058. base = input.string('ABC Extension', 'Base', ['ABC Extension', 'BC Retracement'], 'Base on which entry, stop and target are calculated', group='ABC', display = display.none)
  1059. entryRatio = input.float(0.3, 'Entry Ratio', group='ABC', minval=0.1, step=0.1, display = display.none, tooltip = 'Entry ratio for the calculation of entry level')
  1060. targetRatio = input.float(1.0, 'Target Ratio', group='ABC', display = display.none, tooltip = 'Target Ratio for the calculation of target level')
  1061. stopRatio = input.float(0.0, 'Stop Ratio', group='ABC', maxval=0.0, step=0.1, display = display.none, tooltip = 'Stop Ratio for the calculation of stop level')
  1062. logScale = input.bool(false, 'Log Scale', group='ABC', display = display.none, tooltip = 'Use log scale for scanning and targets')
  1063. useClosePricesForEntry = input.bool(true, 'Entry', group='Use Close Prices', display = display.none, tooltip = 'Use close prices for tracking', inline = 'ucp')
  1064. useClosePricesForTarget = input.bool(true, 'Target', group='Use Close Prices', display = display.none, tooltip = 'Use close prices for tracking', inline = 'ucp')
  1065. useClosePricesForStop = input.bool(true, 'Stop', group='Use Close Prices', display = display.none, tooltip = 'Use close prices for tracking', inline = 'ucp')
  1066. useClosePricesForRetest = input.bool(true, 'Retest', group='Use Close Prices', display = display.none, tooltip = 'Use close prices for tracking', inline = 'ucp')
  1067.  
  1068. tradeConditionTooltip = 'any - no filter\ntrend - Both A and B pivots in the direction of trend. Example, HH, and HL for long signal and LH and LL for short signal\n'+
  1069. 'reverse - Both A and B pivots in the opposite direction of trend. Example, LH, and LL for long signal and HH and HL for short signal\n'+
  1070. 'contracting - Consider only if both A and B pivots are either LH or HL\nexpanding - Consider only if both A and B pivots are either HH or LL'
  1071.  
  1072. tradeCondition = input.string('any', 'Trade Condition', ['any', 'trend', 'reverse', 'contracting', 'expanding'], group='ABC', display = display.none, tooltip = tradeConditionTooltip)
  1073.  
  1074. condition = tradeCondition == 'any'? 0:
  1075. tradeCondition == 'trend'? 1:
  1076. tradeCondition == 'reverse'? 2:
  1077. tradeCondition == 'contracting'? 3: 4
  1078.  
  1079. baseVal = base == 'ABC Extension'? 1 : 2
  1080.  
  1081.  
  1082. var zg.Zigzag zigzag = zg.Zigzag.new(zigzagLength, depth)
  1083. zigzag.calculate(array.from(high, low), indicators, indicatorNames)
  1084.  
  1085. type ABCProperties
  1086. int base = 1
  1087. float entryRatio = 0.23
  1088. float targetRatio = 1.0
  1089. float stopRatio = -0.1
  1090. bool logScale = false
  1091. bool useClosePricesForEntry = true
  1092. bool useClosePricesForTarget = false
  1093. bool useClosePricesForStop = true
  1094. bool useClosePricesForRetest = false
  1095. int condition = 0
  1096.  
  1097. type ABCDrawing
  1098. dr.Line ab
  1099. dr.Line bc
  1100. dr.Line ac
  1101. dr.Label a
  1102. dr.Label b
  1103. dr.Label c
  1104. dr.Label abcRatio
  1105. dr.Box entryBox
  1106. dr.Box targetBox
  1107.  
  1108. type ABC
  1109. int id
  1110. int direction
  1111. zg.Pivot a
  1112. zg.Pivot b
  1113. zg.Pivot c
  1114. color patternColor
  1115. ABCProperties properties
  1116. float entryPrice
  1117. float stopPrice
  1118. float targetPrice
  1119. int status = 0
  1120. ABCDrawing drawing
  1121.  
  1122. initialiseCounts(int numberOfStatus)=>
  1123. countMap = map.new<int, int>()
  1124. for i=0 to numberOfStatus-1
  1125. countMap.put(i, 0)
  1126. countMap
  1127.  
  1128. var array<ABC> abcdPatterns = array.new<ABC>()
  1129. var array<ABC> oldPatterns = array.new<ABC>()
  1130.  
  1131. var map<int, int> bullishCounts = initialiseCounts(3)
  1132. var map<int, int> bearishCounts = initialiseCounts(3)
  1133.  
  1134. var int bullishRetests = 0
  1135. var int bearishRetests = 0
  1136.  
  1137. method calculateTargets(ABC this)=>
  1138. this.entryPrice := this.properties.base == 1 ?
  1139. fibs.extension(this.a.point.price, this.b.point.price, this.c.point.price, this.properties.entryRatio, this.properties.logScale) :
  1140. fibs.retracement(this.b.point.price, this.c.point.price, this.properties.entryRatio, this.properties.logScale)
  1141.  
  1142. this.targetPrice := this.properties.base == 1 ?
  1143. fibs.extension(this.a.point.price, this.b.point.price, this.c.point.price, this.properties.targetRatio, this.properties.logScale) :
  1144. fibs.retracement(this.b.point.price, this.c.point.price, this.properties.targetRatio, this.properties.logScale)
  1145.  
  1146. this.stopPrice := this.properties.base == 1 ?
  1147. fibs.extension(this.a.point.price, this.b.point.price, this.c.point.price, this.properties.stopRatio, this.properties.logScale) :
  1148. fibs.retracement(this.b.point.price, this.c.point.price, this.properties.stopRatio, this.properties.logScale)
  1149. this
  1150.  
  1151. method withinEntry(ABC this)=>
  1152. dir = this.c.point.price > this.b.point.price? -1 : 1
  1153. close*dir < this.entryPrice*dir
  1154.  
  1155. method delete(ABCDrawing this)=>
  1156. if(not na(this))
  1157. this.ab.delete()
  1158. this.bc.delete()
  1159. this.ac.delete()
  1160. this.abcRatio.delete()
  1161. this.a.delete()
  1162. this.b.delete()
  1163. this.c.delete()
  1164. this.entryBox.delete()
  1165. this.targetBox.delete()
  1166. else
  1167. log.info('this should not be na')
  1168. this
  1169.  
  1170. method draw(ABCDrawing this)=>
  1171. if(not na(this))
  1172. this.ab.draw()
  1173. this.bc.draw()
  1174. this.ac.draw()
  1175. this.abcRatio.draw()
  1176. this.a.draw()
  1177. this.b.draw()
  1178. this.c.draw()
  1179. this.entryBox.draw()
  1180. this.targetBox.draw()
  1181. else
  1182. log.info('this should not be na')
  1183. this
  1184.  
  1185. method draw(ABC this)=>
  1186. this.drawing.draw()
  1187. this
  1188.  
  1189. method deleteDrawing(ABC this)=>
  1190. if(not na(this.drawing))
  1191. this.drawing.delete()
  1192. this.drawing := na
  1193. this
  1194.  
  1195. method createDrawing(ABC this)=>
  1196. if(not na(this.drawing))
  1197. this.drawing.delete()
  1198.  
  1199. dr.LineProperties patternLineProps = dr.LineProperties.new(color=this.patternColor, width = 1, style = line.style_solid)
  1200. ab = this.a.point.createLine(this.b.point, patternLineProps)
  1201. bc = this.b.point.createLine(this.c.point, patternLineProps)
  1202. dr.LineProperties angleLineProps = dr.LineProperties.new(color=this.patternColor, width = 0, style = line.style_dotted)
  1203. ac = dr.Line.new(this.a.point, this.c.point, angleLineProps)
  1204. acMidPoint = dr.Point.new((this.a.point.price+this.c.point.price)/2, (this.a.point.bar + this.c.point.bar)/2, (this.a.point.bartime + this.c.point.bartime)/2)
  1205. abcRatioValue = fibs.retracementRatio(this.a.point.price, this.b.point.price, this.c.point.price)
  1206. ratioLabelProperties = dr.LabelProperties.new(yloc = yloc.price, textcolor = this.patternColor, style = label.style_none)
  1207. abcRatio = dr.Label.new(acMidPoint, str.tostring(abcRatioValue), properties = ratioLabelProperties)
  1208. pivotLabelPropertiesAC = dr.LabelProperties.new(yloc = this.a.point.price < this.b.point.price? yloc.belowbar : yloc.abovebar, textcolor = this.patternColor)
  1209. pivotLabelPropertiesBD = dr.LabelProperties.new(yloc = this.a.point.price > this.b.point.price? yloc.belowbar : yloc.abovebar, textcolor = this.patternColor)
  1210. a = dr.Label.new(this.a.point, 'A', properties = pivotLabelPropertiesAC)
  1211. b = dr.Label.new(this.b.point, 'B', properties = pivotLabelPropertiesBD)
  1212. c = dr.Label.new(this.c.point, 'C', properties = pivotLabelPropertiesAC)
  1213.  
  1214. entryPoint = dr.Point.new(this.entryPrice, this.c.point.bar, this.c.point.bartime)
  1215. barDiff = math.min((this.c.point.bar- this.a.point.bar)/2, 490)
  1216.  
  1217. entryBoxEndPoint = dr.Point.new(this.stopPrice, this.c.point.bar+barDiff)
  1218. targetBoxEndPoint = dr.Point.new(this.targetPrice, this.c.point.bar+barDiff)
  1219.  
  1220. boxPropertiesEntry = dr.BoxProperties.new(this.patternColor, color.new(color.red, 90))
  1221. boxPropertiesTarget = dr.BoxProperties.new(this.patternColor, color.new(color.green, 90))
  1222. entryBox = dr.Box.new(entryPoint, entryBoxEndPoint, boxPropertiesEntry)
  1223. targetBox = dr.Box.new(entryPoint, targetBoxEndPoint, boxPropertiesTarget)
  1224. this.drawing := ABCDrawing.new(ab, bc, ac, a, b, c, abcRatio, entryBox, targetBox)
  1225. this
  1226.  
  1227.  
  1228. method update(ABC this, zg.Pivot c)=>
  1229. this.c := c
  1230. alert('ABC Pattern Coordinates Updated')
  1231. this.calculateTargets()
  1232.  
  1233. if(this.withinEntry())
  1234. this.deleteDrawing().
  1235. createDrawing().
  1236. draw()
  1237. this
  1238.  
  1239. method createAbc(zg.Zigzag this, ABCProperties props, color patternColor)=>
  1240. var id = 1
  1241. c = this.zigzagPivots.get(0)
  1242. b = this.zigzagPivots.get(1)
  1243. a = this.zigzagPivots.get(2)
  1244. direction = b.point.price > c.point.price? 1 : -1
  1245. abc = ABC.new(id, direction, a, b, c, patternColor, props)
  1246. id+=1
  1247. abc
  1248.  
  1249. method scanAbc(zg.Zigzag this, ABCProperties props)=>
  1250. isAbc = false
  1251.  
  1252. if(this.zigzagPivots.size() >= 4)
  1253. c = this.zigzagPivots.get(0)
  1254. b = this.zigzagPivots.get(1)
  1255. a = this.zigzagPivots.get(2)
  1256. aDir = math.abs(a.dir)
  1257. bDir = math.abs(b.dir)
  1258. conditionInLine = props.condition == 0 or
  1259. (props.condition == 1 and aDir == 1 and bDir == 2) or
  1260. (props.condition == 2 and aDir == 2 and bDir == 1) or
  1261. (props.condition == 3 and aDir == 1 and bDir == 1) or
  1262. (props.condition == 4 and aDir == 2 and bDir == 2)
  1263. ratioInLine = c.ratio >= 0.618 and c.ratio <= 0.786
  1264. if(ratioInLine and conditionInLine)
  1265. existingPattern = false
  1266. isAbc := true
  1267. for p in abcdPatterns
  1268. existingPattern := p.a.point.price == a.point.price and p.b.point.price == b.point.price
  1269. if(existingPattern)
  1270. if(p.c.point.bar > c.point.bar and p.status == 0)
  1271. p.update(c)
  1272.  
  1273. isAbc:=false
  1274. break
  1275. isAbc
  1276.  
  1277. method record(ABC pattern)=>
  1278. countMapToSet = pattern.direction >0? bullishCounts : bearishCounts
  1279. countMapToSet.put(pattern.status, countMapToSet.get(pattern.status)+1)
  1280.  
  1281. method removePattern(array<ABC> patterns, int index)=>
  1282. pattern = patterns.remove(index)
  1283. pattern.deleteDrawing()
  1284. pattern.record()
  1285.  
  1286. method traverse(array<ABC> patterns)=>
  1287. for i = patterns.size() >0? patterns.size()-1: na to 0
  1288. pattern = patterns.get(i)
  1289. baseTarget = pattern.properties.useClosePricesForTarget? close : (pattern.direction > 0? high : low)
  1290. baseStop = pattern.properties.useClosePricesForStop? close : (pattern.direction >0? low : high)
  1291. baseEntry = pattern.properties.useClosePricesForEntry? close : (pattern.direction > 0? high : low)
  1292. baseValueRetest = pattern.properties.useClosePricesForRetest? close : (pattern.direction > 0? low : high)
  1293. baseInvalidation = close
  1294. newStatus = baseTarget*pattern.direction >= pattern.targetPrice*pattern.direction? 2 :
  1295. baseEntry*pattern.direction >= pattern.entryPrice*pattern.direction? 1: pattern.status
  1296. retested = pattern.status == 1 and baseValueRetest <= pattern.entryPrice
  1297.  
  1298. newStatus := math.max(pattern.status, newStatus)
  1299. closed = (newStatus > 0 and baseStop*pattern.direction <= pattern.stopPrice*pattern.direction) or
  1300. (newStatus == 0 and baseInvalidation*pattern.direction <= pattern.stopPrice*pattern.direction) or
  1301. pattern.status == 2
  1302. increment = newStatus >= pattern.status
  1303. pattern.status := newStatus
  1304. if(closed)
  1305. patterns.removePattern(i)
  1306.  
  1307. var properties = ABCProperties.new(baseVal, entryRatio, targetRatio, stopRatio, logScale, useClosePricesForEntry, useClosePricesForTarget, useClosePricesForStop, useClosePricesForRetest, condition)
  1308. var themeColors = ut.getColors(theme)
  1309.  
  1310. abcdPatterns.traverse()
  1311. oldPatterns.traverse()
  1312.  
  1313. if zigzag.flags.newPivot
  1314. mlzigzag = zigzag
  1315. while(mlzigzag.zigzagPivots.size() >= 3)
  1316. if(mlzigzag.level >= minimumZigZagLevel)
  1317. isAbcd = mlzigzag.scanAbc(properties)
  1318. if(isAbcd)
  1319. patternColor = themeColors.shift()
  1320. alert('New ABC Pattern Detected')
  1321. pattern = mlzigzag.createAbc(properties, patternColor).calculateTargets()
  1322. if(pattern.withinEntry())
  1323. pattern.createDrawing().draw()
  1324. abcdPatterns.push(pattern)
  1325. while(abcdPatterns.size() > 10)
  1326. last = abcdPatterns.shift()
  1327. oldPatterns.push(last)
  1328. last.deleteDrawing()
  1329.  
  1330. themeColors.push(patternColor)
  1331. mlzigzag := mlzigzag.nextlevel()
  1332.  
  1333. while(abcdPatterns.size() < 10 and oldPatterns.size() > 0)
  1334. restoreOld = oldPatterns.pop()
  1335. abcdPatterns.unshift(restoreOld)
  1336. restoreOld.draw()
  1337.  
  1338. if barstate.islast
  1339. var closedStatsTable = table.new(position.top_right, 6, 3, border_color = chart.bg_color)
  1340. closedStatsTable.clear(0, 0, 5, 2)
  1341. closedStatsTable.cell(0, 0, 'Direction\\Status', text_color=color.white, bgcolor = color.maroon)
  1342. closedStatsTable.cell(1, 0, 'Invalid', text_color=color.white, bgcolor = color.maroon)
  1343. closedStatsTable.cell(2, 0, 'Stopped', text_color=color.white, bgcolor = color.maroon)
  1344. closedStatsTable.cell(3, 0, 'Complete', text_color=color.white, bgcolor = color.maroon)
  1345. closedStatsTable.cell(4, 0, 'Win Ratio', text_color=color.white, bgcolor = color.maroon)
  1346. closedStatsTable.cell(5, 0, 'Risk Reward', text_color=color.white, bgcolor = color.maroon)
  1347. closedStatsTable.cell(0, 1, 'Bullish', text_color=color.white, bgcolor = color.new(color.green, 50))
  1348. closedStatsTable.cell(0, 2, 'Bearish', text_color=color.white, bgcolor = color.new(color.red, 50))
  1349.  
  1350. bullishInvalid = bullishCounts.get(0)
  1351. bullishStopped = bullishCounts.get(1)
  1352. bullishCompleted = bullishCounts.get(2)
  1353. riskReward =(targetRatio - entryRatio)/(entryRatio - stopRatio)
  1354. bullishBgColor = color.new(color.green, 70)
  1355. closedStatsTable.cell(1, 1, str.tostring(bullishInvalid), text_color=color.white, bgcolor = bullishBgColor)
  1356. closedStatsTable.cell(2, 1, str.tostring(bullishStopped), text_color=color.white, bgcolor = bullishBgColor)
  1357. closedStatsTable.cell(3, 1, str.tostring(bullishCompleted), text_color=color.white, bgcolor = bullishBgColor)
  1358. closedStatsTable.cell(4, 1, str.tostring(bullishCompleted*100/(bullishCompleted+bullishStopped), format.percent), text_color=color.white, bgcolor = bullishBgColor)
  1359. closedStatsTable.cell(5, 1, str.tostring(riskReward, '#.##'), text_color=color.white, bgcolor = bullishBgColor)
  1360.  
  1361. bearishInvalid = bearishCounts.get(0)
  1362. bearishStopped = bearishCounts.get(1)
  1363. bearishCompleted = bearishCounts.get(2)
  1364. bearishBgColor = color.new(color.red, 70)
  1365. closedStatsTable.cell(1, 2, str.tostring(bearishInvalid), text_color=color.white, bgcolor = bearishBgColor)
  1366. closedStatsTable.cell(2, 2, str.tostring(bearishStopped), text_color=color.white, bgcolor = bearishBgColor)
  1367. closedStatsTable.cell(3, 2, str.tostring(bearishCompleted), text_color=color.white, bgcolor = bearishBgColor)
  1368. closedStatsTable.cell(4, 2, str.tostring(bearishCompleted*100/(bearishCompleted+bearishStopped), format.percent), text_color=color.white, bgcolor = bearishBgColor)
  1369. closedStatsTable.cell(5, 2, str.tostring(riskReward, '#.##'), text_color=color.white, bgcolor = bearishBgColor)
  1370.  
  1371. //end of this part
  1372.  
  1373. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1374. // © ismailcarlik
  1375.  
  1376. //@version=5
  1377. //indicator("Trend Lines, Supports and Resistances", shorttitle = "TSR", overlay = true, max_bars_back = 5000)
  1378.  
  1379. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1380. // ║ * * * I N P U T S * * * ║
  1381. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1382.  
  1383. grpPivotPoints = "Pivot Points ・ Common"
  1384. pvtLength = input.int(20, title = "Pivot Length", minval = 1, group = grpPivotPoints)
  1385. pvtMarkPivots = input.bool(false, title = "Mark Pivots", group = grpPivotPoints)
  1386.  
  1387. grpTrendLines = "Trend Lines"
  1388. tlEnabled = input.bool(true, title = "Enabled", group = grpTrendLines)
  1389. tlPointsToCheck = input.int(3, title = "Points to Check", minval = 2, group = grpTrendLines)
  1390. tlMaxViolation = input.int(0, title = "Maximum Violation", minval = 0, group = grpTrendLines)
  1391. tlExceptBars = input.int(3, title = "Excepted Last Bars", minval = 0, group = grpTrendLines)
  1392. tlShowViolated = input.bool(false, title = "Show Violated Trend Lines", group = grpTrendLines)
  1393. tlExtension = input.string("Right", title = "Line Extension", options = ["None", "Left", "Right", "Both"], group = grpTrendLines)
  1394. tlShowLabels = input.bool(true, title = "Show Labels", group = grpTrendLines)
  1395. tlAlertsEnabled = input.bool(true, title = "Alerts Enabled", inline = "tlAlerts", group = grpTrendLines)
  1396. tlAlertrequency = input.string("Once Per Bar", title = " ・ Frequency", options = ["Once Per Bar", "Once Per Bar Close", "All"], inline = "tlAlerts", group = grpTrendLines, display = display.none)
  1397.  
  1398. grpSupportResistance = "Supports & Resistances"
  1399. srEnabled = input.bool(true, title = "Enabled", group = grpSupportResistance)
  1400. srPointsToCheck = input.int(3, title = "Points to Check", minval = 2, group = grpSupportResistance)
  1401. srMaxViolation = input.int(0, title = "Maximum Violation Allowed", minval = 0, group = grpSupportResistance)
  1402. srExceptBars = input.int(3, title = "Excepted Last Bars", minval = 0, group = grpSupportResistance)
  1403. srShowLabels = input.bool(true, title = "Show Labels", group = grpSupportResistance)
  1404. srAlertsEnabled = input.bool(true, title = "Alerts Enabled", inline = "srAlerts", group = grpSupportResistance)
  1405. srAlertrequency = input.string("Once Per Bar", title = " ・ Frequency", options = ["Once Per Bar", "Once Per Bar Close", "All"], inline = "srAlerts", group = grpSupportResistance, display = display.none)
  1406.  
  1407. grpVisual = "Style"
  1408. stlHighColor = input.color(color.blue, title = "High Color", inline = "colors", group = grpVisual)
  1409. stlLowColor = input.color(color.red, title = "Low Color", inline = "colors", group = grpVisual)
  1410. lineWidth = input.int(1, title = "Line Width", minval = 1, group = grpVisual)
  1411.  
  1412. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1413. // ║ * * * T Y P E S * * * ║
  1414. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1415.  
  1416. // @type Used to represent a point pair.
  1417. // @field firstPoint First point of pair.
  1418. // @field secondPoint Second point of pair.
  1419. type pointPair
  1420. chart.point firstPoint
  1421. chart.point secondPoint
  1422.  
  1423. // @type Used to represent a trend line.
  1424. // @field mainLine Main visible line of the trend.
  1425. // @field extensionLine Extension line of the trend.
  1426. // @field priceLabel Price label of the trend.
  1427. // @field isViolated Violation status of the trend.
  1428. type trendLine
  1429. line mainLine
  1430. line extensionLine = na
  1431. label priceLabel = na
  1432. bool isViolated = false
  1433.  
  1434. // @type Used to represent a support or resistance level.
  1435. // @field levelBox Level box for support or resistance.
  1436. // @field price Price level of the support or resistance.
  1437. // @field priceLabel Price label of the support or resistance.
  1438. type srLevel
  1439. box levelBox
  1440. float price
  1441. label priceLabel = na
  1442.  
  1443. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1444. // ║ * * * V A R I A B L E S * * * ║
  1445. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1446.  
  1447. tlExtendMode = str.lower(array.get(str.split(tlExtension, ""), 0))
  1448. tlAlertrequencyMode = switch tlAlertrequency
  1449. "Once Per Bar" => alert.freq_once_per_bar
  1450. "Once Per Bar Close" => alert.freq_once_per_bar_close
  1451. "All" => alert.freq_all
  1452. => alert.freq_once_per_bar
  1453. srAlertrequencyMode = switch srAlertrequency
  1454. "Once Per Bar" => alert.freq_once_per_bar
  1455. "Once Per Bar Close" => alert.freq_once_per_bar_close
  1456. "All" => alert.freq_all
  1457. => alert.freq_once_per_bar
  1458.  
  1459. var array<chart.point> highPivots = array.new<chart.point>()
  1460. var array<chart.point> lowPivots = array.new<chart.point>()
  1461.  
  1462. var array<trendLine> uptrends = array.new<trendLine>()
  1463. var array<trendLine> downtrends = array.new<trendLine>()
  1464.  
  1465. var array<srLevel> supports = array.new<srLevel>()
  1466. var array<srLevel> resistances = array.new<srLevel>()
  1467.  
  1468. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1469. // ║ * * * M E T H O D S * * * ║
  1470. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1471.  
  1472. // @function Returns reversed version of array.
  1473. // @param id (chart.point[]) Array object.
  1474. // @returns (chart.point[]) Reversed version of given array.
  1475. method reversed(array<chart.point> id) =>
  1476. array<chart.point> reversedArray = array.new<chart.point>()
  1477. for [i, v] in id
  1478. reversedArray.unshift(v)
  1479. reversedArray
  1480.  
  1481. // @function Checks for the bars if highs above trend line price.
  1482. // @param id (trendLine) Trend line object.
  1483. // @param exceptBars (int) Count of last bars for exception.
  1484. // @returns (int) Count of the bars above trend line price.
  1485. method getHighsAbovePrice(trendLine id, int exceptBars) =>
  1486. historyReference = bar_index - id.mainLine.get_x1()
  1487. count = 0
  1488. if exceptBars < historyReference
  1489. for i = historyReference to exceptBars
  1490. if high[i] > line.get_price(id.mainLine, bar_index - i)
  1491. count += 1
  1492. count
  1493.  
  1494. // @function Checks for the bars if lows below trend line price.
  1495. // @param id (trendLine) Trend line object.
  1496. // @param exceptBars (int) Count of last bars for exception.
  1497. // @returns (int) Count of the bars below trend line price.
  1498. method getLowsBelowPrice(trendLine id, int exceptBars) =>
  1499. historyReference = bar_index - id.mainLine.get_x1()
  1500. count = 0
  1501. if exceptBars < historyReference
  1502. for i = historyReference to exceptBars
  1503. if low[i] < line.get_price(id.mainLine, bar_index - i)
  1504. count += 1
  1505. count
  1506.  
  1507. // @function Sets the trend lines status to violated.
  1508. // @param id (trendLine) Trend line object.
  1509. // @param trendColor (color) Color of the trend line.
  1510. // @returns (void)
  1511. method setViolated(trendLine id, color trendColor) =>
  1512. id.isViolated := true
  1513. line.delete(id.extensionLine)
  1514. label.delete(id.priceLabel)
  1515. line.set_style(id.mainLine, line.style_dotted)
  1516. line.set_extend(id.mainLine, extend = tlExtendMode)
  1517. line.set_color(id.mainLine, tlShowViolated ? color.new(trendColor, 50) : na)
  1518.  
  1519. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1520. // ║ * * * F U N C T I O N S * * * ║
  1521. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1522.  
  1523. // @function Compares two points and returns true if first one is higher.
  1524. // @param firstPoint (chart.point) First point to compare.
  1525. // @param secondPoint (chart.point) Second point to compare.
  1526. // @returns (bool) Whether the first point is higher than the second.
  1527. f_isHigher (chart.point firstPoint, chart.point secondPoint) =>
  1528. firstPoint.price > secondPoint.price
  1529.  
  1530. // @function Compares two points and returns true if first one is lower.
  1531. // @param firstPoint (chart.point) First point to compare.
  1532. // @param secondPoint (chart.point) Second point to compare.
  1533. // @returns (bool) Whether the first point is lower than the second.
  1534. f_isLower (chart.point firstPoint, chart.point secondPoint) =>
  1535. firstPoint.price < secondPoint.price
  1536.  
  1537. // @function Checks for violation of support level.
  1538. // @param point (chart.point) Point of support level.
  1539. // @param exceptBars (int) Count of last bars for exception.
  1540. // @returns (int) Count of violations.
  1541. f_checkSupportViolation (chart.point point, int exceptBars) =>
  1542. historyReference = bar_index - point.index
  1543. violationCount = 0
  1544. if exceptBars < historyReference
  1545. for i = historyReference to exceptBars
  1546. if low[i] < point.price
  1547. violationCount += 1
  1548. violationCount
  1549.  
  1550. // @function Checks for violation of reistance level.
  1551. // @param point (chart.point) Point of resistance level.
  1552. // @param exceptBars (int) Count of last bars for exception.
  1553. // @returns (int) Count of violations.
  1554. f_checkResistanceViolation(chart.point point, int exceptBars) =>
  1555. historyReference = bar_index - point.index
  1556. violationCount = 0
  1557. if exceptBars < historyReference
  1558. for i = historyReference to exceptBars
  1559. if high[i] > point.price
  1560. violationCount += 1
  1561. violationCount
  1562.  
  1563. // @function Draws support level to chart.
  1564. // @param index (int) Bar index of support level.
  1565. // @returns (void)
  1566. f_drawSupport(int index) =>
  1567. historyReference = bar_index - index
  1568. lowValue = low[historyReference]
  1569. boxColor = color.new(stlHighColor, 70)
  1570. textColor = color.new(stlHighColor, 50)
  1571. supportBox = box.new(left = index, top = math.min(open[historyReference], close[historyReference]), right = bar_index, bottom = lowValue, bgcolor = boxColor, border_color = boxColor)
  1572. supportLabel = srShowLabels ? label.new(x = bar_index - int(historyReference / 2), y = lowValue, text = "Support : " + str.tostring(lowValue, format.mintick), style = label.style_label_up, color = color.new(boxColor, 100), textcolor = textColor) : na
  1573. supports.push(srLevel.new(levelBox = supportBox, price = lowValue, priceLabel = supportLabel))
  1574.  
  1575. // @function Draws resistance level to chart.
  1576. // @param index (int) Bar index of reistance level.
  1577. // @returns (void)
  1578. f_drawResistance(int index) =>
  1579. historyReference = bar_index - index
  1580. highValue = high[historyReference]
  1581. boxColor = color.new(stlLowColor, 70)
  1582. textColor = color.new(stlLowColor, 50)
  1583. resistanceBox = box.new(left = index, top = highValue, right = bar_index, bottom = math.max(open[historyReference], close[historyReference]), bgcolor = boxColor, border_color = boxColor)
  1584. resistanceLabel = srShowLabels ? label.new(x = bar_index - int(historyReference / 2), y = highValue, text = "Resistance : " + str.tostring(highValue, format.mintick), style = label.style_label_down, color = color.new(boxColor, 100), textcolor = textColor) : na
  1585. resistances.push(srLevel.new(levelBox = resistanceBox, price = highValue, priceLabel = resistanceLabel))
  1586.  
  1587. // @function Gets all pair combinations of given point array.
  1588. // @param srcArray (chart.point[]) Source array.
  1589. // @returns (pointPair[]) Array of point pairs.
  1590. f_getAllPairCombinations(array<chart.point> srcArray) =>
  1591. int inputLength = array.size(srcArray)
  1592. array<pointPair> pairs = array.new<pointPair>()
  1593. for i = 0 to inputLength - 2 by 1
  1594. for j = i + 1 to inputLength - 1 by 1
  1595. pairs.push(pointPair.new(firstPoint = srcArray.get(i), secondPoint = srcArray.get(j)))
  1596. pairs
  1597.  
  1598. // @function Draws an uptrend to chart.
  1599. // @param start (chart.point) Starting point of trend line.
  1600. // @param end (chart.point) Ending point of trend line.
  1601. // @returns (void)
  1602. f_drawUptrend(chart.point start, chart.point end) =>
  1603. uExtension = tlExtendMode == "n" ? na : line.new(start, end, color = color.new(stlHighColor, 50), extend = tlExtendMode, style = line.style_dashed, width = lineWidth)
  1604. uMain = line.new(start, end, color = stlHighColor, style = line.style_arrow_both, width = lineWidth)
  1605. uPrice = line.get_price(uMain, bar_index)
  1606. uLabel = tlShowLabels ? label.new(x = bar_index, y = uPrice, text = "Uptrend : " + str.tostring(uPrice, format.mintick), style = label.style_label_left, color = color.new(stlHighColor, 80), textcolor = stlHighColor) : na
  1607. uptrends.push(trendLine.new(mainLine = uMain, extensionLine = uExtension, priceLabel = uLabel))
  1608.  
  1609. // @function Draws a downtrend to chart.
  1610. // @param start (chart.point) Starting point of trend line.
  1611. // @param end (chart.point) Ending point of trend line.
  1612. // @returns (void)
  1613. f_drawDowntrend(chart.point start, chart.point end) =>
  1614. uExtension = tlExtendMode == "n" ? na : line.new(start, end, color = color.new(stlLowColor, 50), extend = tlExtendMode, style = line.style_dashed, width = lineWidth)
  1615. uMain = line.new(start, end, color = stlLowColor, style = line.style_arrow_both, width = lineWidth)
  1616. uPrice = line.get_price(uMain, bar_index)
  1617. uLabel = tlShowLabels ? label.new(x = bar_index, y = uPrice, text = "Downtrend : " + str.tostring(uPrice, format.mintick), style = label.style_label_left, color = color.new(stlLowColor, 80), textcolor = stlLowColor) : na
  1618. downtrends.push(trendLine.new(mainLine = uMain, extensionLine = uExtension, priceLabel = uLabel))
  1619.  
  1620. // @function Clears all lines, boxes, labels off the chart and empties all trend line, support and resistance arrays.
  1621. // @returns (void)
  1622. f_clearAll() =>
  1623. for [i, v] in line.all
  1624. line.delete(v)
  1625.  
  1626. for [i, v] in box.all
  1627. box.delete(v)
  1628.  
  1629. for [i, v] in label.all
  1630. label.delete(v)
  1631.  
  1632. supports.clear()
  1633. resistances.clear()
  1634. uptrends.clear()
  1635. downtrends.clear()
  1636.  
  1637. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1638. // ║ * * * C A L C U L A T I O N S * * * ║
  1639. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1640.  
  1641. ph = ta.pivothigh(pvtLength, pvtLength)
  1642. pl = ta.pivotlow(pvtLength, pvtLength)
  1643.  
  1644. if not na(ph)
  1645. highPivots.unshift(chart.point.from_index(bar_index[pvtLength], ph))
  1646.  
  1647. if not na(pl)
  1648. lowPivots.unshift(chart.point.from_index(bar_index[pvtLength], pl))
  1649.  
  1650. // ╔═════════════════════════════════════════════════════════════════════════════════════════════╗
  1651. // ║ * * * P L O T S * * * ║
  1652. // ╚═════════════════════════════════════════════════════════════════════════════════════════════╝
  1653.  
  1654. if barstate.islast
  1655. f_clearAll()
  1656.  
  1657. if tlEnabled
  1658. for [i, v] in f_getAllPairCombinations(lowPivots.slice(0, tlPointsToCheck).reversed())
  1659. if f_isLower(v.firstPoint, v.secondPoint)
  1660. f_drawUptrend(v.firstPoint, v.secondPoint)
  1661.  
  1662. for [i, v] in uptrends
  1663. if v.getLowsBelowPrice(exceptBars = tlExceptBars) > tlMaxViolation
  1664. v.setViolated(trendColor = stlHighColor)
  1665.  
  1666. for [i, v] in uptrends
  1667. trendPrice = line.get_price(v.mainLine, bar_index)
  1668. if not v.isViolated and low <= trendPrice and tlAlertsEnabled
  1669. alert(str.format("Uptrend at {0} broken with a new low price at {1} now.", str.tostring(trendPrice, format.mintick), str.tostring(low, format.mintick)), tlAlertrequencyMode)
  1670.  
  1671. for [i, v] in f_getAllPairCombinations(highPivots.slice(0, tlPointsToCheck).reversed())
  1672. if f_isHigher(v.firstPoint, v.secondPoint)
  1673. f_drawDowntrend(v.firstPoint, v.secondPoint)
  1674.  
  1675. for [i, v] in downtrends
  1676. if v.getHighsAbovePrice(exceptBars = tlExceptBars) > tlMaxViolation
  1677. v.setViolated(trendColor = stlLowColor)
  1678.  
  1679. for [i, v] in downtrends
  1680. trendPrice = line.get_price(v.mainLine, bar_index)
  1681. if not v.isViolated and high >= trendPrice and tlAlertsEnabled
  1682. alert(str.format("Downtrend at {0} broken with a new high price at {1} now.", str.tostring(trendPrice, format.mintick), str.tostring(high, format.mintick)), tlAlertrequencyMode)
  1683.  
  1684. if srEnabled
  1685. sCount = 0, lIndex = 0
  1686. rCount = 0, hIndex = 0
  1687.  
  1688. while sCount < srPointsToCheck
  1689. if f_isLower(lowPivots.get(lIndex), lowPivots.get(lIndex + 1))
  1690. if f_checkSupportViolation(lowPivots.get(lIndex), exceptBars = srExceptBars) <= srMaxViolation
  1691. f_drawSupport(lowPivots.get(lIndex).index)
  1692. sCount += 1
  1693. lIndex += 1
  1694.  
  1695. while rCount < srPointsToCheck
  1696. if f_isHigher(highPivots.get(hIndex), highPivots.get(hIndex + 1))
  1697. if f_checkResistanceViolation(highPivots.get(hIndex), exceptBars = srExceptBars) <= srMaxViolation
  1698. f_drawResistance(highPivots.get(hIndex).index)
  1699. rCount += 1
  1700. hIndex += 1
  1701.  
  1702. for [i, v] in supports
  1703. if low <= v.price and srAlertsEnabled
  1704. alert(str.format("Support at {0} broken by new low price at {1} now.", str.tostring(v.price, format.mintick), str.tostring(low, format.mintick)), srAlertrequencyMode)
  1705.  
  1706. for [i, v] in resistances
  1707. if high >= v.price and srAlertsEnabled
  1708. alert(str.format("Resistance at {0} broken by new high price at {1} now.", str.tostring(v.price, format.mintick), str.tostring(high, format.mintick)), srAlertrequencyMode)
  1709.  
  1710.  
  1711. plotshape(not na(ph) and pvtMarkPivots ? ph : na, title = "High Pivots", style = shape.triangleup, color = stlHighColor, location = location.abovebar, size = size.tiny, offset = -pvtLength)
  1712. plotshape(not na(pl) and pvtMarkPivots ? pl : na, title = "Low Pivots", style = shape.triangledown, color = stlLowColor, location = location.belowbar, size = size.tiny, offset = -pvtLength)
  1713.  
  1714. //end of this part
  1715.  
  1716. // ____ __ ___ ________ ___________ ___________ __ ____ ___
  1717. // / __ )/ / / | / ____/ //_/ ____/ |/_ __< / // / / __ |__ \
  1718. // / __ / / / /| |/ / / ,< / / / /| | / / / / // /_/ / / __/ /
  1719. // / /_/ / /___/ ___ / /___/ /| / /___/ ___ |/ / / /__ __/ /_/ / __/
  1720. // /_____/_____/_/ |_\____/_/ |_\____/_/ |_/_/ /_/ /_/ \____/____/
  1721.  
  1722. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1723. // © blackcat1402
  1724. //@version=5
  1725. //indicator(title="[blackcat] L1 Fibonacci MA Band", shorttitle="FMAB", overlay=true)
  1726.  
  1727. // Implementing the slope function
  1728. xsl(src, len) =>
  1729. out = 0.0
  1730. lrc = ta.linreg(src, len, 0)
  1731. lrprev = ta.linreg(src[1], len, 0)
  1732. out := (lrc - lrprev) / timeframe.multiplier
  1733. out
  1734.  
  1735. whales = ta.ema(close, 13)
  1736. resoline = ta.ema(close, 144)
  1737. trendline = ta.ema((xsl(close, 21) * 23 + close), 50)
  1738.  
  1739. // plot candles
  1740. plotcandle(whales, resoline, whales, resoline, color=(whales > resoline) ? color.new(color.blue, 0) : na)
  1741. plotcandle(whales, resoline, whales, resoline, color=(whales < resoline) ? color.new(color.green, 0) : na)
  1742.  
  1743. // plot lines
  1744. plot(whales, color=color.new(#FF7F00, 0), linewidth=2, style=plot.style_linebr)
  1745. plot(resoline, color=color.yellow, linewidth=1, style=plot.style_linebr)
  1746. plot(trendline, color=color.red, linewidth=3, style=plot.style_linebr)
  1747.  
  1748. // Conditional plotting for trendline based on the closing price
  1749. plot(close < trendline ? trendline : na, color=color.green, linewidth=3, style=plot.style_linebr)
  1750.  
  1751. //end of this part
  1752.  
  1753. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1754. // © traderharikrishna
  1755. // Idea and Code by @traderharikrishna
  1756. //@version=5
  1757. //indicator("RSI TREND FILTER",overlay=true)
  1758. showrsi=input.bool(false,title='Show RSI Cloud',group='RSI ')
  1759. showmidband=input.bool(false,title='Show RSI Mid Band',group='RSI ')
  1760. showgrid=input.bool(false,title='Show RSI Levels',group='RSI Levels')
  1761. grid=input.color(color.rgb(26, 22, 22, 34),'RSI LEVELS',group='RSI Levels')
  1762. rsilen=input.int(14,'RSI LENGTH',group='RSI')
  1763. rsima=input.int(100,'RSI 50 level',group='RSI')
  1764. emalen=input.int(20,'RSI EMA Length',group='RSI')
  1765. orsi=ta.rsi(close,rsilen)
  1766. adjrsi=close+ta.atr(100)*orsi/100
  1767. rma=ta.ema(adjrsi,rsima)
  1768. r1=plot(showrsi?adjrsi:na,display=display.all,title='RSI')
  1769. r2=plot(rma,color=open>rma?#00ff08:open<rma?#ff0404:color.white,title='RSI MA',linewidth=2)
  1770. fill(r1,r2,color=adjrsi>rma?color.rgb(76, 175, 79, 70):color.rgb(255, 82, 82, 75),title='RSI Cloud',display=showrsi?display.all:display.none)
  1771. level2=input.float(10,'RSI LEVEL2',minval=10,maxval=100,group='RSI Levels')
  1772. rmau=rma+ta.atr(100)*level2/10
  1773. rmal=rma-ta.atr(100)*level2/10
  1774. u=plot(rmau,display=showgrid?display.all:display.none,title='70',color=grid)
  1775. l=plot(rmal,display=showgrid?display.all:display.none,title='30',color=grid)
  1776. fill(u,l,color=color.rgb(232, 237, 242, 82),title='RSI ZeroBand',display=showmidband?display.all:display.none)
  1777. level3=input.float(40,'RSI LEVEL3',minval=10,maxval=100,group='RSI Levels')
  1778. rmau3=rma+ta.atr(100)*level3/10
  1779. rmal3=rma-ta.atr(100)*level3/10
  1780. o8=plot(rmau3,display=showgrid?display.all:display.none,title='80',color=grid)
  1781. o2=plot(rmal3,display=showgrid?display.all:display.none,title='20',color=grid)
  1782. level5=input.float(50,'RSI LEVEL5',minval=10,maxval=100,group='RSI Levels')
  1783. rmau5=rma+ta.atr(100)*level5/10
  1784. rmal5=rma-ta.atr(100)*level5/10
  1785. ul=plot(rmau5,color=grid,display=showgrid?display.all:display.none,title='100')
  1786. ll=plot(rmal5,color=grid,display=showgrid?display.all:display.none,title='0')
  1787. fill(o8,ul,color=color.rgb(232, 4, 205, 45),title='OverBought')
  1788. fill(o2,ll,color=color.rgb(9, 198, 15, 53),title='OverSold')
  1789. fill(r2,ul,color=color.rgb(76, 175, 79, 85),title='UP TREND')
  1790. fill(r2,ll,color=color.rgb(175, 76, 167, 85),title='DOWN TREND')
  1791.  
  1792. rsiMA=ta.ema(adjrsi,emalen)
  1793. plot(rsiMA,color=color.yellow)
  1794.  
  1795. //end of this part
  1796.  
  1797. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1798. // © TFlab
  1799.  
  1800. //@version=5
  1801. //indicator("ZigZag Multi [TradingFinder] Trend & Wave Lines - Structures", overlay = true , max_bars_back = 1000 , max_lines_count = 500 , max_labels_count = 500)
  1802. // // Input and Setting
  1803. // //Short Term Zig Zag Line
  1804. ShShTZ = input.bool(true , 'Show Short term Zig Zag Line', group = 'Short Term Zig Zag') //Show Short Term Zig Zag
  1805. PPShTZ = input.int(3 ,'Pivot Period Short Term Zig Zag Line' , group = 'Short Term Zig Zag') //Pivot Period Short Term Zig Zag
  1806. ShTZLS = input.string(line.style_dashed , 'Short Term Zig Zag Line Style' , options = [line.style_solid ,line.style_dotted , line.style_dashed], group = 'Short Term Zig Zag' ) //Short Term Zig Zag Line Style
  1807. ShTZLC = input.color(color.rgb(0, 0, 0) , 'Short Term Zig Zag Line Color' , group = 'Short Term Zig Zag') //Short Term Zig Zag Line Color
  1808. ShTZLW = input.int(1 ,'Short Term Zig Zag Line Width' , group = 'Short Term Zig Zag')//Short Term Zig Zag Line Width
  1809. //Short Term Label
  1810. ShShTL = input.bool(true , 'Show Short Term Label', group = 'Short Term Label') //Show Short Term Label
  1811. ShTLC = input.color(color.rgb(0, 0, 0) , 'Short Term Label Color' , group = 'Short Term Label')//Short Term Label Color
  1812. ShTLS = input.string(size.tiny , 'Short Term Label size' , options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = 'Short Term Label' )//Short Term Label size
  1813.  
  1814. //Long Term Zig Zag Line
  1815. ShLTZ = input.bool(true , 'Show Long term Zig Zag Line', group = 'Long Term Zig Zag') //Show Long Term Zig Zag
  1816. PPLTZ = input.int(9 ,'Pivot Period Long Term Zig Zag Line' , group = 'Long Term Zig Zag') //Pivot Period Long Term Zig Zag
  1817. LTZLS = input.string(line.style_solid , 'Long Term Zig Zag Line Style' , options = [line.style_solid ,line.style_dotted , line.style_dashed], group = 'Long Term Zig Zag' ) //Long Term Zig Zag Line Style
  1818. LTZLC = input.color(color.rgb(66, 187, 9) , 'Long Term Zig Zag Line Color' , group = 'Long Term Zig Zag') //Long Term Zig Zag Line Color
  1819. LTZLW = input.int(1 ,'Long Term Zig Zag Line Width' , group = 'Long Term Zig Zag')//Long Term Zig Zag Line Width
  1820. //Long Term Label
  1821. LShTL = input.bool(true , 'Show Long Term Label', group = 'Long Term Label') //Show Long Term Label
  1822. LTLC = input.color(color.rgb(42, 116, 8) , 'Long Term Label Color' , group = 'Long Term Label')//Long Term Label Color
  1823. LTLS = input.string(size.small , 'Long Term Label size' , options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = 'Long Term Label' )//Long Term Label size
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829. // Zig Zag Function
  1830. ZigZag(OPEN ,HIGH ,LOW ,CLOSE ,BAR_INDEX ,PiPe , SHOW_LINE ,STYLE_LINE , COLOR_LINE, WIDTH_LINE ,SHOW_LABEL ,COLOR_LABEL , SIZE_LABEL ) => //{PiPe : Pivot Period}
  1831. Open = OPEN
  1832. High = HIGH
  1833. Low = LOW
  1834. Close = CLOSE
  1835. Bar_Index = BAR_INDEX
  1836. PP = PiPe
  1837. Show_Line = SHOW_LINE
  1838. Style_Line = STYLE_LINE
  1839. Color_Line = COLOR_LINE
  1840. Width_Line = WIDTH_LINE
  1841. Show_Label = SHOW_LABEL
  1842. Color_Label = COLOR_LABEL
  1843. Size_Label = SIZE_LABEL
  1844. var ArrayType = array.new_string()
  1845. var ArrayValue = array.new_float()
  1846. var ArrayIndex = array.new_int()
  1847. var line ZZLine = na
  1848. var label Label = na
  1849. PASS = 0
  1850. HighPivot = ta.pivothigh(PP,PP)
  1851. LowPivot = ta.pivotlow(PP,PP)
  1852. HighValue = ta.valuewhen(HighPivot ,High[PP], 0)
  1853. LowValue = ta.valuewhen(LowPivot ,Low[PP], 0)
  1854. HighIndex = ta.valuewhen(HighPivot ,Bar_Index[PP], 0)
  1855. LowIndex = ta.valuewhen(LowPivot ,Bar_Index[PP], 0)
  1856. Correct_HighPivot = 0.0
  1857. Correct_LowPivot = 0.0
  1858. if HighPivot and LowPivot
  1859. if ArrayType.size() == 0
  1860. PASS := 1
  1861. else if ArrayType.size() >= 1
  1862. if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
  1863. (ArrayType.get(ArrayType.size() - 1)) == "LL")
  1864. if LowPivot < ArrayValue.get(ArrayType.size() - 1)
  1865. array.remove(ArrayType,ArrayType.size() - 1)
  1866. array.remove(ArrayValue,ArrayValue.size() - 1)
  1867. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1868. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1869. array.push(ArrayValue, LowValue)
  1870. array.push(ArrayIndex, LowIndex)
  1871. Correct_LowPivot := LowValue
  1872. else
  1873. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
  1874. array.push(ArrayValue, HighValue)
  1875. array.push(ArrayIndex, HighIndex)
  1876. Correct_HighPivot := HighValue
  1877. else if (ArrayType.get(ArrayType.size() - 1)) == "H" or
  1878. (ArrayType.get(ArrayType.size() - 1)) == "HH"
  1879. if HighPivot > ArrayValue.get(ArrayType.size() - 1)
  1880. array.remove(ArrayType,ArrayType.size() - 1)
  1881. array.remove(ArrayValue,ArrayValue.size() - 1)
  1882. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1883. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
  1884. array.push(ArrayValue, HighValue)
  1885. array.push(ArrayIndex, HighIndex)
  1886. Correct_HighPivot := HighValue
  1887. else
  1888. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1889. array.push(ArrayValue, LowValue)
  1890. array.push(ArrayIndex, LowIndex)
  1891. Correct_LowPivot := LowValue
  1892. else if (ArrayType.get(ArrayType.size() - 1)) == "LH"
  1893. if HighPivot < ArrayValue.get(ArrayType.size() - 1)
  1894. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1895. array.push(ArrayValue, LowValue)
  1896. array.push(ArrayIndex, LowIndex)
  1897. Correct_LowPivot := LowValue
  1898. else if HighPivot > ArrayValue.get(ArrayType.size() - 1)
  1899. if close < ArrayValue.get(ArrayType.size() - 1)
  1900. array.remove(ArrayType,ArrayType.size() - 1)
  1901. array.remove(ArrayValue,ArrayValue.size() - 1)
  1902. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1903. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
  1904. array.push(ArrayValue, HighValue)
  1905. array.push(ArrayIndex, HighIndex)
  1906. Correct_HighPivot := HighValue
  1907. else if close > ArrayValue.get(ArrayType.size() - 1)
  1908. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1909. array.push(ArrayValue, LowValue)
  1910. array.push(ArrayIndex, LowIndex)
  1911. Correct_LowPivot := LowValue
  1912. else if (ArrayType.get(ArrayType.size() - 1)) == "HL"
  1913. if LowPivot > ArrayValue.get(ArrayType.size() - 1)
  1914. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
  1915. array.push(ArrayValue, HighValue)
  1916. array.push(ArrayIndex, HighIndex)
  1917. Correct_HighPivot := HighValue
  1918. else if LowPivot < ArrayValue.get(ArrayType.size() - 1)
  1919. if close > ArrayValue.get(ArrayType.size() - 1)
  1920. array.remove(ArrayType,ArrayType.size() - 1)
  1921. array.remove(ArrayValue,ArrayValue.size() - 1)
  1922. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1923. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1924. array.push(ArrayValue, LowValue)
  1925. array.push(ArrayIndex, LowIndex)
  1926. Correct_LowPivot := LowValue
  1927. else if close < ArrayValue.get(ArrayType.size() - 1)
  1928. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
  1929. array.push(ArrayValue, HighValue)
  1930. array.push(ArrayIndex, HighIndex)
  1931. Correct_HighPivot := HighValue
  1932. else if HighPivot
  1933. if ArrayType.size() == 0
  1934. array.insert(ArrayType, 0, "H")
  1935. array.insert(ArrayValue, 0, HighValue)
  1936. array.insert(ArrayIndex, 0, HighIndex)
  1937. Correct_HighPivot := HighValue
  1938. else if ArrayType.size() >= 1
  1939. if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
  1940. (ArrayType.get(ArrayType.size() - 1)) == "HL" or
  1941. (ArrayType.get(ArrayType.size() - 1)) == "LL")
  1942. if HighPivot > ArrayValue.get(ArrayType.size() - 1)
  1943. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
  1944. array.push(ArrayValue, HighValue)
  1945. array.push(ArrayIndex, HighIndex)
  1946. Correct_HighPivot := HighValue
  1947. else if HighPivot < ArrayValue.get(ArrayType.size() - 1)
  1948. array.remove(ArrayType,ArrayType.size() - 1)
  1949. array.remove(ArrayValue,ArrayValue.size() - 1)
  1950. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1951. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1952. array.push(ArrayValue, LowValue)
  1953. array.push(ArrayIndex, LowIndex)
  1954. Correct_LowPivot := LowValue
  1955. else if (ArrayType.get(ArrayType.size() - 1)) == "H" or
  1956. (ArrayType.get(ArrayType.size() - 1)) == "HH" or
  1957. (ArrayType.get(ArrayType.size() - 1)) == "LH"
  1958. if (ArrayValue.get(ArrayValue.size() - 1)) < HighValue
  1959. array.remove(ArrayType,ArrayType.size() - 1)
  1960. array.remove(ArrayValue,ArrayValue.size() - 1)
  1961. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1962. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
  1963. array.push(ArrayValue, HighValue)
  1964. array.push(ArrayIndex, HighIndex)
  1965. Correct_HighPivot := HighValue
  1966. else if LowPivot
  1967. if ArrayType.size() == 0
  1968. array.insert(ArrayType, 0, "L")
  1969. array.insert(ArrayValue, 0, LowValue)
  1970. array.insert(ArrayIndex, 0, LowIndex)
  1971. Correct_LowPivot := LowValue
  1972. else if ArrayType.size() >= 1
  1973. if (ArrayType.get(ArrayType.size() - 1)) == "H" or
  1974. (ArrayType.get(ArrayType.size() - 1)) == "HH" or
  1975. (ArrayType.get(ArrayType.size() - 1)) == "LH"
  1976. if LowPivot < ArrayValue.get(ArrayType.size() - 1)
  1977. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1978. array.push(ArrayValue, LowValue)
  1979. array.push(ArrayIndex, LowIndex)
  1980. Correct_LowPivot := LowValue
  1981. else if LowPivot > ArrayValue.get(ArrayType.size() - 1)
  1982. array.remove(ArrayType,ArrayType.size() - 1)
  1983. array.remove(ArrayValue,ArrayValue.size() - 1)
  1984. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1985. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
  1986. array.push(ArrayValue, HighValue)
  1987. array.push(ArrayIndex, HighIndex)
  1988. Correct_HighPivot := HighValue
  1989. else if (ArrayType.get(ArrayType.size() - 1)) == "L" or
  1990. (ArrayType.get(ArrayType.size() - 1)) == "HL" or
  1991. (ArrayType.get(ArrayType.size() - 1)) == "LL"
  1992. if (ArrayValue.get(ArrayValue.size() - 1)) > LowValue
  1993. array.remove(ArrayType,ArrayType.size() - 1)
  1994. array.remove(ArrayValue,ArrayValue.size() - 1)
  1995. array.remove(ArrayIndex,ArrayIndex.size() - 1)
  1996. array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
  1997. array.push(ArrayValue, LowValue)
  1998. array.push(ArrayIndex, LowIndex)
  1999. Correct_LowPivot := LowValue
  2000. if ArrayType.size() > 2
  2001. X1 = ArrayIndex.get(ArrayIndex.size()-2)
  2002. Y1 = ArrayValue.get(ArrayIndex.size()-2)
  2003. X2 = ArrayIndex.get(ArrayIndex.size()-1)
  2004. Y2 = ArrayValue.get(ArrayIndex.size()-1)
  2005. T1 = ArrayType.get(ArrayIndex.size()-1)
  2006. if Show_Line
  2007. ZZLine := line.new( X1 , Y1 , X2 , Y2 ,color = Color_Line, style = Style_Line , width = Width_Line )
  2008. if Show_Label
  2009. Label := label.new(x = X2 , y = Y2 , text = T1, color = color.rgb(255, 255, 255, 100) ,
  2010. style = T1 == "LL" or T1 == "HL" ? label.style_label_up : label.style_label_down ,textcolor = Color_Label , size = Size_Label)
  2011. if line.get_x1(ZZLine) == line.get_x1(ZZLine[1])
  2012. label.delete(Label[1])
  2013. line.delete(ZZLine[1])
  2014.  
  2015.  
  2016.  
  2017.  
  2018. //Call Function
  2019. ZigZag(open ,high ,low ,close ,bar_index ,PPShTZ , ShShTZ ,ShTZLS , ShTZLC, ShTZLW ,ShShTL ,ShTLC , ShTLS )
  2020. ZigZag(open ,high ,low ,close ,bar_index ,PPLTZ , ShLTZ ,LTZLS , LTZLC, LTZLW ,LShTL ,LTLC ,LTLS )
  2021.  
  2022.  
  2023. // end of this part
  2024.  
  2025.  
Advertisement
Comments
  • earnmoney9022
    1 year
    # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement