I want to color the background of price range within the latest 5 candle. Get the highest price and lowest price among them and color the background. Other previous candle ( candle 6 and previous ) I just want to ignore.
I'm newbie and still learning.
I try using :
highest(5)
lowest(5)
and
highest(high, 5)
lowest(low, 5)
But it didn't work for me.
Here's the closet example form Kodify web. But need to enter the price range manually.
//@version=4
study(title="Colour background in price range", overlay=true)
// STEP 1:
// Configure price range with inputs
rangeUp = input(title="Price Range Upper Bound", type=input.float, defval=1, minval=0)
rangeDown = input(title="Price Range Lower Bound", type=input.float, defval=0.95, minval=0)
fullBarInRange = input(title="Full Bar In Range?", type=input.bool, defval=false)
// STEP 2:
// Check if bar falls in range, based on input
insideRange = if fullBarInRange
high < rangeUp and low > rangeDown
else
high > rangeDown and low < rangeUp
// STEP 3:
// Plot range's upper and lower bound
ubPlot = plot(series=insideRange ? rangeUp : na, style=plot.style_linebr, transp=100, title="Upper Bound")
lbPlot = plot(series=insideRange ? rangeDown : na, style=plot.style_linebr, transp=100, title="Lower Bound")
// STEP 4:
// Fill the background for bars inside the price range
fill(plot1=ubPlot, plot2=lbPlot, color=#FF8C00, transp=75)