Variable RoundLotSize

Would it be possible to make a formula to vary the round lot size? What I was hoping to do, is have it set for 10 for share numbers less than 200 in the backtest. If it's over 200 shares I'd like it to have the round lot size at 100. So for example, if it called for 57.3 shares, it would round it off to 60 shares. If it wanted 257.3 shares, it would round it off to 300 shares.

If you want to make it dependent on number of shares and independent from position sizing method (e.g. if pos. size is n-percent of equity etc.) then you would have to do that via CBT (custom backtester).

On the other hand I have not tested these ones (which are not using CBT).

SetPositionSize( 201, spsShares );

RoundlotSize = IIf(PositionSize >= -2200 and PositionSize < -2000, 10, 100 );

// Buy Sell rules here 


// Buy Sell Short Cover rules here 

SetPositionSize( IIf( Buy, 300, /*Short*/ 200), spsShares );

RoundlotSize = IIf(PositionSize >= -2200 and PositionSize < -2000, 10, 100 );

Upper examples will work only if using spsShares.

Anyway doing it via CBT should work "for sure" for all position sizing methods.

As for rounding methods search the forum. AFAIK I have posted some functions already (not sure about other ones).


I'll typically set my position size as a percentage, not as fixed number of shares so I would have to resort to the CBT. It's not a problem for me to round it off manually. I was just thinking that other traders might be looking at it from the same perspective and had already figured out a way to do it in Amibroker. An odd lot order like 10 or 20 shares wouldn't matter for some high priced shares like Google or Amazon. However, it wouldn't make a lot of sense to place an order for for something like 1010 shares for a low priced stock, you would just round it off to 1000. Thank you so much fxshrat for looking at my question. Hope you have a Merry Christmas (or alternative Happy Holidays) and a Happy and Prosperous New Year!