EMA crossover strategy fails to close positions
- This topic has 4 replies, 3 voices, and was last updated 5 years ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › EMA crossover strategy fails to close positions
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
//------------------------------------------------------------------------- // Main code : EMA crossover NASDAQ m3 //------------------------------------------------------------------------- // Definition of code parameters DEFPARAM CumulateOrders = False // Cumulating positions deactivated EMAfast = 9 EMAslow = 30 //Risk Management Capital = 5000 Risk = 0.01 StopLoss = abs(close-ExponentialAverage[EMAslow](close)) equity = Capital + StrategyProfit maxrisk = round(equity*Risk) PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize) // Conditions to enter long positions indicator1 = ExponentialAverage[EMAfast](close) indicator2 = ExponentialAverage[EMAslow](close) c1 = (indicator1 CROSSES OVER indicator2) IF c1 THEN BUY PositionSize PERPOINT AT MARKET ENDIF // Conditions to exit long positions indicator3 = ExponentialAverage[EMAfast](close) indicator4 = ExponentialAverage[EMAslow](close) c2 = (indicator3 CROSSES UNDER indicator4) IF c2 THEN SELL AT MARKET ENDIF // Conditions to enter short positions indicator5 = ExponentialAverage[EMAfast](close) indicator6 = ExponentialAverage[EMAslow](close) c3 = (indicator5 CROSSES UNDER indicator6) IF c3 THEN SELLSHORT PositionSize PERPOINT AT MARKET ENDIF // Conditions to exit short positions indicator7 = ExponentialAverage[EMAfast](close) indicator8 = ExponentialAverage[EMAslow](close) c4 = (indicator7 CROSSES OVER indicator8) IF c4 THEN EXITSHORT AT MARKET ENDIF |
Most 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!
Five 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.
Find exclusive trading pro-tools on