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

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



PureBytes Links

Trading Reference Links

ozzyapeman 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:
Good Idea to move this in a separate thread.
I do not know why the following ways accessing TickSize are not working.

method 1
-------------------------------------------
slippage = TickSize;
spread =
2 * TickSize;
for ( bar = 0; bar < BarCount; bar++ )
    {
          
for ( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar) )
          {
method 2
-------------------------------------------

for ( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar) )
{
    slippage = sig.TickSize;
    spread =
2 * sig.TickSize;
}



the followng code returns correctly slippage and spread but the trades are not stopped out at exactly stop distance
I'm having this problem with ApplyStop() generally.

//------------------------------------------------
// Settings for  ( BID+ASK) /2
//------------------------------------------------

SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
   bo =
GetBacktesterObject();
   bo.PreProcess();
   
   
   
for ( bar = 0; bar < BarCount; bar++ )
   {
      
for ( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar) )
      {
         symbol = sig.symbol;
         hi =
Foreign(symbol, "High");
         lo =
Foreign(symbol, "Low");
         
         
         
if( StrFind(symbol, "JPY"))
         {
            slippage =
0.01;
            spread =
2 * 0.01;
         }
         
else
         {
            slippage =
0.0001;
            spread =
2 * 0.0001;
         }
         
         
if(sig.isEntry())
// Contract Specifications
         {
            sig.pointvalue =
1;
// allows trading in units ie. 1234 EURUSD
            sig.margindeposit = sig.price / 100; // Leverage used 1:100
         }
         
         
if ( sig.IsExit() )
         {
                           
            
if ( sig.isLong) // Exit Long
            {
               TrueExit = sig.price - slippage;
               
if( TrueExit >= lo[bar] + 0.5*spread && TrueExit <= hi[bar] - 0.5*spread)
               {
                  sig.price = TrueExit;
               }
               
else
               sig.price = -
1;
// Ignore signal
            }
            
else // Exit short
            {
               TrueExit = sig.price + slippage;
               
if (TrueExit >= lo[bar]+ 0.5*spread && TrueExit <= hi[bar]+0.5*spread)
               {
                  sig.price = TrueExit;                  
               }
               
else
               sig.price = -
1;
// Ignore signal
            }
         }
      }
      
      bo.ProcessTradeSignals( bar );
   }
   
   bo.PostProcess();
}


__._,_.___

**** 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

__,_._,___