Hi

Have you considered making slippage a part of the commision and 
adjust it in the backtester commision settings beforehand, thus avoid 
doing complicated calculations with the signal object of custom 
backtester ?

Huanyan


--- In [email protected], "ozzyapeman" <zoopf...@...> wrote:
>
> Hello, hoping someone can help out with this code. Aron was kind 
enough
> to post a version of some code that is meant to inject some slippage
> when using ApplyStop(). However, I can't seem to get it to work. 
All I
> want it to do is reduce Long exits by 2 pips (I'm backtesting 
Forex) and
> increase Short exits by 2 pips, when using ApplyStop.
> 
> Here is the code. At present, it only ends up blanking out my 
backtest
> report - no trades taken. Without the code, dozens or hundreds of 
trades
> taken, depending on which system I test. As far as I can tell, this 
code
> should work, but doesn't. Any input appreciated:
> 
> 
> SetCustomBacktestProc( "" );
> if ( Status( "action" ) == actionPortfolio )
> {
>      TickSize = 0.0001;           // Forex
>      bo = GetBacktesterObject();
>      bo.PreProcess();
>      slipage = TickSize;
>      spread = 2 * TickSize;
> 
>      for ( bar = 0; bar < BarCount; bar++ )
>      {
>            for ( sig = bo.GetFirstSignal(bar); sig; sig =
> bo.GetNextSignal(bar) )
>            {
>             symbol = sig.symbol;
>             hi = Foreign(symbol, "H");
>             lo = Foreign(symbol, "L");
> 
>               if ( sig.IsExit() )
>               {
>                 if ( sig.isLong)
>                 {
>                   realexitprice = sig.price - slipage;
>                    if( realexitprice >= lo[bar] && realexitprice <=
> hi[bar])
>                    {
>                      sig.price = realexitprice;
>                      bo.ExitTrade(bar,sig.symbol,sig.Price);  // 
I'm not
> sure if it is needed
>                     }
>                    else
>                      sig.price = -1;
>                  }
>                  else
>                 {
>                  ealexitprice = sig.price + slipage;
>                    if (realexitPrice >= lo[bar]+ spread && 
realexitprice
> <= hi[bar]+spread)
>                    {
>                      sig.price = realexitprice;
>                      bo.ExitTrade(bar,sig.symbol,sig.Price); // I'm 
not
> sure if it is needed
>                     }
>                    else
>                      sig.price = -1;
>                  }
> 
>                }
>              }
> 
>          bo.ProcessTradeSignals( bar );
>      }
>    }
>


Reply via email to