Facebook
From jjustingreyy, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 225
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © jjustingreyy
  3.  
  4. //@version=5
  5. indicator("Small Tilt Algo", overlay=true)
  6. plot(close)
  7.  
  8. // Toggle for previous day levels
  9. show_prev_day_high = input(true, title="Show Previous Day High")
  10. show_prev_day_low = input(true, title="Show Previous Day Low")
  11. show_prev_day_close = input(true, title="Show Previous Day Close")
  12.  
  13. //Previous Day Values
  14. // to highlight the session
  15. var line[] prevDayLines = array.new_line()
  16.  
  17. prevDayOpen = na(nz(request.security(syminfo.tickerid, "D", time[1])))
  18. isNewDay = not(na(prevDayOpen)) and prevDayOpen != request.security(syminfo.tickerid, "D", time)
  19.  
  20. if isNewDay and array.size(prevDayLines) > 0
  21.     for i = 0 to array.size(prevDayLines) - 1
  22.         line.delete(array.get(prevDayLines, i))
  23.     array.clear(prevDayLines)
  24.  
  25. [dh1,dl1,dc1, dv1] = request.security(syminfo.ticker, "D", [high[1],low[1], close[1], ta.vwap[1]], lookahead=barmerge.lookahead_on)
  26.  
  27. // Function to create line and label
  28. f_line_and_label(_p, _color, _text) =>
  29.     if (not na(_p))
  30.         l = line.new(x1=na, y1=_p, x2=bar_index + 50, y2=_p, width = 1, color=_color, extend = extend.right)
  31.         array.push(prevDayLines, l)
  32.         var label lb = na
  33.         if (na(lb))
  34.             lb := label.new(na, na, "", color = color.rgb(106, 116, 165), style = label.style_none, textcolor=color.rgb(106, 116, 165))
  35.         label.set_xy(lb, bar_index + 50, _p + syminfo.mintick*0.5)
  36.         label.set_text(lb, _text + ": " + str.tostring(_p))
  37.         label.set_color(lb, _color)
  38.  
  39. // Display Previous Day Values if toggle is on
  40. if show_prev_day_high
  41.     f_line_and_label(dh1, color.rgb(228, 19, 19), "↰ High")
  42. if show_prev_day_low
  43.     f_line_and_label(dl1, color.rgb(21, 204, 125), "↰ Low")
  44. if show_prev_day_close
  45.     f_line_and_label(dc1, color.rgb(45, 140, 224), "↰ Close")
  46.  
  47.  
  48. // VWAP
  49. // © Texmoonbeam
  50.  
  51. //Settings
  52. s = "Settings"
  53. zone = input.string('GMT+1', title='Timezone', options=['GMT-11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-2', 'GMT-1', 'GMT', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+330', 'GMT+4', 'GMT+430', 'GMT+5', 'GMT+530', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11', 'GMT+12'], group = s)
  54. vwap_source = input.source(close, "VWAP Source", group = s)
  55. std_dev  = input.float(defval = 0.5, minval = 0, maxval = 10, title = "Std Deviation Multiplier", group = s)
  56. width = input.int(1, 'Line Width', minval=0, group = s)
  57. leftbars  = input.int(defval = 30, title = "Left Bars for Pivots", minval = 0, group = s)
  58. //rightbars  = input.int(defval = 10, title = "Right Bars for Pivots", minval = 0, group = s)
  59. OSession = input.session("0800-1800:1234567", "Session Time", group=s)
  60.  
  61. // Anchors
  62. g = "AVWAPs"
  63. t = "NOTE: Pivots can only be used with High/Low anchors, Sessions can only be used with Open anchors"
  64. show_hist  = input.bool(defval = true, title = "Show Historical Periods?", group = g, tooltip = "Ticked will show all historical anchor changes based on the period, unticked will just show the most recent period. Does not affect pivots or sessions.")
  65. vwap1_reset = input.string(defval = "Monthly", title = "VWAP 1 Period", options = ["Daily", "Weekly", "Monthly", "Quarterly", "Yearly","All Time", "Pivot", "Session"], group = g, inline = "1", tooltip = t)
  66. vwap_col1 = input.color(defval=color.new(#3fbadf, 0), title='Colour', inline = "1", group = g)
  67. show_vwap1_Open  = input.bool(defval = true, title = "Open Anchor       ", group = g, inline="1a")
  68. show_vwap1_Open_sd  = input.bool(defval = true, title = "With Std Deviation Band", group = g, inline="1a")
  69. show_vwap1_High  = input.bool(defval = false, title = "High Anchor        ", group = g, inline="1b")
  70. show_vwap1_High_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="1b")
  71. show_vwap1_Low  = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="1c")
  72. show_vwap1_Low_sd  = input.bool(defval = false, title = "With Std Deviation Band\n", group = g, inline="1c")
  73.  
  74. vwap2_reset = input.string(defval = "Daily", title = "VWAP 2 Period", options =["Daily", "Weekly", "Monthly", "Quarterly", "Yearly","All Time", "Pivot", "Session"], group = g, inline = "2", tooltip = t)
  75. vwap_col2 = input.color(defval=color.new(#edd81f, 0), title='Colour', inline = "2", group = g)
  76. show_vwap2_Open  = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="2a")
  77. show_vwap2_Open_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2a")
  78. show_vwap2_High  = input.bool(defval = false, title = "High Anchor        ", group = g, inline="2b")
  79. show_vwap2_High_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2b")
  80. show_vwap2_Low  = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="2c")
  81. show_vwap2_Low_sd  = input.bool(defval = false, title = "With Std Deviation Band\n", group = g, inline="2c")
  82.  
  83. vwap3_reset = input.string(defval = "All Time", title = "VWAP 3 Period", options =["Daily", "Weekly", "Monthly", "Quarterly", "Yearly","All Time", "Pivot", "Session"], group = g, inline = "3", tooltip = t)
  84. vwap_col3 = input.color(defval=color.new(#8b32ff, 0), title='Colour', inline = "3", group = g)
  85. show_vwap3_Open  = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="3a")
  86. show_vwap3_Open_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="3a")
  87. show_vwap3_High  = input.bool(defval = false, title = "High Anchor        ", group = g, inline="3b")
  88. show_vwap3_High_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="3b")
  89. show_vwap3_Low  = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="3c")
  90. show_vwap3_Low_sd  = input.bool(defval = false, title = "With Std Deviation Band\n", group = g, inline="3c")
  91.  
  92. // vwap4_reset = input.string(defval = "Monthly", title = "VWAP 4 Period", options =["Daily", "Weekly", "Monthly", "Quarterly", "Yearly","All Time", "Pivot", "Session"], group = g, inline = "2")
  93. // show_vwap4_Open  = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="2a")
  94. // show_vwap4_Open_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2a")
  95. // show_vwap4_High  = input.bool(defval = false, title = "High Anchor        ", group = g, inline="2b")
  96. // show_vwap4_High_sd  = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2b")
  97. // show_vwap4_Low  = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="2c")
  98. // show_vwap4_Low_sd  = input.bool(defval = false, title = "With Std Deviation Band\n", group = g, inline="2c")
  99.  
  100. // List Of Anchors
  101. // Daily Open
  102. // Weekly Open
  103. // Monthly Open
  104. // Yearly Open
  105. // Daily High
  106. // Daily Low
  107. // Weekly High
  108. // Weekly Low
  109. // Monthly High
  110. // Monthly Low
  111. // Yearly High
  112. // Yearly Low
  113. // All time high
  114. // All time low
  115. // All time open
  116. // Customn Pivot Highs
  117. // Custom Pivot Lows
  118. // Session Open
  119.  
  120. //Functions
  121.  
  122. ResolutionToSec(res)=>
  123.     mins = res == "1" ? 1 :
  124.            res == "3" ? 3 :
  125.            res == "5" ? 5 :
  126.            res == "10" ? 10 :
  127.            res == "15" ? 15 :
  128.            res == "30" ? 30 :
  129.            res == "45" ? 45 :
  130.            res == "60" ? 60 :
  131.            res == "120" ? 120 :
  132.            res == "180" ? 180 :
  133.            res == "240" ? 240 :
  134.            res == "D" or res == "1D" ? 1440 :
  135.            res == "W" or res == "1W" ? 10080 :
  136.            res == "M" or res == "1M" ? 43200 :
  137.            res == "" ? int(str.tonumber(timeframe.period)) :
  138.            str.substring(timeframe.period, 2, 3) == "S" ? int(str.tonumber(str.substring(timeframe.period, 0, 2)))/60 : int(str.tonumber(res))
  139.     ms = mins * 60 * 1000
  140.  
  141. GetChartHighest(dataSeries = high) =>
  142.     var chartHighest = dataSeries
  143.     if dataSeries > nz(chartHighest, -1e10)
  144.         chartHighest := dataSeries
  145.     chartHighest
  146.  
  147. GetAllTimeHigh(dataSeries = high) =>
  148.     highestHTF = request.security(syminfo.tickerid, "D", GetChartHighest(dataSeries)[1], lookahead=barmerge.lookahead_on)
  149.     highestChartTF = GetChartHighest(dataSeries)
  150.     math.max(highestHTF, highestChartTF)
  151.  
  152. GetChartLowest(dataSeries = low) =>
  153.     var chartLowest = dataSeries
  154.     if dataSeries < nz(chartLowest, 1e10)
  155.         chartLowest := dataSeries
  156.     chartLowest
  157.  
  158. GetAllTimeLow(dataSeries = low) =>
  159.     lowestHTF = request.security(syminfo.tickerid, "D",
  160.          GetChartLowest(dataSeries)[1], lookahead=barmerge.lookahead_on)
  161.     lowestChartTF = GetChartLowest(dataSeries)
  162.     math.min(lowestHTF, lowestChartTF)
  163.  
  164. f_get_started (_session) => na(_session[1]) and _session
  165.  
  166. //Variables & Change Detection
  167.  
  168. int sess1 = time(timeframe.period, OSession, zone)
  169.  
  170. var dh = 0.0
  171. var dl = 0.0
  172. var wh = 0.0
  173. var wl = 0.0
  174. var mh = 0.0
  175. var ml = 0.0
  176. var qh = 0.0
  177. var ql = 0.0
  178. var yh = 0.0
  179. var yl = 0.0
  180.  
  181. bar = ResolutionToSec(timeframe.period)
  182.  
  183. vis_bars = ((chart.right_visible_bar_time - chart.left_visible_bar_time) / bar)
  184.  
  185. year_change = show_hist ? year(time, zone) != year(time[1], zone) : year(time, zone) != year(time[1], zone) and  time > (timenow - (86400000 * 366))
  186. quarterly_change = show_hist ? ((month(time, zone) == 4 and month(time[1], zone) == 3) or (month(time, zone) == 7 and month(time[1], zone) == 6) or (month(time, zone) == 10 and month(time[1], zone) == 9) or (month(time, zone) == 1 and month(time[1], zone) == 12)) : ((month(time, zone) == 4 and month(time[1], zone) == 3) or (month(time, zone) == 7 and month(time[1], zone) == 6) or (month(time, zone) == 10 and month(time[1], zone) == 9) or (month(time, zone) == 1 and month(time[1], zone) == 12)) and time > (timenow - (86400000 * 94))
  187. month_change = show_hist ? month(time, zone) != month(time[1], zone) : month(time, zone) != month(time[1], zone) and time > (timenow - (86400000 * 32))
  188. week_change = show_hist ? dayofweek(time, zone) == 2 and dayofweek(time[1], zone) == 1 : dayofweek(time, zone) == 2 and dayofweek(time[1], zone) == 1 and time > (timenow - (86400000 * 8))
  189. day_change = show_hist ? dayofweek(time, zone) != dayofweek(time[1], zone) : dayofweek(time, zone) != dayofweek(time[1], zone) and time > (timenow - (86460000 ))
  190.  
  191. if not(year_change)
  192.     if high > yh
  193.         yh := high
  194.     if low < yl
  195.         yl := low
  196. else
  197.     yh := high
  198.     yl := low
  199.  
  200. if not(quarterly_change)
  201.     if high > qh
  202.         qh := high
  203.     if low < ql
  204.         ql := low
  205. else
  206.     qh := high
  207.     ql := low
  208.  
  209. if not(month_change)
  210.     if high > mh
  211.         mh := high
  212.     if low < ml
  213.         ml := low
  214. else
  215.     mh := high
  216.     ml := low
  217. if not(week_change)
  218.     if high > wh
  219.         wh := high
  220.     if low < wl
  221.         wl := low
  222. else
  223.     wh := high
  224.     wl := low
  225.  
  226. if not(day_change)
  227.     if high > dh
  228.         dh := high
  229.     if low < dl
  230.         dl := low
  231. else
  232.     dh := high
  233.     dl := low
  234.  
  235. yh_change = show_hist ? yh > yh[1] or year_change : (yh > yh[1] or year_change) and time > (timenow - (86400000 * 366))
  236. qh_change = show_hist ? qh > qh[1] or quarterly_change : (qh > qh[1] or quarterly_change) and time > (timenow - (86400000 * 94))
  237. mh_change = show_hist ? mh > mh[1] or month_change : (mh > mh[1] or month_change ) and time > (timenow - (86400000 * 32))
  238. wh_change = show_hist ? wh > wh[1] or week_change : (wh > wh[1] or week_change ) and time > (timenow - (86400000 * 8))
  239. dh_change = show_hist ? dh > dh[1] or day_change : (dh > dh[1] or day_change) and time > (timenow - (86460000 ))
  240.  
  241.  
  242. yl_change = show_hist ? yl < yl[1] or year_change :(yl < yl[1] or year_change) and time > (timenow - (86400000 * 366))
  243. ql_change = show_hist ? ql < ql[1] or quarterly_change : (ql < ql[1] or quarterly_change) and time > (timenow - (86400000 * 94))
  244. ml_change = show_hist ? ml < ml[1] or month_change : (ml < ml[1] or month_change ) and time > (timenow - (86400000 * 32))
  245. wl_change = show_hist ? wl < wl[1] or week_change : (wl < wl[1] or week_change ) and time > (timenow - (86400000 * 8))
  246. dl_change = show_hist ? dl < dl[1] or day_change : (dl < dl[1] or day_change) and time > (timenow - (86460000 ))
  247.  
  248. ath = GetAllTimeHigh(high)
  249. ath_change = ath > ath[1]
  250.  
  251. atl = GetAllTimeLow(high)
  252. atl_change = atl < atl[1]
  253.  
  254. ph = ta.pivothigh(leftbars, 0)
  255. pl = ta.pivotlow(leftbars, 0)
  256.  
  257. ph_change = not na(ph)
  258. pl_change = not na(pl)
  259.  
  260. sess_start = f_get_started(sess1)
  261.  
  262. vwap1_open_change = vwap1_reset == "Daily" ? day_change : vwap1_reset == "Weekly" ? week_change : vwap1_reset == "Monthly" ? month_change : vwap1_reset == "Quarterly" ? quarterly_change : vwap1_reset == "Yearly" ? year_change : vwap1_reset == "All Time" ? barstate.isfirst : vwap1_reset == "Session" ? sess_start : na
  263. vwap1_high_change = vwap1_reset == "Daily" ? dh_change : vwap1_reset == "Weekly" ? wh_change : vwap1_reset == "Monthly" ? mh_change : vwap1_reset == "Quarterly" ? qh_change : vwap1_reset == "Yearly" ? yh_change : vwap1_reset == "All Time" ? ath_change : vwap1_reset == "Pivot" ? ph_change :  na
  264. vwap1_low_change = vwap1_reset == "Daily" ? dl_change : vwap1_reset == "Weekly" ? wl_change : vwap1_reset == "Monthly" ? ml_change : vwap1_reset == "Quarterly" ? ql_change : vwap1_reset == "Yearly" ? yl_change : vwap1_reset == "All Time" ? atl_change : vwap1_reset == "Pivot" ? pl_change : na
  265.  
  266. vwap2_open_change = vwap2_reset == "Daily" ? day_change : vwap2_reset == "Weekly" ? week_change : vwap2_reset == "Monthly" ? month_change : vwap2_reset == "Quarterly" ? quarterly_change : vwap2_reset == "Yearly" ? year_change : vwap2_reset == "All Time" ? barstate.isfirst : vwap2_reset == "Session" ? sess_start : na
  267. vwap2_high_change = vwap2_reset == "Daily" ? dh_change : vwap2_reset == "Weekly" ? wh_change : vwap2_reset == "Monthly" ? mh_change : vwap2_reset == "Quarterly" ? qh_change : vwap2_reset == "Yearly" ? yh_change : vwap2_reset == "All Time" ? ath_change : vwap2_reset == "Pivot" ? ph_change :  na
  268. vwap2_low_change = vwap2_reset == "Daily" ? dl_change : vwap2_reset == "Weekly" ? wl_change : vwap2_reset == "Monthly" ? ml_change : vwap2_reset == "Quarterly" ? ql_change : vwap2_reset == "Yearly" ? yl_change : vwap2_reset == "All Time" ? atl_change : vwap2_reset == "Pivot" ? pl_change : na
  269.  
  270. vwap3_open_change = vwap3_reset == "Daily" ? day_change : vwap3_reset == "Weekly" ? week_change : vwap3_reset == "Monthly" ? month_change : vwap3_reset == "Quarterly" ? quarterly_change : vwap3_reset == "Yearly" ? year_change : vwap3_reset == "All Time" ? barstate.isfirst : vwap3_reset == "Session" ? sess_start : na
  271. vwap3_high_change = vwap3_reset == "Daily" ? dh_change : vwap3_reset == "Weekly" ? wh_change : vwap3_reset == "Monthly" ? mh_change : vwap3_reset == "Quarterly" ? qh_change : vwap3_reset == "Yearly" ? yh_change : vwap3_reset == "All Time" ? ath_change : vwap3_reset == "Pivot" ? ph_change :  na
  272. vwap3_low_change = vwap3_reset == "Daily" ? dl_change : vwap3_reset == "Weekly" ? wl_change : vwap3_reset == "Monthly" ? ml_change : vwap3_reset == "Quarterly" ? ql_change : vwap3_reset == "Yearly" ? yl_change : vwap3_reset == "All Time" ? atl_change : vwap3_reset == "Pivot" ? pl_change : na
  273.  
  274. //debug
  275. // if wh_change
  276. //     label.new(bar_index, high, text = "h")
  277.  
  278.  
  279. // Plot all the vwaps!
  280.  
  281. [vwap1_open_vwap, upper_vwap1_open_vwap, lower_vwap1_open_vwap] = ta.vwap(show_vwap1_Open ? vwap_source : na, vwap1_open_change, std_dev)
  282. [vwap1_high_vwap, upper_vwap1_high_vwap, lower_vwap1_high_vwap] = ta.vwap(show_vwap1_High ? vwap_source : na, vwap1_high_change, std_dev)
  283. [vwap1_low_vwap, upper_vwap1_low_vwap, lower_vwap1_low_vwap] = ta.vwap(show_vwap1_Low ? vwap_source : na, vwap1_low_change, std_dev)
  284.  
  285. [vwap2_open_vwap, upper_vwap2_open_vwap, lower_vwap2_open_vwap] = ta.vwap(show_vwap2_Open ? vwap_source : na, vwap2_open_change, std_dev)
  286. [vwap2_high_vwap, upper_vwap2_high_vwap, lower_vwap2_high_vwap] = ta.vwap(show_vwap2_High ? vwap_source : na, vwap2_high_change, std_dev)
  287. [vwap2_low_vwap, upper_vwap2_low_vwap, lower_vwap2_low_vwap] = ta.vwap(show_vwap2_Low ? vwap_source : na, vwap2_low_change, std_dev)
  288.  
  289. [vwap3_open_vwap, upper_vwap3_open_vwap, lower_vwap3_open_vwap] = ta.vwap(show_vwap3_Open ? vwap_source : na, vwap3_open_change, std_dev)
  290. [vwap3_high_vwap, upper_vwap3_high_vwap, lower_vwap3_high_vwap] = ta.vwap(show_vwap3_High ? vwap_source : na, vwap3_high_change, std_dev)
  291. [vwap3_low_vwap, upper_vwap3_low_vwap, lower_vwap3_low_vwap] = ta.vwap(show_vwap3_Low ? vwap_source : na, vwap3_low_change, std_dev)
  292.  
  293.  
  294.  
  295.  plot(show_vwap1_Open_sd ? upper_vwap1_open_vwap : na, "VWAP 1 Open Upper", vwap_col1, width,
  296.  plot(vwap1_open_vwap, "VWAP 1 Open", vwap_col1, width,
  297.  plot(show_vwap1_Open_sd ? lower_vwap1_open_vwap : na, "VWAP 1 Open Lower", vwap_col1, width,
  298.  
  299.  plot(show_vwap1_High_sd ? upper_vwap1_high_vwap : na, "VWAP 1 High Upper", vwap_col1, width,
  300.  plot(vwap1_high_vwap, "VWAP 1 High", vwap_col1, width,
  301.  plot(show_vwap1_High_sd ? lower_vwap1_high_vwap : na, "VWAP 1 High Lower", vwap_col1, width,
  302.  
  303.  plot(show_vwap1_Low_sd ? upper_vwap1_low_vwap : na, "VWAP 1 Low Upper", vwap_col1, width,
  304.  plot(vwap1_low_vwap, "VWAP 1 Low", vwap_col1, width,
  305.  plot(show_vwap1_Low_sd ? lower_vwap1_low_vwap : na, "VWAP 1 Low Lower", vwap_col1, width,
  306.  
  307.  plot(show_vwap2_Open_sd ? upper_vwap2_open_vwap : na, "VWAP 2 Open Upper", vwap_col2, width,
  308.  plot(vwap2_open_vwap, "VWAP 2 Open", vwap_col2, width,
  309.  plot(show_vwap2_Open_sd ? lower_vwap2_open_vwap : na, "VWAP 2 Open Lower", vwap_col2, width,
  310.  
  311.  plot(show_vwap2_High_sd ? upper_vwap2_high_vwap : na, "VWAP 2 High Upper", vwap_col2, width,
  312.  plot(vwap2_high_vwap, "VWAP 2 High", vwap_col2, width,
  313.  plot(show_vwap2_High_sd ? lower_vwap2_high_vwap : na, "VWAP 2 High Lower", vwap_col2, width,
  314.  
  315.  plot(show_vwap2_Low_sd ? upper_vwap2_low_vwap : na, "VWAP 2 Low Upper", vwap_col2, width,
  316.  plot(vwap2_low_vwap, "VWAP 2 Low", vwap_col2, width,
  317.  plot(show_vwap2_Low_sd ? lower_vwap2_low_vwap : na, "VWAP 2 Low Lower", vwap_col2, width,
  318.  
  319.  plot(show_vwap3_Open_sd ? upper_vwap3_open_vwap : na, "VWAP 3 Open Upper", vwap_col3, width,
  320.  plot(vwap3_open_vwap, "VWAP 3 Open", vwap_col3, width,
  321.  plot(show_vwap3_Open_sd ? lower_vwap3_open_vwap : na, "VWAP 3 Open Lower", vwap_col3, width,
  322.  
  323.  plot(show_vwap3_High_sd ? upper_vwap3_high_vwap : na, "VWAP 3 High Upper", vwap_col3, width,
  324.  plot(vwap3_high_vwap, "VWAP 3 High", vwap_col3, width,
  325.  plot(show_vwap3_High_sd ? lower_vwap3_high_vwap : na, "VWAP 3 High Lower", vwap_col3, width,
  326.  
  327.  plot(show_vwap3_Low_sd ? upper_vwap3_low_vwap : na, "VWAP 3 Low Upper", vwap_col3, width,
  328.  plot(vwap3_low_vwap, "VWAP 3 Low", vwap_col3, width,
  329.  plot(show_vwap3_Low_sd ? lower_vwap3_low_vwap : na, "VWAP 3 Low Lower", vwap_col3, width,
  330.  
  331.  
  332.  
  333. // //debug
  334. // if barstate.islast and (timenow - time) >= (timenow - ph_time)
  335.  
  336. //     label.new(bar_index, high, "x")
  337.  
  338. //sma's
  339. srcsma = close
  340. HTFsma = input.timeframe('D', 'TimeFrame')
  341.  
  342. len1 = input.int(5, minval=1, title='SMA1')
  343. len2 = input.int(9, minval=1, title='SMA2')
  344. len3 = input.int(20, minval=1, title='SMA3')
  345. len4 = input.int(50, minval=1, title='SMA4')
  346. len5 = input.int(100, minval=1, title='SMA5')
  347. len6 = input.int(200, minval=1, title='SMA6')
  348.  
  349. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len1)), len1), title='SMA1', color=color.rgb(255, 255, 255), linewidth=2)
  350. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len2)), len1), title='SMA2', color=color.rgb(162, 163, 163), linewidth=2)
  351. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len3)), len1), title='SMA3', color=color.rgb(46, 211, 112), linewidth=2)
  352. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len4)), len1), title='SMA4', color=color.rgb(247, 91, 91), linewidth=2)
  353. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len5)), len1), title='SMA5', color=color.rgb(31, 106, 61), linewidth=2)
  354. plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len6)), len1), title='SMA6', color=color.rgb(161, 23, 23), linewidth=2)
  355.  
  356. //ema's
  357. srcema = close
  358. HTFema = input.timeframe('1', 'TimeFrame')
  359.  
  360. elen1 = input.int(9, minval=1, title='EMA1')
  361. elen2 = input.int(20, minval=1, title='EMA2')
  362. elen3 = input.int(200, minval=1, title='EMA3')
  363.  
  364. plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen1)), len1), title='EMA1', color=color.rgb(70, 210, 242), linewidth=1)
  365. plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen2)), len1), title='EMA2', color=color.rgb(196, 196, 196), linewidth=1)
  366. plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen3)), len1), title='EMA3', color=color.rgb(155, 155, 155), linewidth=1)
  367.  
  368. //FFIBS
  369.  
  370. //----------settings----------//
  371. var g0      = 'Order Block Settings'
  372. barsReq     = input.int(6, 'Consecutive Bars Required', group = g0, tooltip = 'The number of bars required after the last bullish or bearish bar to validate an order block')
  373. percGain    = input.float(0.0, 'Percent Gain Required', step = 0.1, group = g0, tooltip = 'The minimum percent gain or loss of the consecutive bars required to validate an order block')
  374. opposites   = input.bool(false, 'Require Opposite Order Block', group = g0, tooltip = 'Requires an order block in the opposite direction of the previous order block before a new order block is marked')
  375. mitType     = input.string('Wicks', 'Mitigation Type', ['Wicks', 'Close'])
  376. irrOb       = input.string('Length', 'Irrelevant Order Block ', ['Length', 'Distance'], group = g0, tooltip = 'Method for considering Order Blocks irrelevant. Either too long (length) or too far away from current price (distance)')
  377. maxObLen    = input.int(150, 'Max Ob Length or Distance', group = g0, tooltip = 'Maximum bar length or % distance away from Order Block to be considered irrelevant')
  378.  
  379. var g1      = 'Order Block Display Settings'
  380. showOb      = input.bool(true, 'Show Order Blocks', group = g1)
  381. hideOld     = input.bool(false, 'Remove Old or Irrelevant Order Blocks', group = g1)
  382. bullCol     = input.color(color.new(#4caf4f, 60), 'Bullish Color', group = g1)
  383. bearCol     = input.color(color.new(color.red,60), 'Bearish Color', group = g1)
  384.  
  385. var g2      = 'Fibs'
  386. showFibs    = input.bool(true, 'Show Fibs', group = g2)
  387. retraceMax  = input.bool(true,'Stop Fib Recalculation After Retracement', group = g2, tooltip = 'Will stop fibs from recalculating when a new high or low is made, if the retracement level has been hit')
  388. retracelev  = input.string('Order Block', 'Rectracement Level', ['Order Block', '.50', '.618', '.786'], group = g2)
  389. fibStyle    = input.string('Dashed', 'Line style ', options = ['Dashed', 'Dotted', 'Solid'], group = g2, inline = '2')
  390. extLines    = input.bool(false, 'Extend', group = g2, inline = '2')
  391. textColor   = input.color(color.rgb(255, 253, 253), 'Fib Label Color', group = g2)
  392. show_236    = input.bool(true, '.236', inline = '3', group = g2)
  393. color_236   = input.color(#6a74a5, '', inline = '3', group = g2)
  394. show_382    =  input.bool(true, '.382', inline = '3', group = g2)
  395. color_382   = input.color(#6a74a5, '', inline = '3', group = g2)
  396. show_50     = input.bool(true, '.50', inline = '3', group = g2)
  397. color_50    = input.color(#edd81f, '', inline = '3', group = g2)
  398. show_618    = input.bool(true, '.618', inline = '4', group = g2)
  399. color_618   = input.color(#edd81f, '', inline = '4', group = g2)
  400. show_786    = input.bool(true, '.786', inline = '4', group = g2)
  401. color_786   = input.color(#6a74a5, '', inline = '4', group = g2)
  402. show_hl     = input.bool(true, '0 & 1', inline = '4', group = g2)
  403. color_hl    = input.color(#ffffff, '', inline = '4', group = g2)
  404.  
  405. //----------types----------//
  406. type obFibs
  407.     bool a = true
  408.     bool bull = true
  409.     int idx
  410.     float l
  411.     float h
  412.     float chl
  413.     bool ret = false
  414.     float [] levArr
  415.     line [] lineArr
  416.     label [] labArr
  417.     label retLab
  418.  
  419. type obBox
  420.     bool a = true
  421.     bool bull = true
  422.     float top
  423.     float bottom
  424.     box bx
  425.  
  426. //----------switch----------//
  427. method switcher(string this) =>
  428.     switch this
  429.         'Solid'  => line.style_solid
  430.         'Dashed' => line.style_dashed
  431.         'Dotted' => line.style_dotted
  432.  
  433. //----------variables----------//
  434. var obFibsArr   = array.new<obFibs>()
  435. var obBoxArr    = array.new<obBox>()
  436. var fibBoolArr  = array.from(show_hl, show_hl, show_236, show_382, show_50, show_618, show_786)
  437. var fibColArr   = array.from(color_hl, color_hl, color_236, color_382, color_50, color_618, color_786)
  438. var fibLevArr   = array.from('0', '1', '.236', '.382', '.50', '.618', '.786')
  439. var bu          = false
  440. var be          = false
  441. barsCount       = 0
  442. lines           = line.all
  443. labels          = label.all
  444.  
  445. //----------calculations----------//
  446. if irrOb == 'Distance'
  447.     maxObLen := maxObLen / 100
  448.  
  449. gainBull    = ((math.abs(low[barsReq] - close))/low[barsReq]) * 100
  450. gainBear    = ((math.abs(high[barsReq] - close))/high[barsReq]) * 100
  451. gainCheck   = gainBull >= percGain or gainBear >= percGain
  452.  
  453. lastDown    = close[barsReq] < open[barsReq]
  454. lastUp      = close[barsReq] > open[barsReq]
  455.  
  456. if lastDown
  457.     for i = 0 to barsReq
  458.         if close[i] > open[i]
  459.             barsCount += 1
  460.            
  461. if lastUp
  462.     for i = 0 to barsReq
  463.         if close[i] < open[i]
  464.             barsCount += 1
  465.  
  466. //----------conditions----------//
  467. bullish = lastDown and barsCount >= barsReq and gainCheck and (opposites ? not bu : not bu or bu)
  468. bearish = lastUp and barsCount >= barsReq and gainCheck and (opposites ? not be : not be or be)
  469.  
  470. if bullish
  471.     for l in lines
  472.         l.delete()
  473.     for l in labels
  474.         l.delete()
  475.     bu := true
  476.     be := false
  477.     fibTotal = high - low[barsReq]
  478.     lev236   = high - (fibTotal * .236)
  479.     lev382   = high - (fibTotal * .382)
  480.     lev50    = high - (fibTotal * .5)
  481.     lev618   = high - (fibTotal * .618)
  482.     lev786   = high - (fibTotal * .786)
  483.     newFibs = obFibs.new(true, true, bar_index[barsReq], low[barsReq], high[barsReq], high, false, array.from(high, low[barsReq], lev236, lev382, lev50, lev618, lev786), array.new<line>(), array.new<label>())
  484.     if showFibs
  485.         for i = 0 to newFibs.levArr.size()-1
  486.             if fibBoolArr.get(i) == true
  487.                 newFibs.lineArr.unshift(line.new(newFibs.idx, newFibs.levArr.get(i), bar_index, newFibs.levArr.get(i), color = fibColArr.get(i), extend = extLines ? extend.right : extend.none, style = fibStyle.switcher()))
  488.                 newFibs.labArr.unshift(label.new(newFibs.idx, newFibs.levArr.get(i), str.tostring(fibLevArr.get(i)) + ' ($' + str.tostring(newFibs.levArr.get(i), format.mintick) + ')', color=color.new(color.white,100), style = label.style_label_right, textcolor = textColor))
  489.     obFibsArr.unshift(newFibs)
  490.     if showOb
  491.         obBoxArr.unshift(obBox.new(true, true, high[barsCount], low[barsReq], box.new(bar_index[barsReq], high[barsReq], bar_index, low[barsReq], bullCol, bgcolor = bullCol)))
  492.         alert&#40;'New Bullish Order Block', alert.freq_once_per_bar_close&#41;
  493. if bearish
  494.     for l in lines
  495.         l.delete()
  496.     for l in labels
  497.         l.delete()
  498.     be := true
  499.     bu := false
  500.     fibTotal = high[barsReq] - low
  501.     lev236   = low + (fibTotal * .236)
  502.     lev382   = low + (fibTotal * .382)
  503.     lev50    = low +(fibTotal * .5)
  504.     lev618   = low + (fibTotal * .618)
  505.     lev786   = low + (fibTotal * .786)
  506.     newFibs = obFibs.new(true, false, bar_index[barsReq], low[barsReq], high[barsReq], low, false, array.from(low, high[barsReq], lev236, lev382, lev50, lev618, lev786), array.new<line>(), array.new<label>())
  507.     if showFibs
  508.         for i = 0 to newFibs.levArr.size()-1
  509.             if fibBoolArr.get(i) == true
  510.                 newFibs.lineArr.unshift(line.new(newFibs.idx, newFibs.levArr.get(i), bar_index, newFibs.levArr.get(i), color = fibColArr.get(i), extend = extLines ? extend.right : extend.none, style = fibStyle.switcher()))
  511.                 newFibs.labArr.unshift(label.new(newFibs.idx, newFibs.levArr.get(i), str.tostring(fibLevArr.get(i)) + ' ($' + str.tostring(newFibs.levArr.get(i), format.mintick) + ')', color=color.new(color.white,100), style = label.style_label_right, textcolor = textColor))
  512.     obFibsArr.unshift(newFibs)
  513.     if showOb
  514.         obBoxArr.unshift(obBox.new(true, false, high[barsCount], low[barsReq], box.new(bar_index[barsReq], high[barsReq], bar_index, low[barsReq], bearCol, bgcolor = bearCol)))
  515.         alert&#40;'New Bearish Order Block', alert.freq_once_per_bar_close&#41;
  516.  
  517. //----------fib management----------//
  518. if obFibsArr.size() > 0
  519.     for b in obFibsArr
  520.         if b.a
  521.             for l in b.lineArr
  522.                 l.set_x2(bar_index)
  523.             if b.bull
  524.                 retlev = retracelev == 'Order Block' ? b.h : retracelev == '.50' ? b.levArr.get(4) : retracelev == '.618' ? b.levArr.get(5) : b.levArr.get(6)
  525.                 if low <= retlev and retraceMax and not b.ret
  526.                     b.ret    := true
  527.                      b.retLab := label.new(bar_index,low,'?',  yloc = yloc.belowbar)
  528.                     alert&#40;'Retracement Level Hit', alert.freq_once_per_bar&#41;
  529.                 if high > b.chl and not b.ret
  530.                     b.chl    := high
  531.                     fibTotal = b.chl - b.l
  532.                     lev236   = b.chl - (fibTotal * .236)
  533.                     lev382   = b.chl - (fibTotal * .382)
  534.                     lev50    = b.chl - (fibTotal * .5)
  535.                     lev618   = b.chl - (fibTotal * .618)
  536.                     lev786   = b.chl - (fibTotal * .786)
  537.                     b.levArr := array.from(b.chl, b.l, lev236, lev382, lev50, lev618, lev786)
  538.                     for l in b.lineArr
  539.                         l.delete()
  540.                     for l in b.labArr
  541.                         l.delete()
  542.                     if showFibs
  543.                         for i = 0 to b.levArr.size()-1
  544.                             if fibBoolArr.get(i) == true
  545.                                 b.lineArr.unshift(line.new(b.idx, b.levArr.get(i), bar_index, b.levArr.get(i), color = fibColArr.get(i), extend = extLines ? extend.right : extend.none, style = fibStyle.switcher()))
  546.                                 b.labArr.unshift(label.new(b.idx, b.levArr.get(i), str.tostring(fibLevArr.get(i)) + ' ($' + str.tostring(b.levArr.get(i), format.mintick) + ')', color=color.new(color.white,100), style = label.style_label_right, textcolor = textColor))
  547.                 if (be and not be[1] and opposites) or (close < b.l) or (bullish and bar_index > b.idx + barsReq and not opposites) or (retraceMax and high > b.chl)
  548.                     b.a := false
  549.                     if (bullish and bar_index > b.idx + barsReq and not opposites)
  550.                         for l in b.lineArr
  551.                             l.delete()
  552.                         for l in b.labArr
  553.                             l.delete()
  554.             if not b.bull
  555.                 retlev = retracelev == 'Order Block' ? b.h : retracelev == '.50' ? b.levArr.get(4) : retracelev == '.618' ? b.levArr.get(5) : b.levArr.get(6)
  556.                 if high >= retlev and retraceMax and not b.ret
  557.                     b.ret    := true
  558.                     b.retLab := label.new(bar_index,low,'?', style=label.style_none, yloc = yloc.abovebar)
  559.                     alert&#40;'Retracement Level Hit', alert.freq_once_per_bar&#41;
  560.                 if low < b.chl and not b.ret
  561.                     b.chl    := low
  562.                     fibTotal = b.h - b.chl
  563.                     lev236   = b.chl + (fibTotal * .236)
  564.                     lev382   = b.chl + (fibTotal * .382)
  565.                     lev50    = b.chl +(fibTotal * .5)
  566.                     lev618   = b.chl + (fibTotal * .618)
  567.                     lev786   = b.chl + (fibTotal * .786)
  568.                     b.levArr := array.from(b.chl, b.h, lev236, lev382, lev50, lev618, lev786)
  569.                     for l in b.lineArr
  570.                         l.delete()
  571.                     for l in b.labArr
  572.                         l.delete()
  573.                     if showFibs
  574.                         for i = 0 to b.levArr.size()-1
  575.                             if fibBoolArr.get(i) == true
  576.                                  b.lineArr.unshift(line.new(b.idx, b.levArr.get(i), bar_index, b.levArr.get(i), color = fibColArr.get(i), extend = extLines ? extend.right : extend.none,
  577.                                  b.labArr.unshift(label.new(b.idx, b.levArr.get(i), str.tostring(fibLevArr.get(i)) + ' ($' + str.tostring(b.levArr.get(i), format.mintick) + ')', color=color.new(color.white,100),  textcolor = textColor))
  578.                 if (bu and not bu[1] and opposites) or (close > b.h) or (bearish and bar_index > b.idx + barsReq and not opposites) or (retraceMax and low < b.chl)
  579.                     b.a := false
  580.                     if (bearish and bar_index > b.idx + barsReq and not opposites)
  581.                         for l in b.lineArr
  582.                             l.delete()
  583.                         for l in b.labArr
  584.                             l.delete()
  585.  
  586. //----------order block management----------//
  587. if obBoxArr.size() > 0
  588.     for bx in obBoxArr
  589.         if bx.a
  590.             bx.bx.set_right(bar_index)
  591.         if bx.bull
  592.             src = mitType == 'Wicks' ? low : close
  593.             if src <= bx.bx.get_top() or (irrOb == 'Length' and bar_index - bx.bx.get_left() > maxObLen-1 or irrOb == 'Distance' and low >= bx.bx.get_top()*(1+maxObLen))
  594.                 bx.a := false
  595.                 if hideOld
  596.                     bx.bx.delete()
  597.         else if not bx.bull
  598.             src = mitType == 'Wicks' ? high : close
  599.             if src >= bx.bx.get_bottom() or (irrOb == 'Length' and bar_index - bx.bx.get_left() > maxObLen-1 or irrOb == 'Distance' and high <= bx.bx.get_bottom()*(1-maxObLen))
  600.                 bx.a := false
  601.                 if hideOld
  602.                     bx.bx.delete()
  603.  
  604.  
  605.