I want to know whether the candles after crossover of EMA 6 and 12 are red or green.
I have written the code for the crossover also to find whether the candle is green or red after the crossover . I am having problem
ma = ema(close, 6)
ma2 = ema(close, 12)
aboveMa = crossover(ma,ma2)
// TO FIND THE NEXT CANDLE
threeAboveMa1 = aboveMa[1]
open[threeAboveMa1]
close[threeAboveMa1]
it is showing error
One way of doing this is, just find out whether the current bar is green or red and see if ma crossover happened one bar ago . You can use []
operator to access historical values.
//@version=5
indicator("My Script")
ma = ta.ema(close, 6)
ma2 = ta.ema(close, 12)
aboveMa = ta.crossover(ma,ma2)
greenCandle = aboveMa[1] and (close >= open)
redCandle = aboveMa[1] and (open > close)
plot(greenCandle ? 1 : 0, color=color.green)
plot(redCandle ? 1 : 0, color=color.red)
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.