Joana
Joana

Reputation: 1

signals repeating before reversal

I am working on an ema crossoversignal. Everything works but can't stop the buy or sell signal from appearing on every candle close.

I want to keep it on a candle close but only at the actual crossover candles. I mean, could be to keep the signal for the next 5 candles since crossover (30 min on 5 min chart) but not on every candle until opposite signal (it is what's happening)

Also could be only the ema crossover and have nothing to do with price action.

This is what I have got.

//@version=5
//Currently using Forex Session Templates Based on WET — Western European Time
indicator(title="LON & NY: Sessions Highlighter",shorttitle="LON & NY: Trading Sessions Highlighter", overlay=true)
timeinrange(res, sess) => time(res, sess) != 0


ema9 = ta.ema(close, 9)
ema200 = ta.ema(close, 200)

isCrossOver = if(ema9 > ema200)
    1
 
else
    0


isCrossUnder = if(ema9 < ema200)
    1

else
    0




plotshape(isCrossOver ? low : na, color=color.green, style=shape.triangleup, text = "BUY", textcolor = color.green,location=location.belowbar )
plotshape(isCrossUnder ? high : na, color=color.red, style=shape.triangledown, text = "SELL", textcolor = color.red,location=location.belowbar)
plot(isCrossOver,color = color.green)
plot(isCrossUnder, color = color.red)

//plotshape only at cross

plot(ema9, color = color.green)
plot(ema200, color = color.red)

//if(ta.crossover(ema50, ema200))

Upvotes: 0

Views: 50

Answers (1)

Gu5tavo71
Gu5tavo71

Reputation: 1214

Try to use not on the previous value[]

Something like this:

plotshape(isCrossOver and not isCrossOver[1]? low : na, color=color.green, style=shape.triangleup, text = "BUY", textcolor = color.green,location=location.belowbar )
plotshape(isCrossUnder and not isCrossUnder[1] ? high : na, color=color.red, style=shape.triangledown, text = "SELL", textcolor = color.red,location=location.belowbar)

Upvotes: 0

Related Questions