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

[amibroker] Re: Removing Trades In Custom Backtester



PureBytes Links

Trading Reference Links

I can't get this to work properly. The moment it sets any trade to
PosSize = 0, it stops processing anymore trades. Thus, if you hit the
limit on your longs, it won't process anymore shorts.

Jay

--- In amibroker@xxxxxxxxxxxxxxx, "emp62" <emp62@xxx> wrote:
>
> hi,
> 
> I have done something similar in the past and I believe it worked.
Have a look. It seems you do the same so I'm not sure my code will help,
> 
> rgds, Ed
> 
> 
> 
> 
> /* 
> 
> Do not allow more than "maxLong" LONG positions OR "maxShort" SHORT
positions 
> 
> */ 
> 
> SetCustomBacktestProc(""); 
> 
> maxLong = 8; 
> maxShort = 9; 
> 
> if( Status("action") == actionPortfolio ) { 
> 
>    bo = GetBacktesterObject(); 
>    bo.PreProcess(); 
>     
>    for( i = 0; i < BarCount; i++ ) { 
>     
>     
>       cntLongOpen = 0; 
>       cntShortOpen = 0; 
>     
>       // scan through open positions and count the number of long
positions 
>       for( openpos = bo.GetFirstOpenPos(); openpos; openpos =
bo.GetNextOpenPos() ) { 
>           
>          // check for entry signal and long signal 
>          if( openpos.IsOpen AND openpos.IsLong ) { 
>           
>             cntLongOpen = cntLongOpen + 1; 
>              
>          } else if ( openpos.IsOpen AND openpos.IsLong == 0) { 
>           
>             cntShortOpen = cntShortOpen + 1; 
>           
>          } 
>        
>       } 
>     
>     
>       // look at new signals and exclude Long signals if they exceed
maxLong 
>       for( sig = bo.GetFirstSignal(i); sig; sig =
bo.GetNextSignal(i) ) { 
>        
>          // check for entry signal and long signal 
>          if( sig.IsEntry() AND sig.IsLong() ) { 
>           
>             if( cntLongOpen >= maxLong ) {   
>              
>                sig.PosSize = 0; 
>                 
>             } else { 
>              
>                cntLongOpen = cntLongOpen + 1; 
>                 
>              
>             } 
>              
>          // check for entry signal and short signal    
>          } else if ( sig.IsEntry() AND sig.IsLong() == 0) { 
>           
>             if( cntShortOpen >= maxShort ) {   
>              
>                sig.PosSize = 0; 
>                 
>             } else { 
>              
>                cntShortOpen = cntShortOpen + 1; 
>                 
>              
>             } 
>              
>              
>          } 
>           
>        
>       } 
> 
>       bo.ProcessTradeSignals( i ); 
>    } 
> 
>    bo.PostProcess(); 
> 
> } 
> 
> 
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "C Alvarez" <yahoo@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Saturday, January 21, 2006 1:37 AM
> Subject: [amibroker] Removing Trades In Custom Backtester
> 
> 
> >I am backtesting a portolfio stock system. I am using the custom 
> > backest proc to decide if certain trades should happen or not, based 
> > on how many open position there are and other factors. So I walk 
> > through the signals on a bar and check my condition. If a trade 
> > should not happen, then I try and set the position size to zero. 
> > This works, the trade for the symbol does not happen, but then all 
> > other signals for that bar do not happen.
> > 
> > Any ideas on how to get this to work. It is almost like I need to 
> > resort the signal array, but I do not know how to do that.
> > 
> > Code below.
> > 
> > Thanks,
> > Cesar
> > 
> > 
> > SetCustomBacktestProc(""); 
> > 
> > if( Status("action") == actionPortfolio ) { 
> >   bo = GetBacktesterObject(); 
> >   bo.PreProcess(); // Initialize backtester 
> > 
> >   for(bar=0; bar<BarCount; bar++) 
> >   { 
> > 
> >    for( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal
> > (bar) ) 
> >     { 
> >        if( sig.IsEntry()) 
> >         { 
> > if (some_condition) // don't take trade
> > {
> > sig.PosSize = 0;
> > //sig.PosScore = 0;
> > _TRACE("No Trigger:" + ":" + 
> > sig.Symbol());
> > }
> >         } 
> >     }
> > 
> > 
> >    bo.ProcessTradeSignals(bar); // Process current bar's signals 
> > 
> >   } 
> > 
> >   bo.PostProcess(); 
> > } 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 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
> > 
> > 
> > 
> > 
> > 
> > 
> >
>




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