Help get this topic noticed by sharing it on Twitter, Facebook, or email.

# HOW TO FILL COLOR BETWEEN EMA 20 HIGH AND EMA 20 LOW FROM LAST 5 CANDLE TO CURRENT CANDLE ? Edit Subject

i want help in my script.
i want that if price closes above ema(high, 20) or below ema(low, 20) then there should be color filled between both 20high and 20low ema from last 5 candle to current candle(where close cross ema20 low or high).
otherwise both ema should be invisible till next cross over.
2 people have
this question
• Something like this?

Make notations in MS Paint and repost if this is close to your conception.
How does this make you feel?
I'm

• like explained in screenshot, i just want that if price close above ema(high,20)
or close below ema(low, 20) then only both ema should be visible with color filled between both. and it should be visible from the candle where cross happened to previous 5 candles.
when new candle open after that cross candle both ema should be invisible till next cross of price to ema.
How does this make you feel?
I'm
• it's possible to implement with such workout:

```
//@version=3
study("My Script")
condition = close > 220 // here's condition, where you can put your `ema`s
color = condition ? red : white // white is workout for light theme
p1 = plot(open, color = color)
p2 = plot(close, color = color)
fill(p1, p2, color = color)```

Note: it works with light color theme.
I hope, make suitable for you condition won't be a problem.

How does this make you feel?
I'm
• thank you very much sir.
but it is plotting emas on where cross happened but i want that when cross happen
emas should be plotted from current cross candle to previous 5 candle.
is there any way to do that.

god bless you
• As handling of a bar has finished, it's impossible to change the series of the bar. At the same time, you cannot look at the comming bars, because they don't exist yet. Considering this, we can't fill 5 previous candles - only current and (if you wish) - numerous next bars, but none of previous.
In my example, I just showed a workaround for making partial filling. To implement crossing you should look at @midtownsk8rguy's example below. Maybe `na` won't work (I haven't tried the snippet) and you'll have to use white (or black if you use dark theme) to hide the plot.
How does this make you feel?
I'm
• I was thinking along the lines of:
```
highColor = close > ema(high, 20) ? lime : na
lowColor = close < ema(low, 20) ? red : na
//OR
highColor = crossover(close, ema(high, 20)) ? lime : na
lowColor = crossunder(close, ema(low, 20)) ? red : na```

This way the line plots and should be invisible on ANY background using "na" for color=. Using plot(condition ? close : na, color=) would create an undesirable zig zag effect. You might also be able to use:

bgcolor(crossover(close, ema(high, 20)) ? lime : na)

This is a technique I have used for those momentary crosses that occur every once in a while.

REPAINTING 5 previous bars after they have been plotted has always failed for me. You should be able to use plotchar(char="*", offset=-1)plotchar(char="*", offset=-2)plotchar(char="*", offset=-3)plotchar(char="*", offset=-4)plotchar(char="*", offset=-5) or plotshape(offset=-1)... Don't forget your location= using these. The algorithm could be complex tossing this around in my mind. Good luck!
How does this make you feel?
I'm
• ```
//@version=3
study("[RS]ZigZag (MA, Pattern Recognition) V2", overlay=true)
ema20 = ema(close, 20)
ema40 = ema(close, 40)
plotEMA20 = plot(ema20, color=ema20>ema40 ? lime : na)
plotEMA40 = plot(ema40, color=ema20>ema40 ? red : na)
fill(plotEMA20, plotEMA40, color=ema20>ema40 ? lime : na)```

Plotting the lines with plot(color=na) works GREAT, however fill(color=na) was not as expected. Possible bug I'm suspecting. I drag/zoom the screen and fill changes colors from a gray to a lime inconsistently. I uploaded a picture and encircled the anomalies in red.
How does this make you feel?
I'm
• ```
//@version=3
study("[RS]ZigZag (MA, Pattern Recognition) V2", overlay=true)
ema20 = ema(close, 20)
ema40 = ema(close, 40)
plotEMA20 = plot(ema20, color=ema20>ema40 ? lime : na)
plotEMA40 = plot(ema40, color=ema20>ema40 ? red : na)
fill(plotEMA20, plotEMA40, color=ema20>ema40 ? color(lime,0) : color(na,100))```

Result: Script study added to the chart, BUT Internal server pine compilation error

The following below did work as expected though:
```
//@version=3
study("[RS]ZigZag (MA, Pattern Recognition) V2", overlay=true)
ema20 = ema(close, 20)
ema40 = ema(close, 40)
plotEMA20 = plot(ema20, color=ema20>ema40 ? lime : na)
plotEMA40 = plot(ema40, color=ema20>ema40 ? red : na)
fill(plotEMA20, plotEMA40, color=ema20>ema40 ? color(lime,0) : color(lime,100))```

How does this make you feel?