Hello community,
I am working on a automated strategy and would ask you, if you can help me at one point in my code.
The strategy includes some EMA’s and i tried to figure out the exactly chartposition (value) when one EMA crosses the other EMA.
I am still stuck at this point and couldnt even find anything in the code documentation.
I would like to share my code after backtests here, but i need this parameter for clocking up the performance in real trading and not only in backtesting.
Does someone knows the right coding?
Thank you very much
Trade Wolf
Hello Trade Wolf,
You can record the EMA value when you detect of the crossing of your 2 moving average:
if EMA1 crosses over EMA2 then
value = EMA1[1]
endif
crosses over and crosses under refer to crosses that have already occurred, so you can get value of the EMA within a 1 period offset in the past: EMA1[1]
I think it should make the trick. Please let us know.
Hi Nicolas,
this sounds very good and i think this will do the job.
But now the problem is that the execution of the BUY/SELL-Order starts with the next candle, instead of the exact moment when the EMA’s are crossing. So i will miss the correct entry point for my orders 🙁
I hope you can tell me the solution for this, if there is anyone.
Thank you and sorry for my ignorance.
Conditions are tested at bar close and trades are launched at next bar open. That’s how PRT deals with the code.
It sounds logic since moving average are commonly calculated on price Close, so that’s why we need to wait the candlestick close to validate their crossing.
Thanks Nicolas. This makes sense.
I will try to go on with this conditions.