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

[amibroker] Re: looking for help on custom backtest procedure



PureBytes Links

Trading Reference Links

Thanks emp62!

--- In amibroker@xxxxxxxxxxxxxxx, "emp62" <emp62@xxx> wrote:
>
> hi,
> 
> below I show how to get started. This example shows a simple 
system where on the top you add the line with SetCustomBacktestProc 
where you call for a file.
> 
> The file called contains the CBT (custom back test). The code of 
this file is shown at the bottom. This particular CBT code makes a 
basket file ready to send to the TWS.  But CBT code can do various 
things. It can derive information from a existing backtest or it can 
alter an existing backtest. Soon I am promissed code that will 
enable one to do complicated portfolio backtests. 
> 
> rgds, Ed
> 
> 
> 
> 
> main program in indicator window
> 
> #pragma nocache 
> 
> SetCustomBacktestProc( "C:\\Amibroker 
Programs\\myAFL\\CustomBacktest\\IBbasketfileProfitStop.afl" ); 
> 
> // initial settings for portfolio trading (also see Settings 
window) 
> SetBarsRequired(10000,10000); 
> SetOption("MaxOpenPositions", 100 ); 
> PositionSize = -5; 
> SetTradeDelays(0,0,0,0); 
> 
> sk1 = RSI(14); 
> 
> // buy and short rules 
> Buy = Buy rules; 
> Short = Short rules; 
> 
> // sell and cover rules 
> ApplyStop ... 
> 
> 
> SetChartOptions(0, chartShowDates); 
> GraphXSpace = 5; 
> Plot(C,"C",1,64); 
> 
> 
> 
> 
> 
> 
> 
> in a separate file:   IBbasketfileProfitStop.afl 
> 
> SetOption("UseCustomBacktestProc", True ); 
> 
> if( Status("action") == actionPortfolio ) { 
>    
>    fh = fopen("c:\\Test4.txt", "w" ); 
>    bo = GetBacktesterObject(); 
>    bo.PreProcess(); 
>     
>    for( bar = 0; bar < BarCount; bar++ ) { 
> 
>       bo.ProcessTradeSignals( bar ); 
> 
>       if (bar == BarCount - 1) { 
>        
>          for( Openpos = bo.GetFirstOpenPos(); Openpos ; Openpos = 
bo.GetNextOpenPos() ) { 
>                 
>             // old positions still in portfolio 
>             if (Openpos.BarsInTrade > 1) { 
>           
>                // determine whether long / short position 
>                if (Openpos.IsLong) { 
>                 
>                   // format: SELL, 100, CHRW , STK, SMART, LMT, 
52.44, 
>                   pp = Openpos.GetPrice(Bar - 1,"H") - 0.01; 
>                   string = "SELL, " + Openpos.Shares + ", " + 
Openpos.Symbol + " , STK, SMART, LMT, " + pp + ","; 
>                   if( fh ) fputs( string + "\n", fh ); 
>                 
>                } else if (!Openpos.IsLong) { 
>                 
>                   // format: BUY, 100, CHRW , STK, SMART, LMT, 
52.44, 
>                   pp = Openpos.GetPrice(Bar - 1,"L") + 0.01; 
>                   string = "BUY, " + Openpos.Shares + ", " + 
Openpos.Symbol + " , STK, SMART, LMT, " + pp + ","; 
>                   if( fh ) fputs( string + "\n", fh ); 
>                 
>                } 
>                                
>             // the new positions to enter 
>             } else if (Openpos.BarsInTrade == 1) { 
>              
>                if (Openpos.IsLong) { 
>                 
>                   // format: BUY, 100, CHRW , STK, SMART, LMT, 
52.44, 
>                   pp = Openpos.GetPrice(Bar - 1,"C"); pp = Prec(pp 
+ pp/100*0.25 + 0.01,2); 
>                   string = "BUY, " + Openpos.Shares + ", " + 
Openpos.Symbol + " , STK, SMART, LMT, " + pp + ","; 
>                   if( fh ) fputs( string + "\n", fh ); 
>                    
>                } else if (!Openpos.IsLong) { 
>                 
>                   // format: SELL, 100, CHRW , STK, SMART, LMT, 
52.44, 
>                   pp = Openpos.GetPrice(Bar - 1,"C"); pp = Prec
(pp - pp/100*0.25,2); 
>                   string = "SELL, " + Openpos.Shares + ", " + 
Openpos.Symbol + " , STK, SMART, LMT, " + pp + ","; 
>                   if( fh ) fputs( string + "\n", fh );    
>                 
>                } 
>                 
>             }                   
>              
>          } 
> 
>       } 
>     
>    } 
> 
>    bo.PostProcess(); 
>    fclose( fh ); 
>    
> } 
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "tomsoyer_php" <tom.soyer@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Thursday, February 16, 2006 5:00 PM
> Subject: [amibroker] looking for help on custom backtest procedure
> 
> 
> > Hi,
> > 
> > Does anyone have examples of custom backtest procedures in AFL 
code? I 
> > read the beta documentation on the Advanced portfolio backtester 
> > inferface, but still couldn't figure out how to get it to work. 
There 
> > is no examples in the documentation, so it's hard to learn 
exactly how 
> > to do this (or maybe I am just stupid). Has anyone gotten it to 
work? 
> > 
> > Tom
> > 
> > 
> > 
> > 
> > 
> > 
> > Please note that this group is for discussion between users only.
> > 
> > To get support from AmiBroker please send an e-mail directly to 
> > SUPPORT {at} amibroker.com
> > 
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> > 
> > 
> > Yahoo! Groups Links
> > 
> > 
> > 
> > 
> > 
> >
>







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

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

 
Yahoo! Groups Links

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

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