// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © jjustingreyy //@version=5 indicator("Small Tilt Algo", overlay=true) plot(close) // Toggle for previous day levels show_prev_day_high = input(true, title="Show Previous Day High") show_prev_day_low = input(true, title="Show Previous Day Low") show_prev_day_close = input(true, title="Show Previous Day Close") //Previous Day Values // to highlight the session var line[] prevDayLines = array.new_line() prevDayOpen = na(nz(request.security(syminfo.tickerid, "D", time[1]))) isNewDay = not(na(prevDayOpen)) and prevDayOpen != request.security(syminfo.tickerid, "D", time) if isNewDay and array.size(prevDayLines) > 0 for i = 0 to array.size(prevDayLines) - 1 line.delete(array.get(prevDayLines, i)) array.clear(prevDayLines) [dh1,dl1,dc1, dv1] = request.security(syminfo.ticker, "D", [high[1],low[1], close[1], ta.vwap[1]], lookahead=barmerge.lookahead_on) // Function to create line and label f_line_and_label(_p, _color, _text) => if (not na(_p)) l = line.new(x1=na, y1=_p, x2=bar_index + 50, y2=_p, width = 1, color=_color, extend = extend.right) array.push(prevDayLines, l) var label lb = na if (na(lb)) lb := label.new(na, na, "", color = color.rgb(106, 116, 165), style = label.style_none, textcolor=color.rgb(106, 116, 165)) label.set_xy(lb, bar_index + 50, _p + syminfo.mintick*0.5) label.set_text(lb, _text + ": " + str.tostring(_p)) label.set_color(lb, _color) // Display Previous Day Values if toggle is on if show_prev_day_high f_line_and_label(dh1, color.rgb(228, 19, 19), "↰ High") if show_prev_day_low f_line_and_label(dl1, color.rgb(21, 204, 125), "↰ Low") if show_prev_day_close f_line_and_label(dc1, color.rgb(45, 140, 224), "↰ Close") // VWAP // © Texmoonbeam //Settings s = "Settings" 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) vwap_source = input.source(close, "VWAP Source", group = s) std_dev = input.float(defval = 0.5, minval = 0, maxval = 10, title = "Std Deviation Multiplier", group = s) width = input.int(1, 'Line Width', minval=0, group = s) leftbars = input.int(defval = 30, title = "Left Bars for Pivots", minval = 0, group = s) //rightbars = input.int(defval = 10, title = "Right Bars for Pivots", minval = 0, group = s) OSession = input.session("0800-1800:1234567", "Session Time", group=s) // Anchors g = "AVWAPs" t = "NOTE: Pivots can only be used with High/Low anchors, Sessions can only be used with Open anchors" 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.") 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) vwap_col1 = input.color(defval=color.new(#3fbadf, 0), title='Colour', inline = "1", group = g) show_vwap1_Open = input.bool(defval = true, title = "Open Anchor       ", group = g, inline="1a") show_vwap1_Open_sd = input.bool(defval = true, title = "With Std Deviation Band", group = g, inline="1a") show_vwap1_High = input.bool(defval = false, title = "High Anchor        ", group = g, inline="1b") show_vwap1_High_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="1b") show_vwap1_Low = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="1c") show_vwap1_Low_sd = input.bool(defval = false, title = "With Std Deviation Bandn", group = g, inline="1c") 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) vwap_col2 = input.color(defval=color.new(#edd81f, 0), title='Colour', inline = "2", group = g) show_vwap2_Open = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="2a") show_vwap2_Open_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2a") show_vwap2_High = input.bool(defval = false, title = "High Anchor        ", group = g, inline="2b") show_vwap2_High_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2b") show_vwap2_Low = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="2c") show_vwap2_Low_sd = input.bool(defval = false, title = "With Std Deviation Bandn", group = g, inline="2c") 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) vwap_col3 = input.color(defval=color.new(#8b32ff, 0), title='Colour', inline = "3", group = g) show_vwap3_Open = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="3a") show_vwap3_Open_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="3a") show_vwap3_High = input.bool(defval = false, title = "High Anchor        ", group = g, inline="3b") show_vwap3_High_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="3b") show_vwap3_Low = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="3c") show_vwap3_Low_sd = input.bool(defval = false, title = "With Std Deviation Bandn", group = g, inline="3c") // vwap4_reset = input.string(defval = "Monthly", title = "VWAP 4 Period", options =["Daily", "Weekly", "Monthly", "Quarterly", "Yearly","All Time", "Pivot", "Session"], group = g, inline = "2") // show_vwap4_Open = input.bool(defval = false, title = "Open Anchor       ", group = g, inline="2a") // show_vwap4_Open_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2a") // show_vwap4_High = input.bool(defval = false, title = "High Anchor        ", group = g, inline="2b") // show_vwap4_High_sd = input.bool(defval = false, title = "With Std Deviation Band", group = g, inline="2b") // show_vwap4_Low = input.bool(defval = false, title = "Low Anchor        ", group = g, inline="2c") // show_vwap4_Low_sd = input.bool(defval = false, title = "With Std Deviation Bandn", group = g, inline="2c") // List Of Anchors // Daily Open // Weekly Open // Monthly Open // Yearly Open // Daily High // Daily Low // Weekly High // Weekly Low // Monthly High // Monthly Low // Yearly High // Yearly Low // All time high // All time low // All time open // Customn Pivot Highs // Custom Pivot Lows // Session Open //Functions ResolutionToSec(res)=> mins = res == "1" ? 1 : res == "3" ? 3 : res == "5" ? 5 : res == "10" ? 10 : res == "15" ? 15 : res == "30" ? 30 : res == "45" ? 45 : res == "60" ? 60 : res == "120" ? 120 : res == "180" ? 180 : res == "240" ? 240 : res == "D" or res == "1D" ? 1440 : res == "W" or res == "1W" ? 10080 : res == "M" or res == "1M" ? 43200 : res == "" ? int(str.tonumber(timeframe.period)) : str.substring(timeframe.period, 2, 3) == "S" ? int(str.tonumber(str.substring(timeframe.period, 0, 2)))/60 : int(str.tonumber(res)) ms = mins * 60 * 1000 GetChartHighest(dataSeries = high) => var chartHighest = dataSeries if dataSeries > nz(chartHighest, -1e10) chartHighest := dataSeries chartHighest GetAllTimeHigh(dataSeries = high) => highestHTF = request.security(syminfo.tickerid, "D", GetChartHighest(dataSeries)[1], lookahead=barmerge.lookahead_on) highestChartTF = GetChartHighest(dataSeries) math.max(highestHTF, highestChartTF) GetChartLowest(dataSeries = low) => var chartLowest = dataSeries if dataSeries < nz(chartLowest, 1e10) chartLowest := dataSeries chartLowest GetAllTimeLow(dataSeries = low) => lowestHTF = request.security(syminfo.tickerid, "D", GetChartLowest(dataSeries)[1], lookahead=barmerge.lookahead_on) lowestChartTF = GetChartLowest(dataSeries) math.min(lowestHTF, lowestChartTF) f_get_started (_session) => na(_session[1]) and _session //Variables & Change Detection int sess1 = time(timeframe.period, OSession, zone) var dh = 0.0 var dl = 0.0 var wh = 0.0 var wl = 0.0 var mh = 0.0 var ml = 0.0 var qh = 0.0 var ql = 0.0 var yh = 0.0 var yl = 0.0 bar = ResolutionToSec(timeframe.period) vis_bars = ((chart.right_visible_bar_time - chart.left_visible_bar_time) / bar) year_change = show_hist ? year(time, zone) != year(time[1], zone) : year(time, zone) != year(time[1], zone) and time > (timenow - (86400000 * 366)) 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)) month_change = show_hist ? month(time, zone) != month(time[1], zone) : month(time, zone) != month(time[1], zone) and time > (timenow - (86400000 * 32)) 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)) day_change = show_hist ? dayofweek(time, zone) != dayofweek(time[1], zone) : dayofweek(time, zone) != dayofweek(time[1], zone) and time > (timenow - (86460000 )) if not(year_change) if high > yh yh := high if low < yl yl := low else yh := high yl := low if not(quarterly_change) if high > qh qh := high if low < ql ql := low else qh := high ql := low if not(month_change) if high > mh mh := high if low < ml ml := low else mh := high ml := low if not(week_change) if high > wh wh := high if low < wl wl := low else wh := high wl := low if not(day_change) if high > dh dh := high if low < dl dl := low else dh := high dl := low yh_change = show_hist ? yh > yh[1] or year_change : (yh > yh[1] or year_change) and time > (timenow - (86400000 * 366)) qh_change = show_hist ? qh > qh[1] or quarterly_change : (qh > qh[1] or quarterly_change) and time > (timenow - (86400000 * 94)) mh_change = show_hist ? mh > mh[1] or month_change : (mh > mh[1] or month_change ) and time > (timenow - (86400000 * 32)) wh_change = show_hist ? wh > wh[1] or week_change : (wh > wh[1] or week_change ) and time > (timenow - (86400000 * 8)) dh_change = show_hist ? dh > dh[1] or day_change : (dh > dh[1] or day_change) and time > (timenow - (86460000 )) yl_change = show_hist ? yl < yl[1] or year_change :(yl < yl[1] or year_change) and time > (timenow - (86400000 * 366)) ql_change = show_hist ? ql < ql[1] or quarterly_change : (ql < ql[1] or quarterly_change) and time > (timenow - (86400000 * 94)) ml_change = show_hist ? ml < ml[1] or month_change : (ml < ml[1] or month_change ) and time > (timenow - (86400000 * 32)) wl_change = show_hist ? wl < wl[1] or week_change : (wl < wl[1] or week_change ) and time > (timenow - (86400000 * 8)) dl_change = show_hist ? dl < dl[1] or day_change : (dl < dl[1] or day_change) and time > (timenow - (86460000 )) ath = GetAllTimeHigh(high) ath_change = ath > ath[1] atl = GetAllTimeLow(high) atl_change = atl < atl[1] ph = ta.pivothigh(leftbars, 0) pl = ta.pivotlow(leftbars, 0) ph_change = not na(ph) pl_change = not na(pl) sess_start = f_get_started(sess1) 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 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 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 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 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 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 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 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 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 //debug // if wh_change // label.new(bar_index, high, text = "h") // Plot all the vwaps! [vwap1_open_vwap, upper_vwap1_open_vwap, lower_vwap1_open_vwap] = ta.vwap(show_vwap1_Open ? vwap_source : na, vwap1_open_change, std_dev) [vwap1_high_vwap, upper_vwap1_high_vwap, lower_vwap1_high_vwap] = ta.vwap(show_vwap1_High ? vwap_source : na, vwap1_high_change, std_dev) [vwap1_low_vwap, upper_vwap1_low_vwap, lower_vwap1_low_vwap] = ta.vwap(show_vwap1_Low ? vwap_source : na, vwap1_low_change, std_dev) [vwap2_open_vwap, upper_vwap2_open_vwap, lower_vwap2_open_vwap] = ta.vwap(show_vwap2_Open ? vwap_source : na, vwap2_open_change, std_dev) [vwap2_high_vwap, upper_vwap2_high_vwap, lower_vwap2_high_vwap] = ta.vwap(show_vwap2_High ? vwap_source : na, vwap2_high_change, std_dev) [vwap2_low_vwap, upper_vwap2_low_vwap, lower_vwap2_low_vwap] = ta.vwap(show_vwap2_Low ? vwap_source : na, vwap2_low_change, std_dev) [vwap3_open_vwap, upper_vwap3_open_vwap, lower_vwap3_open_vwap] = ta.vwap(show_vwap3_Open ? vwap_source : na, vwap3_open_change, std_dev) [vwap3_high_vwap, upper_vwap3_high_vwap, lower_vwap3_high_vwap] = ta.vwap(show_vwap3_High ? vwap_source : na, vwap3_high_change, std_dev) [vwap3_low_vwap, upper_vwap3_low_vwap, lower_vwap3_low_vwap] = ta.vwap(show_vwap3_Low ? vwap_source : na, vwap3_low_change, std_dev) plot(show_vwap1_Open_sd ? upper_vwap1_open_vwap : na, "VWAP 1 Open Upper", vwap_col1, width, plot(vwap1_open_vwap, "VWAP 1 Open", vwap_col1, width, plot(show_vwap1_Open_sd ? lower_vwap1_open_vwap : na, "VWAP 1 Open Lower", vwap_col1, width, plot(show_vwap1_High_sd ? upper_vwap1_high_vwap : na, "VWAP 1 High Upper", vwap_col1, width, plot(vwap1_high_vwap, "VWAP 1 High", vwap_col1, width, plot(show_vwap1_High_sd ? lower_vwap1_high_vwap : na, "VWAP 1 High Lower", vwap_col1, width, plot(show_vwap1_Low_sd ? upper_vwap1_low_vwap : na, "VWAP 1 Low Upper", vwap_col1, width, plot(vwap1_low_vwap, "VWAP 1 Low", vwap_col1, width, plot(show_vwap1_Low_sd ? lower_vwap1_low_vwap : na, "VWAP 1 Low Lower", vwap_col1, width, plot(show_vwap2_Open_sd ? upper_vwap2_open_vwap : na, "VWAP 2 Open Upper", vwap_col2, width, plot(vwap2_open_vwap, "VWAP 2 Open", vwap_col2, width, plot(show_vwap2_Open_sd ? lower_vwap2_open_vwap : na, "VWAP 2 Open Lower", vwap_col2, width, plot(show_vwap2_High_sd ? upper_vwap2_high_vwap : na, "VWAP 2 High Upper", vwap_col2, width, plot(vwap2_high_vwap, "VWAP 2 High", vwap_col2, width, plot(show_vwap2_High_sd ? lower_vwap2_high_vwap : na, "VWAP 2 High Lower", vwap_col2, width, plot(show_vwap2_Low_sd ? upper_vwap2_low_vwap : na, "VWAP 2 Low Upper", vwap_col2, width, plot(vwap2_low_vwap, "VWAP 2 Low", vwap_col2, width, plot(show_vwap2_Low_sd ? lower_vwap2_low_vwap : na, "VWAP 2 Low Lower", vwap_col2, width, plot(show_vwap3_Open_sd ? upper_vwap3_open_vwap : na, "VWAP 3 Open Upper", vwap_col3, width, plot(vwap3_open_vwap, "VWAP 3 Open", vwap_col3, width, plot(show_vwap3_Open_sd ? lower_vwap3_open_vwap : na, "VWAP 3 Open Lower", vwap_col3, width, plot(show_vwap3_High_sd ? upper_vwap3_high_vwap : na, "VWAP 3 High Upper", vwap_col3, width, plot(vwap3_high_vwap, "VWAP 3 High", vwap_col3, width, plot(show_vwap3_High_sd ? lower_vwap3_high_vwap : na, "VWAP 3 High Lower", vwap_col3, width, plot(show_vwap3_Low_sd ? upper_vwap3_low_vwap : na, "VWAP 3 Low Upper", vwap_col3, width, plot(vwap3_low_vwap, "VWAP 3 Low", vwap_col3, width, plot(show_vwap3_Low_sd ? lower_vwap3_low_vwap : na, "VWAP 3 Low Lower", vwap_col3, width, // //debug // if barstate.islast and (timenow - time) >= (timenow - ph_time) // label.new(bar_index, high, "x") //sma's srcsma = close HTFsma = input.timeframe('D', 'TimeFrame') len1 = input.int(5, minval=1, title='SMA1') len2 = input.int(9, minval=1, title='SMA2') len3 = input.int(20, minval=1, title='SMA3') len4 = input.int(50, minval=1, title='SMA4') len5 = input.int(100, minval=1, title='SMA5') len6 = input.int(200, minval=1, title='SMA6') plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len1)), len1), title='SMA1', color=color.rgb(255, 255, 255), linewidth=2) plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len2)), len1), title='SMA2', color=color.rgb(162, 163, 163), linewidth=2) plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len3)), len1), title='SMA3', color=color.rgb(46, 211, 112), linewidth=2) plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len4)), len1), title='SMA4', color=color.rgb(247, 91, 91), linewidth=2) plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len5)), len1), title='SMA5', color=color.rgb(31, 106, 61), linewidth=2) plot(ta.sma(request.security(syminfo.tickerid, HTFsma, ta.sma(srcsma, len6)), len1), title='SMA6', color=color.rgb(161, 23, 23), linewidth=2) //ema's srcema = close HTFema = input.timeframe('1', 'TimeFrame') elen1 = input.int(9, minval=1, title='EMA1') elen2 = input.int(20, minval=1, title='EMA2') elen3 = input.int(200, minval=1, title='EMA3') plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen1)), len1), title='EMA1', color=color.rgb(70, 210, 242), linewidth=1) plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen2)), len1), title='EMA2', color=color.rgb(196, 196, 196), linewidth=1) plot(ta.ema(request.security(syminfo.tickerid, HTFema, ta.sma(srcema, elen3)), len1), title='EMA3', color=color.rgb(155, 155, 155), linewidth=1) //FFIBS //----------settings----------// var g0 = 'Order Block Settings' 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') 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') 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') mitType = input.string('Wicks', 'Mitigation Type', ['Wicks', 'Close']) 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)') 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') var g1 = 'Order Block Display Settings' showOb = input.bool(true, 'Show Order Blocks', group = g1) hideOld = input.bool(false, 'Remove Old or Irrelevant Order Blocks', group = g1) bullCol = input.color(color.new(#4caf4f, 60), 'Bullish Color', group = g1) bearCol = input.color(color.new(color.red,60), 'Bearish Color', group = g1) var g2 = 'Fibs' showFibs = input.bool(true, 'Show Fibs', group = g2) 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') retracelev = input.string('Order Block', 'Rectracement Level', ['Order Block', '.50', '.618', '.786'], group = g2) fibStyle = input.string('Dashed', 'Line style ', options = ['Dashed', 'Dotted', 'Solid'], group = g2, inline = '2') extLines = input.bool(false, 'Extend', group = g2, inline = '2') textColor = input.color(color.rgb(255, 253, 253), 'Fib Label Color', group = g2) show_236 = input.bool(true, '.236', inline = '3', group = g2) color_236 = input.color(#6a74a5, '', inline = '3', group = g2) show_382 = input.bool(true, '.382', inline = '3', group = g2) color_382 = input.color(#6a74a5, '', inline = '3', group = g2) show_50 = input.bool(true, '.50', inline = '3', group = g2) color_50 = input.color(#edd81f, '', inline = '3', group = g2) show_618 = input.bool(true, '.618', inline = '4', group = g2) color_618 = input.color(#edd81f, '', inline = '4', group = g2) show_786 = input.bool(true, '.786', inline = '4', group = g2) color_786 = input.color(#6a74a5, '', inline = '4', group = g2) show_hl = input.bool(true, '0 & 1', inline = '4', group = g2) color_hl = input.color(#ffffff, '', inline = '4', group = g2) //----------types----------// type obFibs bool a = true bool bull = true int idx float l float h float chl bool ret = false float [] levArr line [] lineArr label [] labArr label retLab type obBox bool a = true bool bull = true float top float bottom box bx //----------switch----------// method switcher(string this) => switch this 'Solid' => line.style_solid 'Dashed' => line.style_dashed 'Dotted' => line.style_dotted //----------variables----------// var obFibsArr = array.new<obFibs>() var obBoxArr = array.new<obBox>() var fibBoolArr = array.from(show_hl, show_hl, show_236, show_382, show_50, show_618, show_786) var fibColArr = array.from(color_hl, color_hl, color_236, color_382, color_50, color_618, color_786) var fibLevArr = array.from('0', '1', '.236', '.382', '.50', '.618', '.786') var bu = false var be = false barsCount = 0 lines = line.all labels = label.all //----------calculations----------// if irrOb == 'Distance' maxObLen := maxObLen / 100 gainBull = ((math.abs(low[barsReq] - close))/low[barsReq]) * 100 gainBear = ((math.abs(high[barsReq] - close))/high[barsReq]) * 100 gainCheck = gainBull >= percGain or gainBear >= percGain lastDown = close[barsReq] < open[barsReq] lastUp = close[barsReq] > open[barsReq] if lastDown for i = 0 to barsReq if close[i] > open[i] barsCount += 1 if lastUp for i = 0 to barsReq if close[i] < open[i] barsCount += 1 //----------conditions----------// bullish = lastDown and barsCount >= barsReq and gainCheck and (opposites ? not bu : not bu or bu) bearish = lastUp and barsCount >= barsReq and gainCheck and (opposites ? not be : not be or be) if bullish for l in lines l.delete() for l in labels l.delete() bu := true be := false fibTotal = high - low[barsReq] lev236 = high - (fibTotal * .236) lev382 = high - (fibTotal * .382) lev50 = high - (fibTotal * .5) lev618 = high - (fibTotal * .618) lev786 = high - (fibTotal * .786) 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>()) if showFibs for i = 0 to newFibs.levArr.size()-1 if fibBoolArr.get(i) == true 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())) 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)) obFibsArr.unshift(newFibs) if showOb obBoxArr.unshift(obBox.new(true, true, high[barsCount], low[barsReq], box.new(bar_index[barsReq], high[barsReq], bar_index, low[barsReq], bullCol, bgcolor = bullCol))) alert('New Bullish Order Block', alert.freq_once_per_bar_close) if bearish for l in lines l.delete() for l in labels l.delete() be := true bu := false fibTotal = high[barsReq] - low lev236 = low + (fibTotal * .236) lev382 = low + (fibTotal * .382) lev50 = low +(fibTotal * .5) lev618 = low + (fibTotal * .618) lev786 = low + (fibTotal * .786) 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>()) if showFibs for i = 0 to newFibs.levArr.size()-1 if fibBoolArr.get(i) == true 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())) 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)) obFibsArr.unshift(newFibs) if showOb obBoxArr.unshift(obBox.new(true, false, high[barsCount], low[barsReq], box.new(bar_index[barsReq], high[barsReq], bar_index, low[barsReq], bearCol, bgcolor = bearCol))) alert('New Bearish Order Block', alert.freq_once_per_bar_close) //----------fib management----------// if obFibsArr.size() > 0 for b in obFibsArr if b.a for l in b.lineArr l.set_x2(bar_index) if b.bull retlev = retracelev == 'Order Block' ? b.h : retracelev == '.50' ? b.levArr.get(4) : retracelev == '.618' ? b.levArr.get(5) : b.levArr.get(6) if low <= retlev and retraceMax and not b.ret b.ret := true b.retLab := label.new(bar_index,low,'?', yloc = yloc.belowbar) alert('Retracement Level Hit', alert.freq_once_per_bar) if high > b.chl and not b.ret b.chl := high fibTotal = b.chl - b.l lev236 = b.chl - (fibTotal * .236) lev382 = b.chl - (fibTotal * .382) lev50 = b.chl - (fibTotal * .5) lev618 = b.chl - (fibTotal * .618) lev786 = b.chl - (fibTotal * .786) b.levArr := array.from(b.chl, b.l, lev236, lev382, lev50, lev618, lev786) for l in b.lineArr l.delete() for l in b.labArr l.delete() if showFibs for i = 0 to b.levArr.size()-1 if fibBoolArr.get(i) == true 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())) 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)) 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) b.a := false if (bullish and bar_index > b.idx + barsReq and not opposites) for l in b.lineArr l.delete() for l in b.labArr l.delete() if not b.bull retlev = retracelev == 'Order Block' ? b.h : retracelev == '.50' ? b.levArr.get(4) : retracelev == '.618' ? b.levArr.get(5) : b.levArr.get(6) if high >= retlev and retraceMax and not b.ret b.ret := true b.retLab := label.new(bar_index,low,'?', style=label.style_none, yloc = yloc.abovebar) alert('Retracement Level Hit', alert.freq_once_per_bar) if low < b.chl and not b.ret b.chl := low fibTotal = b.h - b.chl lev236 = b.chl + (fibTotal * .236) lev382 = b.chl + (fibTotal * .382) lev50 = b.chl +(fibTotal * .5) lev618 = b.chl + (fibTotal * .618) lev786 = b.chl + (fibTotal * .786) b.levArr := array.from(b.chl, b.h, lev236, lev382, lev50, lev618, lev786) for l in b.lineArr l.delete() for l in b.labArr l.delete() if showFibs for i = 0 to b.levArr.size()-1 if fibBoolArr.get(i) == true 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, 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)) 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) b.a := false if (bearish and bar_index > b.idx + barsReq and not opposites) for l in b.lineArr l.delete() for l in b.labArr l.delete() //----------order block management----------// if obBoxArr.size() > 0 for bx in obBoxArr if bx.a bx.bx.set_right(bar_index) if bx.bull src = mitType == 'Wicks' ? low : close 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)) bx.a := false if hideOld bx.bx.delete() else if not bx.bull src = mitType == 'Wicks' ? high : close 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)) bx.a := false if hideOld bx.bx.delete()