Hello,
I would like to ask a strategy that works this way:
EMA50<EMA100<EMA200 and with a distance between them that can be defined
buy if close crosses over ema 200 and the close of three candle before is lower than EMA50 (so price needs to crosse the three EMA in not more than 3 candles)
the opposite for short.
thank’s in advance
Alessio
I did something like this but it opens also position when it shouldn’t.
DEFPARAM CumulateOrders = false
Ema50= ExponentialAverage[50](close)
ema100= ExponentialAverage[100](close)
Ema200= ExponentialAverage[200](close)
c1= close crosses under ema200 and close[barindex-3]>=ema50
c2= close crosses over ema200 and close[barindex-3]<=ema50
c3=ema50>ema100
c4=ema100>ema200
c5=ema50<ema100
c6=ema100<ema200
If not longonmarket and c2 and c5 and c6 then
Buy 1 contract at Market
endif
If longOnMarket AND (BarIndex - TradeIndex) >= 4 Then
Sell at Market
Endif
If not shortonmarket and c1 and c3 and c4 then
sellshort 1 contract at Market
endif
If shortOnMarket AND (BarIndex - TradeIndex) >= 4 Then
exitshort at Market
Endif
exit is just to try, nothing defined
JSParticipant
Senior
Hi,
Try using Close[3] instead of Close[BarIndex-3]…
Hi
You have to change c1 and c2:
c1= close crosses under ema200 and close[3]>=ema50
c2= close crosses over ema200 and close[3]<=ema50
I didn’t see your answer…
As Roberto says, better 2 than… 🙂
Thank you very much Ivan, 2 is better than one, of course! by the way I don’t understand why close[barindex–3] was not correct.
thanks
Alessio
Hi,
Maybe you should check the Probuilder’s manual or at least here https://www.prorealcode.com/documentation/close/
I think doing that will clarify your doubts.
why close[barindex–3] was not correct.
barindex increases by 1 for every new candle and so if your Algo has been running for 600 candles then you would have close[barindex–3] = close[597]