I want to fill between 2 plots. It works when chart is in 1W mode, but the idea is to be able to use it in 1D or 4H but still see the plots and fill based on the 1W data, hence the resolution param. In these timeframes the fill disappears yet the plots remain.
//@version=4
study("SMA/EMA Ribbon", overlay=true, resolution="1W")
ribbon_period = input(20, "Period")
ema = ema(close, ribbon_period)
sma = sma(close, ribbon_period)
p1 = plot(ema, color= #53b987, title="EMA", transp = 50, linewidth = 1)
p2 = plot(sma, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)
fill(p1, p2, color = ema > sma ? #26d06a55 : #f3313d55)
Please see below code:
I compared the output of your code above and the below and both give the same output values.
//@version=4
study("SMA/EMA Ribbon - StackOverflow", overlay=true)
src = close,
res = input(title="Use Different Timeframe? Uncheck Box Above", type=input.resolution, defval="W")
ribbon_period = input(20, "Period")
ema = security(syminfo.tickerid, res, ema(src, ribbon_period))
sma = security(syminfo.tickerid, res, sma(src, ribbon_period))
//EMA Plots
p1 = plot(ema, title="W EMA 20", linewidth=1, color=#53b987, transp = 50)
p2 = plot(sma, title="W SMA 20", linewidth=1, color=#eb4d5c, transp = 50)
fill(p1, p2, color = ema > sma ? #26d06a55 : #f3313d55)