EMA crossover strategy fails to close positions
Forums › ProRealTime English forum › ProOrder support › EMA crossover strategy fails to close positions
- This topic has 4 replies, 3 voices, and was last updated 5 years ago by Thally.
-
-
08/05/2019 at 9:02 AM #104198
Hi,
I have written a simple EMA crossover strategy which I am now forward testing in demo mode. It is in the market close to 100% of the time and goes long when fast EMA crosses over the slow and vice versa for short positions and long exits. The strategy code is pasted below. The problem I am having is that it seems to be failing to close positions. E.g. Over night last night on the Nasdaq it when short at the appropriate place but failed to close out the position this morning when the fast EMA crossed above the slow (see attached image).
Does anyone have an idea as to why this is occurring and how it can be resolved?
Thanks,
Roj
EMA crossover strat1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253//-------------------------------------------------------------------------// Main code : EMA crossover NASDAQ m3//-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedEMAfast = 9EMAslow = 30//Risk ManagementCapital = 5000Risk = 0.01StopLoss = abs(close-ExponentialAverage[EMAslow](close))equity = Capital + StrategyProfitmaxrisk = round(equity*Risk)PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)// Conditions to enter long positionsindicator1 = ExponentialAverage[EMAfast](close)indicator2 = ExponentialAverage[EMAslow](close)c1 = (indicator1 CROSSES OVER indicator2)IF c1 THENBUY PositionSize PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator3 = ExponentialAverage[EMAfast](close)indicator4 = ExponentialAverage[EMAslow](close)c2 = (indicator3 CROSSES UNDER indicator4)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = ExponentialAverage[EMAfast](close)indicator6 = ExponentialAverage[EMAslow](close)c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELLSHORT PositionSize PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator7 = ExponentialAverage[EMAfast](close)indicator8 = ExponentialAverage[EMAslow](close)c4 = (indicator7 CROSSES OVER indicator8)IF c4 THENEXITSHORT AT MARKETENDIF08/05/2019 at 10:20 AM #104201Most likely because of the 3 minute time frame that you are using. If the chart that you show was started at a different minute to the minute that the strategy was started at then you will get a different chart. In fact you can get three different charts of the 3 minute time frame depending upon which of the three minutes that you start the chart on!
08/05/2019 at 11:53 AM #10420708/05/2019 at 1:53 PM #104213Five minute chart candles are always at 0000 0005 0010 0015 etc but a three minute candle is constructed from whenever the chart or strategy starts. If could be 0000 or 0001 or 0002. The open at 0000 is different to that at 0001 and so we can instantly see that a different three minute candle will be drawn depending on the start time. The close is different too and you are plotting an average of it so it stands to reason that the two different start times will not have the same average returned.
1 user thanked author for this post.
08/05/2019 at 2:46 PM #104215 -
AuthorPosts
Find exclusive trading pro-tools on