Category
Strategy Elements
Description
Specifies the number of shares or contracts to buy or sell when ExitRule is true
Input
Any formula specifying a number of shares or contracts
Notes
ExitQty can be used to model partial exits (scaling out of positions or reducing their size).
If ExitQty is not specified then then entire position is always exited when ExitRule is true.
The ExitQty formula must calculate the number of shares or contracts to exit regardless of the strategy's QtyType setting.
To model partial exits for the other exit types, ExitLimitQty and/or ExitStopQty can also be added to a strategy.
If the specified quantity is less than or equal to 0 then the exit is cancelled (the position is held at its current size).
If the quantity is greater than or equal to the current position size then the entire position is exited.
Use FillQty in these formulas to express the partial exit in terms of the original position size.
For example to exit one fourth of the original position on each of the first four days after entry:
This use of FillQty rather than Shares is necessary because Shares will be reduced after each partial exit.
Partial exits are implemented internally by temporarily cloning the position, changing the clone's quantity to the desired exit quantity, and then processing the exit of that new position. The quantity of the original position (Shares) is then changed to the prior quantity minus the exit quantity.
When looking at the trade list of a strategy that uses partial exits, none of the trades will show the original entry quantity as their QtyIn values. Instead QtyIn is always equal to QtyOut (the partial exit quantity) for each individual trade (unless it was held across a split).
To see the original entry quantities in the trade list, add this to the strategy:
and add this to Trades.rts:
