When scaling out, I am trying to exit the same number of shares as my last entry and/or scale-in. I am real close, but off by just a little. Here is my CBT code:

```
dn = DateNum();
tn = TimeNum();
dt=DateTime();
doTrace = 1;
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.PreProcess();
for ( i = 0; i < BarCount; i++ )
{
if ( i == 0 )
{
LastEntryShares = 0;
}
if ( i > 0 )
{
dn_tn = NumToStr(dn[i], 1.0, False, False) + "_" + NumToStr(tn[i], 1.0, False, False);
dn_tn_i = "DT: " + dn_tn + " i: " + NumToStr(i,1.0, True, False) + " ||||| " ;
for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
{
tmpPrc = sig.Price;
if (doTrace) { _TRACE(dn_tn_i + " tmpPrc: " + NumToStr(tmpPrc, 1.2)); }
if (sig.IsLong() AND NOT sig.Type == 2 AND NOT sig.Type == 6 )
{
psize = sig.PosSize;
if (psize < 0)
psize = (-psize/100) * bo.Equity;
LastEntryShares = psize / tmpPrc;
StaticVarSet ( "LastEntryShares" + sig.Symbol, LastEntryShares);
if (doTrace) { _TRACE(dn_tn_i + " !!!!!!!!! En ---LastEntryShares: " + NumToStr(LastEntryShares, 1.4) + " Equity: " + NumToStr(bo.Equity, 1.6) + " psize: " + NumToStr(psize, 1.2) + " sig.Price: " + NumToStr(tmpPrc, 1.2) + " sig.Type: " + NumToStr(sig.Type, 1.0) ); }
}
if (sig.Type == 6) // If this signal is a scale-out exit
{
LastEntryShares = StaticVarGet ( "LastEntryShares" + sig.Symbol);
if (doTrace) { _TRACE(dn_tn_i + " Ex ---LastEntryShares: " + NumToStr(LastEntryShares, 1.4)); }
sig.PosSize = LastEntryShares * tmpPrc; // Set modified position size back into object
}
}
}
bo.ProcessTradeSignals( i );
}
bo.PostProcess();
}
```

I have set positions sizing to 5% per entry and/or scale-in. With the given example here, I calculate the number of shares to enter at 33.6198, but AB is entering 33.62014 shares. Why? I do not have AllowPositionSizeShrinking on. You can see that I am calculating the number of shares traded like this:

LastEntryShares = psize / sig.Price;

But that gives me 33.6198 shares, not what the detailed report is showing at 33.62014.

Also if I do the math from my print statements:

Equity: 121878.382813 * 5% = $6093.92 to trade, divided by price of 181.26 = 33.6198 shares.

Why would AB say that we entered 33.62014 shares when all calculations return 33.6198?