Backtest seems to ignore Trade Close Conditions

Created at 19 Jun 2013, 03:35
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Delta_Gamma's avatar

Delta_Gamma

Joined 02.06.2013

Backtest seems to ignore Trade Close Conditions
19 Jun 2013, 03:35


Hi,


I have coded my bot so that if for example a SELL trade is entered and the price closes above the SMA it closes the position(vice versa with BUY, except closes below).

This seems to work when I forward test the bot, however when backtesting it seems to ignore this condition and go on to hit the 100 pip stop loss I set, this of course skews the results of the backtest significantly.

Please see attached pic for an example of this. As you can see, the trade goes on to close much later instead of closing above the SMA.


Is there any explanation for this? I worry that it will happen in the forward test randomly.

 

Thanks for the help.

   this is the Close Position code:


            foreach (Position position in _listPosition)
            {              
                            
             if  
                  (position.TradeType == TradeType.Buy &&  Functions.HasCrossedBelow(MarketSeries.Close,WELL.Result,0)) 
                  {
                    ClosePosition(position);
                  }                   
                        

            if (position.TradeType == TradeType.Sell && Functions.HasCrossedAbove(MarketSeries.Close,WELL.Result,0)) 
                {
                    ClosePosition(position);
                }    
            
            }

 

   
                     

 

 

 


@Delta_Gamma
Replies

daemon
19 Jun 2013, 13:07

Try using period 1:

 Functions.HasCrossedBelow(MarketSeries.Close,WELL.Result,1)




@daemon

Delta_Gamma
23 Jun 2013, 07:01

Ah that worked! dunno why I didn't think of that lol.

Thanks mate.


@Delta_Gamma