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

[amibroker] Re: Simple slippage implemented in CBT generates COM error



PureBytes Links

Trading Reference Links

But I need "ExitAtStop" to be set at "1" in order for it to exit between the Low and High of each bar, as opposed to exiting on, say, the Close. 

I am trading intraday. And in order to model the profitstop I use in the real world, ApplyStop needs to exit with ExitAtStop = 1.

Therein lies the problem.


--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> You don't need custom backtester to do such things.
> BuyPrice = BuyPrice + Slippage:
> SellPrice = SellPrice - Slippage;
> CoverPrice = CoverPrice + Slippage:
> ShortPrice = ShortPrice - Slippage.
> 
> When using ApplyStop make sure to switch "ExitAtStop" argument to false
> and it will use prices defined above.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
>   ----- Original Message ----- 
>   From: Aron 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Thursday, March 19, 2009 8:08 AM
>   Subject: Re: [amibroker] Re: Simple slippage implemented in CBT generates COM error
> 
> 
>   Tomasz Janeczko wrote: 
>     Hello,
> 
>     You need to call ProcessTradeSignals.
> 
>     BTW: it is easier to just define custom commission table (AA->Settings "Commission table: Define...") 
>     that includes slippage than wresting with code.
> 
>     Best regards,
>     Tomasz Janeczko
>     amibroker.com
>   Hello Tomasz,
> 
>   I would deeply appreciate if you provided an example on how to adjust Exits in CBT in order to account for spread and slippage.
> 
>   For FX scalping systems backtesting (takeProfit = 2-3 pips. ) , I think it is crucial to be able to do this since all depends on spread and slippage (if commissions ==0).
> 
>   Unfortunately, the code I have come up with is not quite working :
> 
>   // EURUSD example
>   // price = (bid+ask)/2
> 
>   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" ); 
> 
>             
>               slippage = 0.0001; 
>               spread = 2 * 0.0001; 
>             
> 
>              
> 
>               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 ) // bid pricebound check
>                       { 
>                           sig.price = TrueExit; 
>                          // bo.ExitTrade( BAR, sig.Symbol, sig.Price ); 
>                       } 
>                       else 
>                           sig.price = -1; 
> 
> 
> 
>                   } 
>                   else // Exit short 
>                   { 
>                       TrueExit = sig.price + slippage; 
> 
>                       if ( TrueExit >= lo[bar] + 0.5*spread && TrueExit <= hi[bar] + 0.5*spread ) // ask pricebound check
>                       { 
>                           sig.price = TrueExit; 
>                           //bo.ExitTrade( BAR, sig.Symbol, sig.Price ); 
>                       } 
>                       else 
>                           sig.price = -1; 
> 
>                   } 
>               } 
>           } 
> 
>           bo.ProcessTradeSignals( bar ); 
> 
>           bo.handlestops( bar ); 
>          
>       } 
> 
>       for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) 
>       { 
>           trade.addcustommetric( "numPips", ( trade.exitprice - trade.entryprice ) / trade.ticksize ); 
>       } 
> 
>       bo.PostProcess(); 
>   }
>




------------------------------------

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

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

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/