[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Custom Backtester Slippage Code for ApplyStop - Need Help



PureBytes Links

Trading Reference Links

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 );
    }
  }


__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___