Scale in or out 1 share in CBT

Hi,
I am using CBT in amibroker. I don't know how to sclale in 1 share to my open position (short or long).
I could't find any answer to this question online.

SetUp = IIf(BuyScale, 1, IIf(ShortScale, -1, 0));
StaticVarSet(Name() + "SetUp", SetUp);

//Custom Backtest.......

for	(Openpos = bo.getfirstopenpos(); Openpos; Openpos = bo.getnextopenpos())      
{		
	
	ScaleSetUp = StaticVarGet(openPos.Symbol + "SetUp");
	if (OpenPos.IsLong AND ScaleSetUp[bar] > 0) 
	{ 
		bo.ScaleTrade(bar, openPos.Symbol, openPos.IsLong(), pClose, ?1share);                  		        					
	}
	else if (!OpenPos.IsLong AND ScaleSetUp[bar] < 0) 
	{
		bo.ScaleTrade(bar, openPos.Symbol, openPos.IsLong(), pClose, ?1share);                  							
	}
}

The third parameter to bo.ScaleTrade() is a boolean indicating whether you want to scale in (true) or scale out (false). That's different than bo.EnterTrade(), where the third parameter indicates whether the trade is long or short.

To see the rules for encoding position sizes, see the documentation for the SetPositionSize function. There you will see that it says "values below -2000 encode share count". So if you want to scale in or out by one share, then you should use a position size of -2001.

Also, please make sure to verify your AmiBroker license.

1 Like