// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Credits to the original Script - Range Filter DonovanWall https://www.tradingview.com/script/lut7sBgG-Range-Filter-DW/ // This version is the old version of the Range Filter with less settings to tinker with //@version=5 indicator(title='Range Filter - B&S Signals+OB+SND', shorttitle='RF - B&S Signals+OB+SND', overlay=true, max_labels_count = 500, max_boxes_count = 500, max_lines_count = 500) //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Functions //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Range Size Function rng_size(x, qty, n) => // AC = Cond_EMA(abs(x - x[1]), 1, n) wper = n * 2 - 1 avrng = ta.ema(math.abs(x - x[1]), n) AC = ta.ema(avrng, wper) * qty rng_size = AC rng_size //Range Filter Function rng_filt(x, rng_, n) => r = rng_ var rfilt = array.new_float(2, x) array.set(rfilt, 1, array.get(rfilt, 0)) if x - r > array.get(rfilt, 1) array.set(rfilt, 0, x - r) if x + r < array.get(rfilt, 1) array.set(rfilt, 0, x + r) rng_filt1 = array.get(rfilt, 0) hi_band = rng_filt1 + r lo_band = rng_filt1 - r rng_filt = rng_filt1 [hi_band, lo_band, rng_filt] //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Inputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Range Source rng_src = input(defval=close, title='Swing Source') //Range Period rng_per = input.int(defval=200, minval=1, title='Swing Period') //Range Size Inputs rng_qty = input.float(defval=7.5, minval=0.0000001, title='Swing Multiplier') //Bar Colors use_barcolor = input(defval=true, title='Bar Colors On/Off') //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Definitions //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Range Filter Values [h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per) //Direction Conditions var fdir = 0.0 fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir upward = fdir == 1 ? 1 : 0 downward = fdir == -1 ? 1 : 0 //Trading Condition longCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt and rng_src < rng_src[1] and upward > 0 shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src < filt and rng_src > rng_src[1] and downward > 0 CondIni = 0 CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1] longCondition = longCond and CondIni[1] == -1 shortCondition = shortCond and CondIni[1] == 1 //Colors filt_color = upward ? #2adf06e5 : downward ? #ec0606e0 : #cccccc bar_color = upward and rng_src > filt ? rng_src > rng_src[1] ? #76ff05 : #76ff05 : downward and rng_src < filt ? rng_src < rng_src[1] ? #ff0505 : #ff0505 : #109404 //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Outputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Filter Plot filt_plot = plot(filt, color=filt_color, linewidth=3, title='Filter', transp=67) //Band Plots h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title='High Band') l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title='Low Band') //Band Fills fill(h_band_plot, filt_plot, color=#00b36b00, title='High Band Fill') fill(l_band_plot, filt_plot, color=#b8005c00, title='Low Band Fill') //Bar Color barcolor(use_barcolor ? bar_color : na) // // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ // ---------------------------------------------- Order Blocks ------------------------------------------------ // Order Blocks const color colup = #089981 const color coldn = #f23645 const string tm = "[Length] Use Length to adjust cordinate of the orderblocks\n[Full] Use whole candle body" const string tn = "Mitigation method for when to trigger order blocks" const string tj = "Order block Metrics text size" const string ta = 'Display internal buy & sell activity' const string tsorder = 'Show Last number of orderblocks' const string gv = "Volumetric Order Blocks" obshow = input.bool (false , "Show Last" , tsorder, '1', gv) oblast = input.int (3 , "" , 0, 50, 1 , inline = '1', group = gv) obupcs = input.color (color.new(colup, 90), "" , inline = '1', group = gv) obdncs = input.color (color.new(coldn, 90), "" , inline = '1', group = gv) obshowactivity = input.bool (true , "Show Buy/Sell Activity         ", ta, '2', gv) obactup = input.color (color.new(colup, 50), "" , inline = '2', group = gv) obactdn = input.color (color.new(coldn, 50), "" , inline = '2', group = gv) obmode = input.string("Length" , "Construction " , ["Length", "Full"], tm, '3', gv) len = input.int (5 , "" , 1, 20, 1 , inline = '3', group = gv) obmiti = input.string("Close" , "Mitigation Method" , ["Close", "Wick", "Avg"], tn, group = gv) obtxt = input.string("Normal" , "Metric Size" , ["Tiny", "Small", "Normal", "Large", "Huge"], tj, group = gv) showmetric = input.bool (false , "Show Metrics" , group = gv) showline = input.bool (false , "Show Mid-Line" , group = gv) overlap = input.bool (true , "Hide Overlap" , group = gv, tooltip = "Most recent order block will be preserved") bull = input.bool(true , "Buy signal" , inline = "Inside" , group = "ANY ALERT") bear = input.bool(true , "Sell Signal" , inline = "Formed" , group = "ANY ALERT") blcreated = input.bool(false , "Bullish OB Formed      " , inline = "Formed" , group = "ANY ALERT") brcreated = input.bool(false , "Bearish OB Formed" , inline = "Formed" , group = "ANY ALERT") blmitigated = input.bool(false , "Bullish OB Mitigated   " , inline = "Mitigated" , group = "ANY ALERT") brmitigated = input.bool(false , "Bearish OB Mitigated" , inline = "Mitigated" , group = "ANY ALERT") blinside = input.bool(true , "Price Inside Bullish OB" , inline = "Inside" , group = "ANY ALERT") brinside = input.bool(true , "Price Inside Bearish OB" , inline = "Inside" , group = "ANY ALERT") type bar float o = open float h = high float l = low float c = close float v = volume int i = bar_index int t = time type ob float top float btm float avg int loc color css float vol int dir int move int blPOS int brPOS int xlocbl int xlocbr type alert bool created = false bool inside = false bool mitigated = false type cross bool reset = false bar b = bar .new() alert blal = alert.new() alert bral = alert.new() var cross blIS = cross.new() var cross brIS = cross.new() method txSz(string s) => out = switch s "Tiny" => size.tiny "Small" => size.small "Normal" => size.normal "Large" => size.large "Huge" => size.huge out method display(ob id, ob[] full, int i) => box.new (top = id.top, bottom = id.btm, left = id.loc, right = b.t , border_color = na, bgcolor = id.css, xloc = xloc.bar_time) box.new (top = id.top, bottom = id.btm, left = b.t , right = b.t + 1 , border_color = na, bgcolor = id.css, xloc = xloc.bar_time, extend = extend.right) if obshowactivity box.new(top = id.top, bottom = id.avg, left = id.loc, right = id.xlocbl, border_color = na, bgcolor = obactup, xloc = xloc.bar_time) box.new(top = id.avg, bottom = id.btm, left = id.loc, right = id.xlocbr, border_color = na, bgcolor = obactdn, xloc = xloc.bar_time) if showline line.new( x1 = id.loc , x2 = b.t , y1 = id.avg , y2 = id.avg , color = color.new(id.css, 0) , xloc = xloc.bar_time , style = line.style_dashed ) if showmetric if i == math.min(oblast - 1, full.size() - 1) float tV = 0 float[] dV = array.new() seq = math.min(oblast - 1, full.size() - 1) for j = 0 to seq cV = full.get(j) tV += cV.vol if j == seq for y = 0 to seq dV.push( math.floor( (full.get(y).vol / tV) * 100) ) id = full.get(y) label.new( b.i + 1 , id.avg , textcolor = color.new(id.css, 0) , style = label.style_label_left , size = obtxt.txSz() , color = #ffffff00 , text = str.tostring( math.round(full.get(y).vol, 3), format = format.volume) + " (" + str.tostring(dV.get(y)) + "%)" ) method overlap(ob[] id) => if id.size() > 1 for i = id.size() - 1 to 1 stuff = id.get(i) current = id.get(0) switch stuff.btm > current.btm and stuff.btm < current.top => id.remove(i) stuff.top < current.top and stuff.btm > current.btm => id.remove(i) stuff.top > current.top and stuff.btm < current.btm => id.remove(i) stuff.top < current.top and stuff.top > current.btm => id.remove(i) method umt(ob metric) => switch metric.dir 1 => switch metric.move 1 => metric.blPOS := metric.blPOS + 1, metric.move := 2 2 => metric.blPOS := metric.blPOS + 1, metric.move := 3 3 => metric.brPOS := metric.brPOS + 1, metric.move := 1 -1 => switch metric.move 1 => metric.brPOS := metric.brPOS + 1, metric.move := 2 2 => metric.brPOS := metric.brPOS + 1, metric.move := 3 3 => metric.blPOS := metric.blPOS + 1, metric.move := 1 if (b.t - b.t[1]) == (b.t[1] - b.t[2]) metric.xlocbl := metric.loc + (b.t - b.t[1]) * metric.blPOS metric.xlocbr := metric.loc + (b.t - b.t[1]) * metric.brPOS fnOB() => var ob[] blob = array.new() var ob[] brob = array.new() var int dir = 0 up = ta.highest ( len ) dn = ta.lowest ( len ) pv = ta.pivothigh(b.v, len, len) dir := b.h[len] > up ? -1 : b.l[len] < dn ? 1 : dir[1] atr = ta.atr(len) btmP = obmode == "Length" ? (b.h[len] - 1 * atr[len]) < b.l[len] ? b.l[len] : (b.h[len] - 1 * atr[len]) : b.l[len] topP = obmode == "Length" ? (b.l[len] + 1 * atr[len]) > b.h[len] ? b.h[len] : (b.l[len] + 1 * atr[len]) : b.h[len] if pv and dir == 1 blob.unshift( ob.new(topP, b.l[len], math.avg(topP, b.l[len]), b.t[len], obupcs, b.v[len], b.c[len] > b.o[len] ? 1 : -1, 1, 0, 0, b.t[len])) blal.created := true blIS.reset := false if pv and dir == -1 brob.unshift( ob.new( b.h[len] , btmP , math.avg(btmP, b.h[len]) , b.t[len] , obdncs , b.v[len] , b.c[len] > b.o[len] ? 1 : -1 , 1 , 0 , 0 , b.t[len] ) ) bral.created := true brIS.reset := false if blob.size() > 0 and barstate.isconfirmed for [i, ob] in blob for j = 0 to len - 1 if obmiti == "Close" ? math.min(b.c[j], b.o[j]) < ob.btm : obmiti == "Wick" ? b.l < ob.btm : obmiti == "Avg" ? b.l < ob.avg : na blob.remove(i) blal.mitigated := true break if brob.size() > 0 and barstate.isconfirmed for[i, ob] in brob for j = 0 to len - 1 if obmiti == "Close" ? math.max(b.c[j], b.o[j]) > ob.top : obmiti == "Wick" ? b.h > ob.top : obmiti == "Avg" ? b.h > ob.avg : na brob.remove(i) bral.mitigated := true break if blob.size() > 0 for [i, metric] in blob metric.umt() if brob.size() > 0 for [i, metric] in brob metric.umt() if overlap blob.overlap() brob.overlap() if barstate.isconfirmed if blob.size() > 0 ob = blob.get(0) if low < ob.top and blIS.reset == false blal.inside := true blIS.reset := true if brob.size() > 0 ob = brob.get(0) if high > ob.btm and brIS.reset == false bral.inside := true brIS.reset := true if barstate.islast for bx in box.all bx.delete() for ln in line.all ln.delete() // for lb in label.all //Razzere Fixed! // lb.delete() //Razzere Fixed! if blob.size() > 0 for i = 0 to math.min(oblast - 1, blob.size() - 1) blob.get(i).display(blob, i) if brob.size() > 0 for i = 0 to math.min(oblast - 1, brob.size() - 1) brob.get(i).display(brob, i) if obshow fnOB() if bull and longCondition alert("Buy Signal") if bear and shortCondition alert("Sell Signal") if blinside and blal.inside alert("Price Inside Bullish OB") if blcreated and blal.created alert("Bullish OB Formed") if blmitigated and blal.mitigated alert("Bullish OB Mitigated") if brinside and bral.inside alert("Price Inside Bearish OB") if brcreated and bral.created alert("Bearish OB Formed") if brmitigated and bral.mitigated alert("Bearish OB Mitigated") // Risk Management levels = input.bool(true, "Show TP/SL Levels" , group = "Risk Management" , inline = "MMDB2") lvlLines = input.bool(false, "Show Lines ", inline="levels", group = "Risk Management") linesStyle = input.string("SOLID", "", ["SOLID", "DASHED", "DOTTED"], inline="levels", group = "Risk Management") lvlDistance = input.int(105, "Distance", 1, inline="levels2", group = "Risk Management") lvlDecimals = input.int(2, "   Decimals", 1, 8, inline="levels2", group = "Risk Management") atrRisk = input.int(5, "Risk % ", 1, group = "Risk Management" , inline="levels3") atrLen = input.int(14, "  ATR Length", 1, group = "Risk Management" , inline="levels3") decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3 ? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" : lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########" trigger2 = longCondition ? 1 : 0 countBull = ta.barssince(longCondition) countBear = ta.barssince(shortCondition) trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0 atrBand = ta.atr(atrLen) * atrRisk atrStop = trigger == 1 ? low - atrBand : high + atrBand lastTrade(close) => ta.valuewhen(longCondition or shortCondition, close, 0) entry = levels ? label.new(time, close, "ENTRY " + str.tostring(lastTrade(close), decimals), xloc.bar_time, yloc.price, #e0ad06, label.style_label_left, color.white, size.normal) : na label.set_x(entry, label.get_x(entry) + math.round(ta.change(time) * lvlDistance)) label.set_y(entry, lastTrade(close)) label.delete(entry[1]) stop_y = lastTrade(atrStop) stop = levels ? label.new(time, close, "SL " + str.tostring(stop_y, decimals), xloc.bar_time, yloc.price, #ff00008c, label.style_label_left, color.white, size.normal) : na label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance)) label.set_y(stop, stop_y) label.delete(stop[1]) tp1Rl_y = (lastTrade(close)-lastTrade(atrStop))*1 + lastTrade(close) tp1Rl = levels ? label.new(time, close, "1:1 TP " + str.tostring(tp1Rl_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal ) : na label.set_x(tp1Rl, label.get_x(tp1Rl) + math.round(ta.change(time) * lvlDistance)) label.set_y(tp1Rl, tp1Rl_y) label.delete(tp1Rl[1]) tp2RL_y = (lastTrade(close)-lastTrade(atrStop))*2 + lastTrade(close) tp2RL = levels ? label.new(time, close, "2:1 TP " + str.tostring(tp2RL_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal) : na label.set_x(tp2RL, label.get_x(tp2RL) + math.round(ta.change(time) * lvlDistance)) label.set_y(tp2RL, tp2RL_y) label.delete(tp2RL[1]) tp3RL_y = (lastTrade(close)-lastTrade(atrStop))*3 + lastTrade(close) tp3RL = levels ? label.new(time, close, "3:1 TP " + str.tostring(tp3RL_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal) : na label.set_x(tp3RL, label.get_x(tp3RL) + math.round(ta.change(time) * lvlDistance)) label.set_y(tp3RL, tp3RL_y) label.delete(tp3RL[1]) style = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ? line.style_dashed : line.style_dotted lineEntry = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), lastTrade(close), bar_index + lvlDistance, lastTrade(close), xloc.bar_index, extend.none, #e0ad06, style, 2) : na, line.delete(lineEntry[1]) lineStop = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), stop_y, bar_index + lvlDistance, stop_y, xloc.bar_index, extend.none, #ff00008c, style, 2) : na, line.delete(lineStop[1]) lineTp1Rl = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp1Rl_y, bar_index + lvlDistance, tp1Rl_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp1Rl[1]) lineTp2RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp2RL_y, bar_index + lvlDistance, tp2RL_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp2RL[1]) lineTp3RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp3RL_y, bar_index + lvlDistance, tp3RL_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp3RL[1]) //Plot Buy and Sell Labels plotshape(longCondition, title='Buy Signal', text='Buy\n▲+ ', textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=#00cf4b8c) plotshape(shortCondition, title='Sell Signal', text='Sell\n▼+', textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=#ff00008c) //Alerts alertcondition(longCondition, title='Buy Alert', message='BUY') alertcondition(shortCondition, title='Sell Alert', message='SELL') // // ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ // ---------------------------------------------- SR ------------------------------------------------ // show_current_sr = input.bool(true, title = "Show Current TF S/R", group = "Setting") swing_length = input.int(10, title = 'Swing Length', group = 'Setting', minval = 1, maxval = 50) history_of_demand_to_keep = input.int(20, title = 'Lookback', minval = 5, maxval = 50, group = "Setting") box_width = input.float(10, title = 'S/R Range', group = 'Setting', minval = 1, maxval = 10, step = 0.5) string group3 = "TF Setting" enableHtf1 = input.bool(false, group = group3, inline = "htf1", title = "") htf1 = input.timeframe("W", "TF1", group = group3, inline = "htf1") enableHtf2 = input.bool(false, group = group3, inline = "htf2", title = "") htf2 = input.timeframe("D", "TF2", group = group3, inline = "htf2") enableHtf3 = input.bool(false, group = group3, inline = "htf3", title = "") htf3 = input.timeframe("240", "TF3", group = group3, inline = "htf3") enableHtf4 = input.bool(false, group = group3, inline = "htf4", title = "") htf4 = input.timeframe("180", "TF4", group = group3, inline = "htf4") enableHtf5 = input.bool(false, group = group3, inline = "htf5", title = "") htf5 = input.timeframe("120", "TF5", group = group3, inline = "htf5") enableHtf6 = input.bool(false, group = group3, inline = "htf6", title = "") htf6 = input.timeframe("60", "TF6", group = group3, inline = "htf6") enableHtf7 = input.bool(false, group = group3, inline = "htf7", title = "") htf7 = input.timeframe("45", "TF7", group = group3, inline = "htf7") enableHtf8 = input.bool(true, group = group3, inline = "htf8", title = "") htf8 = input.timeframe("30", "TF8", group = group3, inline = "htf8") enableHtf9 = input.bool(false, group = group3, inline = "htf9", title = "") htf9 = input.timeframe("15", "TF9", group = group3, inline = "htf9") supply_color = input.color(#f236468a, title = 'Support Zone', group = 'Color Settings', inline = '3') supply_outline_color = input.color(#f236468a, title = 'BoS', group = 'Color Settings', inline = '3') demand_color = input.color(#2962ff8a, title = 'Resistance Zone', group = 'Color Settings', inline = '4') demand_outline_color = input.color(#2962ff8a, title = 'BoR', group = 'Color Settings', inline = '4') // bos_label_color = input.color(color.white, title = 'Fracture Zone', group = 'Color Settings', inline = '5') poi_label_color = input.color(#b9b9b9, title = 'S/R Zone Label', group = 'Color Settings', inline = '7') type zone_with_strength box zone int count = 0 string tf // FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY array_add_pop(array, new_value_to_add) => array.unshift(array, new_value_to_add) array.pop(array) // FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING check_overlapping(new_poi, box_array, atr) => atr_threshold = atr * 2 okay_to_draw = true for i = 0 to array.size(box_array) - 1 zone_with_strength zws = array.get(box_array, i) if not na(zws) box b = zws.zone top = box.get_top(b) bottom = box.get_bottom(b) poi = (top + bottom) / 2 upper_boundary = poi + atr_threshold lower_boundary = poi - atr_threshold if new_poi >= lower_boundary and new_poi <= upper_boundary okay_to_draw := false break else okay_to_draw := true okay_to_draw // FUNCTION TO DRAW SUPPLY OR DEMAND ZONE support_resistance(value_array, bn_array, box_array, label_array, count_array, box_type, atr, tf_label, tfbarindex, is_htf) => atr_buffer = atr * (box_width / 10) box_left = is_htf ? bar_index : array.get(bn_array, 0) box_right = bar_index var float box_top = 0.00 var float box_bottom = 0.00 var float poi = 0.00 if box_type == 1 box_top := array.get(value_array, 0) box_bottom := box_top - atr_buffer poi := (box_top + box_bottom) / 2 else if box_type == -1 box_bottom := array.get(value_array, 0) box_top := box_bottom + atr_buffer poi := (box_top + box_bottom) / 2 okay_to_draw = check_overlapping(poi, box_array, atr) // okay_to_draw = true //delete oldest box, and then create a new box and add it to the array if box_type == 1 and okay_to_draw zone_with_strength last = array.get(box_array, array.size(box_array) - 1) if not na(last) box.delete(last.zone) box b = box.new(left = box_left, top = box_top, right = bar_index, bottom = box_bottom, border_color = supply_outline_color, bgcolor = color.new(supply_color, 80), extend = extend.none, text = tf_label, text_halign = text.align_right, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index) zone_with_strength zws = zone_with_strength.new(b, 0, tf_label) array_add_pop(box_array, zws) else if box_type == -1 and okay_to_draw zone_with_strength last = array.get(box_array, array.size(box_array) - 1) if not na(last) box.delete(last.zone) box b = box.new(left = box_left, top = box_top, right = bar_index, bottom = box_bottom, border_color = demand_outline_color, bgcolor = color.new(demand_color, 80), extend = extend.none, text = tf_label, text_halign = text.align_right, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index) zone_with_strength zws = zone_with_strength.new(b, 0, tf_label) array_add_pop(box_array, zws) // FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN sd_to_bos(box_array, bos_array, count_array, label_array, zone_type, tfclose, tfbarindex) => for i = 0 to array.size(box_array) - 1 zone_with_strength zws = array.get(box_array, i) if not na(zws) box b = zws.zone level_to_break_top = box.get_top(b) level_to_break_bottom = box.get_bottom(b) // if ta.crossover(close, level_to_break) if (zone_type == 1 and close >= level_to_break_top) or (zone_type == -1 and close <= level_to_break_bottom) copied_zone = zone_with_strength.copy(zws) box cz = copied_zone.zone mid = (box.get_top(b) + box.get_bottom(b)) / 2 line bosline = line.new(box.get_left(cz), mid, bar_index, mid, xloc.bar_index, extend.none, zone_type == 1 ? supply_outline_color : demand_outline_color, line.style_dotted) array_add_pop(bos_array, bosline) // box bos = array.get(bos_array, 0) // box.set_top(bos, mid) // box.set_bottom(bos, mid) // box.set_right(bos, bar_index) // box.set_extend(bos, extend.none) // box.set_text(bos, '') // box.set_text_color( bos, bos_label_color) // box.set_text_size(bos, size.small) // box.set_text_halign(bos, text.align_center) // box.set_text_valign(bos, text.align_center) box.delete(b) array.set(box_array, i, na) // array.remove(box_array, i) // box.delete(array.get(label_array, i)) // FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT extend_box_endpoint(box_array, count_array, tfbarindex, tfhigh, tflow) => for i = 0 to array.size(box_array) - 1 zone_with_strength zws = array.get(box_array, i) if not na(zws) box b = zws.zone top = box.get_top(b) bottom = box.get_bottom(b) count = zws.count if (high[swing_length - 1] >= bottom and high[swing_length - 1] <= top) or (low[swing_length - 1] >= bottom and low[swing_length - 1] <= top) count := count + 1 zws.count := count // count := count + 1 // zws.count := count box.set_right(b, bar_index + 40) box.set_text(b, str.format("{0} / {1}", count, zws.tf)) zws.zone := b array.set(box_array, i, zws) // //END FUNCTIONS // // // CALCULATIONS FOR SUPPORT AND RESISTANCE // calculateSR(swing_high_values, swing_low_values, swing_high_bns, swing_low_bns, supply_zone, demand_zone, current_supply_touch_count, current_demand_touch_count, current_supply_poi, current_demand_poi, supply_bos, demand_bos, series1, series2, tf_label, tfbarindex, tfclose, atr, is_htf, swing_high, swing_low, swing_index) => // NEW SWING HIGH if not na(swing_high) //MANAGE SWING HIGH VALUES array_add_pop(swing_high_values, swing_high) array_add_pop(swing_high_bns, swing_index) support_resistance(swing_high_values, swing_high_bns, supply_zone, current_supply_poi, current_supply_touch_count, 1, atr, tf_label, tfbarindex, is_htf) // NEW SWING LOW else if not na(swing_low) //MANAGE SWING LOW VALUES array_add_pop(swing_low_values, swing_low) array_add_pop(swing_low_bns, swing_index) support_resistance(swing_low_values, swing_low_bns, demand_zone, current_demand_poi, current_demand_touch_count, -1, atr, tf_label, tfbarindex, is_htf) sd_to_bos(supply_zone, supply_bos, current_supply_touch_count, current_supply_poi, 1, tfclose, tfbarindex) sd_to_bos(demand_zone, demand_bos, current_demand_touch_count, current_demand_poi, -1, tfclose, tfbarindex) extend_box_endpoint(supply_zone, current_supply_touch_count, tfbarindex, series1, series2) extend_box_endpoint(demand_zone, current_demand_touch_count, tfbarindex, series1, series2) var swing_high_values = array.new_float(5,0.00) var swing_low_values = array.new_float(5,0.00) var swing_high_bns = array.new_int(5,0) var swing_low_bns = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi = array.new_box(history_of_demand_to_keep, na) var current_demand_poi = array.new_box(history_of_demand_to_keep, na) var supply_zones = array.new(history_of_demand_to_keep, na) var demand_zones = array.new(history_of_demand_to_keep, na) var touches_for_supply = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR BOS var supply_bos = array.new_line(5, na) var demand_bos = array.new_line(5, na) var swing_high_values1 = array.new_float(5,0.00) var swing_low_values1 = array.new_float(5,0.00) var swing_high_bns1 = array.new_int(5,0) var swing_low_bns1 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones1 = array.new(history_of_demand_to_keep, na) var demand_zones1 = array.new(history_of_demand_to_keep, na) var touches_for_supply1 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand1 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi1 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi1 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos1 = array.new_line(5, na) var demand_bos1 = array.new_line(5, na) var swing_high_values2 = array.new_float(5,0.00) var swing_low_values2 = array.new_float(5,0.00) var swing_high_bns2 = array.new_int(5,0) var swing_low_bns2 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones2 = array.new(history_of_demand_to_keep, na) var demand_zones2 = array.new(history_of_demand_to_keep, na) var touches_for_supply2 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand2 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi2 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi2 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos2 = array.new_line(5, na) var demand_bos2 = array.new_line(5, na) var swing_high_values3 = array.new_float(5,0.00) var swing_low_values3 = array.new_float(5,0.00) var swing_high_bns3 = array.new_int(5,0) var swing_low_bns3 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones3 = array.new(history_of_demand_to_keep, na) var demand_zones3 = array.new(history_of_demand_to_keep, na) var touches_for_supply3 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand3 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi3 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi3 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos3 = array.new_line(5, na) var demand_bos3 = array.new_line(5, na) var swing_high_values4 = array.new_float(5,0.00) var swing_low_values4 = array.new_float(5,0.00) var swing_high_bns4 = array.new_int(5,0) var swing_low_bns4 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones4 = array.new(history_of_demand_to_keep, na) var demand_zones4 = array.new(history_of_demand_to_keep, na) var touches_for_supply4 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand4 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi4 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi4 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos4 = array.new_line(5, na) var demand_bos4 = array.new_line(5, na) var swing_high_values5 = array.new_float(5,0.00) var swing_low_values5 = array.new_float(5,0.00) var swing_high_bns5 = array.new_int(5,0) var swing_low_bns5 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones5 = array.new(history_of_demand_to_keep, na) var demand_zones5 = array.new(history_of_demand_to_keep, na) var touches_for_supply5 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand5 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi5 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi5 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos5 = array.new_line(5, na) var demand_bos5 = array.new_line(5, na) var swing_high_values6 = array.new_float(5,0.00) var swing_low_values6 = array.new_float(5,0.00) var swing_high_bns6 = array.new_int(5,0) var swing_low_bns6 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones6 = array.new(history_of_demand_to_keep, na) var demand_zones6 = array.new(history_of_demand_to_keep, na) var touches_for_supply6 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand6 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi6 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi6 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos6 = array.new_line(5, na) var demand_bos6 = array.new_line(5, na) var swing_high_values7 = array.new_float(5,0.00) var swing_low_values7 = array.new_float(5,0.00) var swing_high_bns7 = array.new_int(5,0) var swing_low_bns7 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones7 = array.new(history_of_demand_to_keep, na) var demand_zones7 = array.new(history_of_demand_to_keep, na) var touches_for_supply7 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand7 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi7 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi7 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos7 = array.new_line(5, na) var demand_bos7 = array.new_line(5, na) var swing_high_values8 = array.new_float(5,0.00) var swing_low_values8 = array.new_float(5,0.00) var swing_high_bns8 = array.new_int(5,0) var swing_low_bns8 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones8 = array.new(history_of_demand_to_keep, na) var demand_zones8 = array.new(history_of_demand_to_keep, na) var touches_for_supply8 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand8 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi8 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi8 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos8 = array.new_line(5, na) var demand_bos8 = array.new_line(5, na) var swing_high_values9 = array.new_float(5,0.00) var swing_low_values9 = array.new_float(5,0.00) var swing_high_bns9 = array.new_int(5,0) var swing_low_bns9 = array.new_int(5,0) // ARRAYS FOR SUPPORT / RESISTANCE var supply_zones9 = array.new(history_of_demand_to_keep, na) var demand_zones9 = array.new(history_of_demand_to_keep, na) var touches_for_supply9 = array.new_int(history_of_demand_to_keep, 0) var touches_for_demand9 = array.new_int(history_of_demand_to_keep, 0) // ARRAYS FOR SUPPORT / RESISTANCE POI LABELS var current_supply_poi9 = array.new_box(history_of_demand_to_keep, na) var current_demand_poi9 = array.new_box(history_of_demand_to_keep, na) // ARRAYS FOR BOS var supply_bos9 = array.new_line(5, na) var demand_bos9 = array.new_line(5, na) atr = ta.atr(50) if show_current_sr cur_tf_label = timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period swing_high = ta.pivothigh(swing_length, swing_length) swing_low = ta.pivotlow(swing_length, swing_length) swing_index = bar_index[swing_length] calculateSR(swing_high_values, swing_low_values, swing_high_bns, swing_low_bns, supply_zones, demand_zones, touches_for_supply, touches_for_demand, current_supply_poi, current_demand_poi, supply_bos, demand_bos, high, low, cur_tf_label, bar_index, close, atr, false, swing_high, swing_low, swing_index) // SUPPORT / RESISTANCE FOR HTF1 [high1, low1, close1, barindex1, atr1, timeframe1, swing_high1, swing_low1, swing_index1] = request.security(syminfo.tickerid, htf1, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF2 [high2, low2, close2, barindex2, atr2, timeframe2, swing_high2, swing_low2, swing_index2] = request.security(syminfo.tickerid, htf2, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF3 [high3, low3, close3, barindex3, atr3, timeframe3, swing_high3, swing_low3, swing_index3] = request.security(syminfo.tickerid, htf3, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF4 [high4, low4, close4, barindex4, atr4, timeframe4, swing_high4, swing_low4, swing_index4] = request.security(syminfo.tickerid, htf4, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF5 [high5, low5, close5, barindex5, atr5, timeframe5, swing_high5, swing_low5, swing_index5] = request.security(syminfo.tickerid, htf5, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF6 [high6, low6, close6, barindex6, atr6, timeframe6, swing_high6, swing_low6, swing_index6] = request.security(syminfo.tickerid, htf6, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF7 [high7, low7, close7, barindex7, atr7, timeframe7, swing_high7, swing_low7, swing_index7] = request.security(syminfo.tickerid, htf7, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF8 [high8, low8, close8, barindex8, atr8, timeframe8, swing_high8, swing_low8, swing_index8] = request.security(syminfo.tickerid, htf8, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) // SUPPORT / RESISTANCE FOR HTF9 [high9, low9, close9, barindex9, atr9, timeframe9, swing_high9, swing_low9, swing_index9] = request.security(syminfo.tickerid, htf9, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index[swing_length]]) if enableHtf1 and htf1 != "" calculateSR(swing_high_values1, swing_low_values1, swing_high_bns1, swing_low_bns1, supply_zones1, demand_zones1, touches_for_supply1, touches_for_demand1, current_supply_poi1, current_demand_poi1, supply_bos1, demand_bos1, high1, low1, timeframe1, barindex1, close1, atr1, true, swing_high1, swing_low1, swing_index1) if enableHtf2 and htf2 != "" calculateSR(swing_high_values2, swing_low_values2, swing_high_bns2, swing_low_bns2, supply_zones2, demand_zones2, touches_for_supply2, touches_for_demand2, current_supply_poi2, current_demand_poi2, supply_bos2, demand_bos2, high2, low2, timeframe2, barindex2, close2, atr2, true, swing_high2, swing_low2, swing_index2) if enableHtf3 and htf3 != "" calculateSR(swing_high_values3, swing_low_values3, swing_high_bns3, swing_low_bns3, supply_zones3, demand_zones3, touches_for_supply3, touches_for_demand3, current_supply_poi3, current_demand_poi3, supply_bos3, demand_bos3, high3, low3, timeframe3, barindex3, close3, atr3, true, swing_high3, swing_low3, swing_index3) if enableHtf4 and htf4 != "" calculateSR(swing_high_values4, swing_low_values4, swing_high_bns4, swing_low_bns4, supply_zones4, demand_zones4, touches_for_supply4, touches_for_demand4, current_supply_poi4, current_demand_poi4, supply_bos4, demand_bos4, high4, low4, timeframe4, barindex4, close4, atr4, true, swing_high4, swing_low4, swing_index4) if enableHtf5 and htf5 != "" calculateSR(swing_high_values5, swing_low_values5, swing_high_bns5, swing_low_bns5, supply_zones5, demand_zones5, touches_for_supply5, touches_for_demand5, current_supply_poi5, current_demand_poi5, supply_bos5, demand_bos5, high5, low5, timeframe5, barindex5, close5, atr5, true, swing_high5, swing_low5, swing_index5) if enableHtf6 and htf6 != "" calculateSR(swing_high_values6, swing_low_values6, swing_high_bns6, swing_low_bns6, supply_zones6, demand_zones6, touches_for_supply6, touches_for_demand6, current_supply_poi6, current_demand_poi6, supply_bos6, demand_bos6, high6, low6, timeframe6, barindex6, close6, atr6, true, swing_high6, swing_low6, swing_index6) if enableHtf7 and htf7 != "" calculateSR(swing_high_values7, swing_low_values7, swing_high_bns7, swing_low_bns7, supply_zones7, demand_zones7, touches_for_supply7, touches_for_demand7, current_supply_poi7, current_demand_poi7, supply_bos7, demand_bos7, high7, low7, timeframe7, barindex7, close7, atr7, true, swing_high7, swing_low7, swing_index7) if enableHtf8 and htf8 != "" calculateSR(swing_high_values8, swing_low_values8, swing_high_bns8, swing_low_bns8, supply_zones8, demand_zones8, touches_for_supply8, touches_for_demand8, current_supply_poi8, current_demand_poi8, supply_bos8, demand_bos8, high8, low8, timeframe8, barindex8, close8, atr8, true, swing_high8, swing_low8, swing_index8) if enableHtf9 and htf9 != "" calculateSR(swing_high_values9, swing_low_values9, swing_high_bns9, swing_low_bns9, supply_zones9, demand_zones9, touches_for_supply9, touches_for_demand9, current_supply_poi9, current_demand_poi9, supply_bos9, demand_bos9, high9, low9, timeframe9, barindex9, close9, atr9, true, swing_high9, swing_low9, swing_index9)