Alright, so obviously this sounds hella basic. I know how to fill between two plots using x > y, but what is really happening is that pinescript is filling between two float values that are represented by plots on the chart. Pinescript doesn't allow one to compare between two plots themselves, as evidenced by this error:
"line 366: Cannot call 'operator >' with 'expr1'=plot. The argument should be of type: float"
Here's the issue, that I think is unsolvable, but I want to see if any brains have a solution to this. I'm not much of a pinescript (or any language) coder. I'm making a baseline indicator with bands surrounding it. For each upper and lower band there are two plots that are filled between them. I want the fill color to be different depending on if one plot is above the other. This is perfectly normal, but the twist here is that technically speaking each of these pairs of plots are identical. What I'm doing is adding an offset to one of them, and this is what creates the cross. So now you see my problem. I can't use > or < to compare the plots because pinescript doesn't allow that, and because the offset is outside of the calculations of the plots themselves the language sees that both plots are the same. I can fill between the plots, because that's how "fill" is used, but I can't have a "bullish" and "bearish" fill because based on the calculations one plot (float, in reality) isn't above or below the other.
Can anyone think of a workaround for this??? Like somehow adding an offset to the calculation of a moving average? It's 100% a cosmetic thing, but I like cosmetic things, lol, and I want this optionality as it'll make the indicator look freakin great.
Many thanks from first time questioner.
Cheers, Scott
Below is the code.
.... smooth_mc_upper = mc_ma(mc_type, mc_upper, band_lkbk) smooth_mc_upper_two = mc_ma(mc_type, mc_upper, band_lkbk)
smooth_mc_lower = mc_ma(mc_type, mc_lower, band_lkbk) smooth_mc_lower_two = mc_ma(mc_type, mc_lower, band_lkbk)
////////////////////////////////////////////////////////////////////////////////
////PLOTS & FILLS FOR INTERIOR MAGIC CARPET p_mc_upper = plot(mc_on_off ? smooth_mc_upper : na, offset=offset_one, title="Interior Upper Band", display=display.none) p_mc_upper_two = plot(mc_on_off ? smooth_mc_upper_two : na, offset=offset_two, color=color.red, title="Interior Offset Upper Band")
p_mc_lower = plot(mc_on_off ? smooth_mc_lower : na, offset=offset_one, title="Interior Lower Band", display=display.none) p_mc_lower_two = plot(mc_on_off ? smooth_mc_lower_two : na, offset=offset_two, color=color.red, title="Interior Offset Lower Band")
fill(p_mc_upper, p_mc_upper_two, color=smooth_mc_upper > smooth_mc_upper_two ? bull_upper : bear_upper, title="Upper Interior Magic Carpet") fill(p_mc_lower, p_mc_lower_two, color=smooth_mc_lower > smooth_mc_lower_two ? bull_lower : bear_lower, title="Lower Interior Magic Carpet")
You have to account for the offset. If you are using a positive offset value (which it appears you are from your image), then it shouldn't be an issue.
Say you have an offset value of 50 on a plot. That means the current bar is actually the value of the variable 50 bars ago, equivalent to using the historical operator [50].
For example :
ma = ta.ema(close, 50)
off = 50
p1 = plot(ma, color = color.gray)
p2 = plot(ma, color = color.yellow, offset = off)
fill(p1, p2, color = ma > ma[off] ? color.lime : color.red)