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

[amibroker] Low Level CBT Executing Sales before Buys



PureBytes Links

Trading Reference Links

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(); 
}





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/