There is a script ( Vector Candle Zones/Cloud MTF X4 ) which can plot imbalanced candle zones at MTF.
This is the 4hr timeframe:
This is the 1hr timeframe:
This code is hidden and to elaborate for what I want. I only need the vector (imbalanced candle) zones option. If possible with the mitigation calculation and script.
The code should draw boxes when the candle volume value from the 4hr timeframe is on average 1.5 higher then the average volume of the last 10 candles on the 4hr timeframe.
It should draw a box with the open and close value as top and bottom values for the box at that time.
When I am on the 4hr timeframe this code works OK
, but no mitigation.
When I switch to the 1hr timeframe the boxes do not align with the 4hr timeframe values anymore even though I use request.security(syminfo.tickerid, "240", close)
.
What am I missing??
So far, this is the code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator("Box Indicator", overlay=true)
var color GREEN = color.green
var color RED = color.red
var string G1 = "Show"
var string G2 = "Hide"
var string IMB1 = "Shrink when mitigated"
var string IMB2 = "Do not shrink"
var GRP3 = "Imbalance Zones"
showImbalance = input.bool(true, "Show Imbalance/Fair Value Gaps", inline = "30", group = GRP3)
numberOfZonesInput = input.int(6, "# Zones", inline = "31", group = GRP3)
updateZonesWithPriceMovement = input.string(IMB1, "", inline = "32", options = [IMB1, IMB2], group = GRP3) == IMB1
bullishImbColorInput = input.color(GREEN, "", inline = "32", group = GRP3)
bearishImbColorInput = input.color(RED, "", inline = "32", group = GRP3)
imbTranspInput = input.int(80, "Transparency", inline = "32", group = GRP3)
// Calculate average volume of the last 10 candles on the 4-hour timeframe
avgVolume = ta.sma(request.security(syminfo.tickerid, "240", volume), 10)
actVolume = request.security(syminfo.tickerid, "240", volume)
// Calculate ohlc values from the 4-hour timeframe
pvsra_open = request.security(syminfo.tickerid, "240", open)
pvsra_close = request.security(syminfo.tickerid, "240", close)
pvsra_high = request.security(syminfo.tickerid, "240", high)
pvsra_low = request.security(syminfo.tickerid, "240", low)
// Calculate bearish or bullish candle of the last candle on the 4-hour timeframe
isBull = pvsra_close > pvsra_open
isBear = pvsra_open > pvsra_close
// Check for candles on the 4-hour timeframe with volume 150% larger than the average
bullishImb = actVolume > avgVolume * 1.5 and isBull
bearishImb = actVolume > avgVolume * 1.5 and isBear
var box[] bullishImbBox = array.new_box()
var box[] bearishImbBox = array.new_box()
var color bullColor = color.new(bullishImbColorInput, imbTranspInput)
var color bearColor = color.new(bearishImbColorInput, imbTranspInput)
if bullishImb and showImbalance
array.push(bullishImbBox, box.new(left = time, top = pvsra_close, right = time, bottom = pvsra_open, extend = extend.right, xloc = xloc.bar_time, border_color = bullColor, border_style = line.style_dashed, bgcolor = bullColor))
if array.size(bullishImbBox) + array.size(bearishImbBox) > numberOfZonesInput
box.delete(array.shift(bullishImbBox))
if bearishImb and showImbalance
array.push(bearishImbBox, box.new(left = time, top = pvsra_open, right = time, bottom = pvsra_close, extend = extend.right, xloc = xloc.bar_time, border_color = bearColor, border_style = line.style_dashed, bgcolor = bearColor))
if array.size(bullishImbBox) + array.size(bearishImbBox) > numberOfZonesInput
box.delete(array.shift(bearishImbBox))
So far I have struck rock bottom so I anyone of you Could help me, it would be appreciated, also with the mitigation part of the code.