RealTest User Guide
RealTest User Guide

 

 

Navigation: Realtest Script Language > Syntax Element Details >

DynamicSizing

 

 

 

 

Category

Strategy Elements

Description

Determines whether strategy operates in a special dynamic sizing mode

Choices

True - use dynamic sizing mode

False - use typical entry/exit formula mode (default)

Notes

If DynamicSizing is set to True then most of the typical strategy formulas become disabled and the Quantity formula determines whether a new position or partial position is entered or exited each day.

In this mode the following elements are disallowed: EntrySetup, EntryLimit, EntryStop, EntryScore, ExitRule, ExitQty, ExitLimitQty, ExitStopQty, ExitScore, MaxSameSym, MaxSameCat, MaxSetups, MaxEntries, Side.

EntryTime and ExitTime can be specified but must be the same. The default NextOpen makes most sense in this mode, so it is recommended to not specify them.

Instead of the logic provided by all of the above elements, the backtest engine simple evaluates Quantity once per test period. The value returned is the "target position size" for that period.

If the target size is larger than the current size, an entry is made for the difference.

If the target size is smaller than the current size, an exit is made for the difference.

The sign of the quantity determines the side (long vs. short) of the position to establish.

If the prior position was the opposite side, all current positions are exited and then the new position is entered.

Internally RealTest implements this functionality using multiple positions per symbol, similar to the older way of simulating dynamic sizing.

The key differences are:

Quantity is simply the desired position rather than having to calculate the difference vs. current position

EntrySetup is implicitly True when quantity is larger than current position

MaxSameSym is implicitly infinite

ExitRule is implicitly true when quantity is smaller than current position

ExitScore is implicitly "-Shares" i.e. always exit the smallest sub-positions first

Shares are implicitly Extern(@thisStrat, Shares), i.e., combined quantity of all sub-positions in this strategy for this symbol

there is no way to access individual sub-positions from strategy formulas though they are still evident in the trade list, log, and orders

DynamicSizing strategies can specify any desired QtyType and, as usual, should express their target quantities in that type.

The Quantity formula is by far the most important strategy formula in this mode. The Select function can be useful to make the typically complex Quantity formula more manageable.

Note that unlike normal strategy mode, where Quantity: 0 means "no entry", in dynamic mode this means "exit any open position" (go flat).

To specify "no change" in the current position, the Quantity formula should return the constant nan, for example:

Quantity: Select(C > BBTop(20,2), 100, C < BBBot(20,2), -100, nan)

This says "go or stay long 100 when above the upper band, go or stay short 100 when below the lower band, otherwise don't change the position."

Dynamic-sizing strategies can specify any of the usual capacity constraints except for those that constrain position counts. Top-down setup selection logic works as usual, including when adding to positions.

See the two example scripts clenow_stocks_on_move.rts and clenow_stocks_on_move_dynamic.rts. These implement the same strategy logic using (a) the older approach and (b) dynamic sizing mode.


As of RealTest 2.0.31, ExitLimit and ExitStop are also allowed in dynamic-sizing mode, but ExitLimitTime and ExitStopTime are NOT allowed, i.e., these must be live intraday limit and/or stop orders.

When ExitLimit or ExitStop is used, they are evaluated separately for each sub-position.

Use Extern(@strat_name, FillPrice) in these formulas to calculate your limit or stop prices relative to the average fill price of the entire position, or just use FillPrice if you want different limit or stop prices for each sub-position.

 

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC