// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © kriswaters //@version=5 indicator('Zones Indicator v3', overlay=true, max_boxes_count=300, max_bars_back=4999) //HMA useHullFilter = input.bool(true,title="Use Hull Filter?",group="Zone") filterLb = input.int(10,minval=1,title="Filter Lookforward Period",group="Zone") n = input(title='HMA Length', defval=16,group="Zone") n2ma = 2 * ta.wma(close, math.round(n / 2)) nma = ta.wma(close, n) diff = n2ma - nma sqn = math.round(math.sqrt(n)) sqn1 = math.round(math.sqrt(n)) hullValue = ta.wma(diff, sqn) clrHull = hullValue > hullValue[1] ? color.green : color.red hullBull = hullValue > hullValue[1] hullBear = hullValue <= hullValue[1] plot(hullValue, color=clrHull,linewidth = 2) //ZONES minZoneLen = input.int(3, minval=1, title='Minumum Zone Length',group="Zone") lookback = input.int(200, minval=10, title='Lookback Period', tooltip='Minimum 10, Maximum 300',group="Zone") showEngulfBars = input(false, title='Show Engulf Bars',group="Zone") showImb = input(true, title='Show Imbalance Bars',group="Zone") //CALCS Wick = high - low Body = open - close Imbalance = Body * 100 / Wick bullCandle = close > open bearCandle = open > close imbCond = Imbalance > -50 and Imbalance < 50 bullEngulf = imbCond[1] and bullCandle and close > high[1] and imbCond == false bearEngulf = imbCond[1] and bearCandle and close < low[1] and imbCond == false var box sup = na var box res = na transpClrBull = color.new(color.gray,100) transpClrBear = color.new(color.gray,100) defaultBgClr = color.new(color.black,60) defaultBorderClr = color.new(color.teal,0) if bullEngulf sup := box.new(bar_index - 1, math.max(open[1], close[1]), bar_index, low[1], bgcolor=useHullFilter ? transpClrBull : defaultBgClr, border_color=useHullFilter ? transpClrBull : defaultBorderClr) if bearEngulf res := box.new(bar_index - 1, high[1], bar_index, math.min(open[1], close[1]), bgcolor=useHullFilter ? transpClrBear : defaultBgClr, border_color=useHullFilter ? transpClrBear : defaultBorderClr) if barstate.islast var int bullCount = 0 var int bearCount = 0 var int shiftCount = 0 var int shiftIndex = 0 var isBull = false var isBear = false var bool isShift = false var float tempLow = na var float tempHigh = na var int tempIndex = na for i = 0 to lookback - 1 by 1 //Calculate Hull filter if (hullValue[i] > hullValue[i+1]) and (hullValue[i+1] <= hullValue[i+2]) isBull := true isBear := false tempLow := na tempHigh := na if (hullValue[i] < hullValue[i+1]) and (hullValue[i+1] >= hullValue[i+2]) isBear := true isBull := false tempLow := na tempHigh := na if (hullValue[i] > hullValue[i+1]) and (hullValue[i+1] <= hullValue[i+2]) or (hullValue[i] < hullValue[i+1]) and (hullValue[i+1] >= hullValue[i+2]) shiftCount := 0 isShift := true shiftIndex := bar_index[i] if hullBull[i] shiftCount := shiftCount + 1 if hullBear[i] shiftCount := shiftCount + 1 //Support box supPrice = box.get_top(sup[i]) supPriceLow = box.get_bottom(sup[i]) indexBull = box.get_left(sup[i]) diffBull = math.abs(bar_index - indexBull) box.set_right(sup[i], bar_index + 20) //Check Hull Confrimation / Bullish zones if isShift and math.abs(indexBull-shiftIndex) <= filterLb and isBull and useHullFilter if supPriceLow == nz(tempLow,supPriceLow) tempLow := supPriceLow box.set_bgcolor(sup[i],color=color.new(color.black,60)) box.set_border_color(sup[i],color=color.new(color.teal,0)) else if supPriceLow < tempLow box.set_bgcolor(sup[tempIndex],color=transpClrBull) box.set_border_color(sup[tempIndex],color=transpClrBull) box.set_bgcolor(sup[i],color=color.new(color.black,60)) box.set_border_color(sup[i],color=color.new(color.teal,0)) tempIndex := i //Check deleted boxes for j = 0 to math.max(diffBull - 2, 0) by 1 if open[j] > supPrice and low[j] < supPrice box.set_right(sup[i], bar_index[math.max(j + 1, 0)]) if indexBull + minZoneLen > bar_index[math.max(j + 1, 0)] box.delete(sup[i]) //Resistanc box resPrice = box.get_bottom(res[i]) resPriceHigh = box.get_top(res[i]) indexBear = box.get_left(res[i]) diffBear = math.abs(bar_index - indexBear) box.set_right(res[i], bar_index + 20) //Check Hull Confrimation / Bearish zones if isShift and math.abs(indexBear-shiftIndex) <= filterLb and isBear and useHullFilter if resPriceHigh == nz(tempHigh,resPriceHigh) tempHigh := resPriceHigh box.set_bgcolor(res[i],color=color.new(color.black,60)) box.set_border_color(res[i],color=color.new(color.teal,0)) else if resPriceHigh > tempHigh box.set_bgcolor(res[tempIndex],color=transpClrBull) box.set_border_color(res[tempIndex],color=transpClrBull) box.set_bgcolor(res[i],color=color.new(color.black,60)) box.set_border_color(res[i],color=color.new(color.teal,0)) tempIndex := i for j = 0 to math.max(diffBear - 2, 0) by 1 if open[j] < resPrice and high[j] > resPrice //box.delete(res[i]) box.set_right(res[i], bar_index[math.max(j + 1, 0)]) if indexBear + minZoneLen > bar_index[math.max(j + 1, 0)] box.delete(res[i]) box.delete(sup[lookback - 1]) box.delete(res[lookback - 1]) //PLOTS barcolor(showImb and imbCond ? color.white : na) barcolor(showEngulfBars and bearEngulf ? color.new(color.purple, 0) : na) barcolor(showEngulfBars and bullEngulf ? color.new(color.yellow, 0) : na)