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

[amibroker] Re: Hedging with PositionScore?



PureBytes Links

Trading Reference Links

Question for Ed (nl) who created the code below in 03/2005, or of 
course anybody else who cares to jump in.

Is there any reason why I cannot seem to get, in the GetFirstSignal-
loop, the values from a VarSet which I defined previously in the 
GetFirstOpenPos-loop. Your code below shows that the "cntlongopen" 
variable, defined in the 1st loop, can be called later in the 2nd 
loop.

For all clarity, I need to make a link between stock-specific 
variables between these loops. In other words, I use VarSet 
("Var1"+openpos.Symbol, var1) in order to retrieve it in the 2nd loop 
via VarGet("Var1"+sig.Symbol). So far, this doesn't work.

For context, and as mentioned in some of my previous mails, I'm 
trying to code a fairly simple (I thought) rebalancing strategy, this 
time without the rotational trading bit. Any help appreciated.

Thx,

PS 

--- In amibroker@xxxxxxxxxxxxxxx, "ed nl" <ed2000nl@xxx> wrote:
>
> Herman,
> 
> I expanded the code a little. Now you can set maxShort is well. The 
nice thing about this is that you will only go full inside the margin 
with mixed long and short positions and not just either long or short,
> 
> 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: Herman van den Bergen 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Tuesday, March 01, 2005 11:59 AM
>   Subject: RE: [amibroker] Hedging with PositionScore?
> 
> 
>   Thank you Ed, will try that!
> 
>   herman
>     -----Original Message-----
>     From: ed nl [mailto:ed2000nl@...]
>     Sent: Tuesday, March 01, 2005 2:42 AM
>     To: amibroker@xxxxxxxxxxxxxxx
>     Subject: Re: [amibroker] Hedging with PositionScore?
> 
> 
>     I think I answered my own question in case you are interested. 
It seems to work.
> 
>     rgds, Ed
> 
> 
>     /* 
> 
>     Number of positions: do not allow more than "maxLong" LONG 
positions 
> 
>     */ 
> 
>     SetCustomBacktestProc(""); 
> 
>     maxLong = 7; 
> 
>     if( Status("action") == actionPortfolio ) { 
> 
>        bo = GetBacktesterObject(); 
>        bo.PreProcess(); 
>         
>        for( i = 0; i < BarCount; i++ ) { 
>         
>         
>           cntLongOpen = 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; 
>                  
>              } 
>            
>           } 
>         
>         
>           // 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; 
>                     
>                  
>                 } 
>                  
>               
>              } 
>            
>           } 
> 
>           bo.ProcessTradeSignals( i ); 
>        } 
> 
>        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 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/