0

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)
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

0

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)

enter image description here

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)

enter image description here

Community
  • 1
  • 1
PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
  • Thanks PineCoders-LucF.. But is there any way i can just color the last 5 candle and ignore the rest previous candle ( candle 6 and previous ) – Gen Tradex Jun 15 '20 at 00:52
  • Yes. See version 2 of the answer. – PineCoders-LucF Jun 15 '20 at 15:17
  • Dear Coders, I would like to improve the script and create it like this : https://i.stack.imgur.com/8swCa.png 1 .The box will display 30 boxes backward, start from latest candle (Monday, trading day) 2. The boxes shouldn't move when new candle appear/born because I need to see the progress/trend. Thanks and hope to get feedback and idea :) – Gen Tradex Jun 23 '20 at 23:00
  • Try the "Multi-Time Period Charts" built-in. – PineCoders-LucF Jun 24 '20 at 01:53