简体   繁体   中英

Color background within price range of only latest 5 candle ( highest and lowest price level)

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)

Version 1

This will fill between the highest/lowest of the last 5 bars:

//@version=4
study("Hi/Lo Range", "", true)
p = input(5)
hi = highest(p)
lo = lowest(p)
p_hi = plot(hi, "Hi")
p_lo = plot(lo, "Lo")
fill(p_hi, p_lo)

在此处输入图像描述

Version 2

//@version=4
study("Hi/Lo Range", "", true)
p = input(5)
hi = highest(p)
lo = lowest(p)
p_hi = plot(hi, "Hi", show_last = 5)
p_lo = plot(lo, "Lo", show_last = 5)
fill(p_hi, p_lo, show_last = 5)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM