TJ may possibly correct me on this (if so, than hopefully with 
example code), but as far as I know you cannot (if that is your 
intention) prioritize the sales/shorts to be executed first(in a 
seperate loop as it were, and thereby generate cash) before you 
execute the buys/longs.

PS
--- In [email protected], "tipequity" <[EMAIL PROTECTED]> wrote:
>
> Can someone point out a way that the code below would execute sales 
> before buys. TIA Cam
> 
> SetBacktestMode( backtestRegularRaw ); 
> SetCustomBacktestProc(""); 
> MaxBuys = 3; 
> if( Status("action") == actionPortfolio )
> { 
>       bo = GetBacktesterObject(); 
>       bo.PreProcess(); 
>       MaxHoldingPer = 14;
>       TradeDate = DateTime(); 
>    for( i = 0; i < BarCount; i++ ) 
>   { 
>       cntBuys = 0; 
>               for( OP = bo.GetFirstOpenPos(); OP; OP = 
> bo.GetNextOpenPos() )
>               { 
>                       if ( OP.BarsInTrade >= MaxHoldingPer) 
>                               bo.ExitTrade( i, OP.Symbol, 
> OP.GetPrice(i, "C"), 1);
>               }
>               for( sig = bo.GetFirstSignal(i); sig; sig = 
> bo.GetNextSignal(i) )
>               { 
>                       OpenPos = bo.FindOpenPos( sig.Symbol );
> 
>                       if( Sig.IsExit() AND OpenPos )
>                       {
>                               bo.ExitTrade( i, OpenPos.symbol, 
> sig.Price, 1); 
>                                       bo.RawTextOutput(
>       DateTimeToStr(TradeDate[ i ])+ " Sell "+sig.symbol()+" 
> Cash "+bo.cash); 
>                       }
>               // look at new signals AND Exclude signals if they 
> exceed maxBuys 
>                       if( sig.IsEntry() ) 
>                       { 
>                                       bo.RawTextOutput(
>       DateTimeToStr(TradeDate[ i ])+ " BuySig "+sig.symbol()+" 
> Cash "+bo.cash); 
>                               if( cntBuys > MaxBuys )
>                               {   
>                                       bo.RawTextOutput(
>       DateTimeToStr(TradeDate[ i ])+ " Rejected BuySig "+sig.symbol
> ()); 
> 
>                               } 
>                               else if( IsNull(OpenPos))
>                               { 
>                                       bo.RawTextOutput(
>       DateTimeToStr(TradeDate[ i ])+ " Buy "+sig.symbol()+" 
> Cash "+bo.cash); 
>                                       cntBuys = cntBuys + 1;
>                                       bo.EnterTrade( i, sig.Symbol, 
> True, sig.Price, sig.PosSize, sig.PosScore, RoundLotSize = 1);
>                                       bo.RawTextOutput(
>       DateTimeToStr(TradeDate[ i ])+ " Buy2 "+sig.symbol()+" 
> Cash "+bo.cash); 
>                               } 
>                       } 
>               } 
>               bo.HandleStops(i);
>               bo.UpdateStats(i,1);
>               bo.UpdateStats(i,2);
>         } 
>    bo.PostProcess(); 
> }
>


Reply via email to