SHARES
SHARES in ProBacktest and ProOrder sizes an order as a number of shares for stock and CFD strategies. Covers syntax, unit choice and worked examples.
Syntax
[BUY|SELLSHORT] quantity SHARES [AT MARKET|AT price LIMIT|AT price STOP]How it works
SHARES names the unit that the order quantity is counted in. BUY 100 SHARES AT MARKET buys 100 shares at the next available price. The keyword follows the number and precedes the order type, whether that is AT MARKET, an AT price LIMIT, or an AT price STOP.
The sizing unit should match the instrument. SHARES fits stocks and share CFDs, CONTRACT fits futures and CFDs, and LOT fits forex. Choosing the wrong unit sizes the position incorrectly for that market. Whether repeated orders stack into a larger position is governed by CumulateOrders, exactly as with any other sizing unit.
Examples
Example 1, Short entry sized in shares (ProBacktest)
// Sell short one share when MACD crosses below zero and no short is open
myMACD = MACD[12,26,9](close)
shortCondition = myMACD CROSSES UNDER 0
IF NOT ShortOnMarket AND shortCondition THEN
SELLSHORT 1 SHARES AT MARKET
ENDIFThis is the pattern from the official reference. The order sells one share at market when the MACD histogram crosses below zero and there is no short position already open.
Example 2, Long entry with a fixed share count (ProOrder)
DEFPARAM CumulateOrders = false
// Buy 100 shares on a break above the 20-bar high
IF NOT LongOnMarket AND close CROSSES OVER Highest[20](high) THEN
BUY 100 SHARES AT MARKET
ENDIFThe position is a flat 100 shares each time the entry fires, with the position guard preventing a second entry while already long.
Example 3, Pending stop order sized in shares (ProOrder)
DEFPARAM CumulateOrders = false
// Rest a stop entry above the market for 50 shares
entryLevel = Highest[20](high)
IF NOT OnMarket THEN
BUY 50 SHARES AT entryLevel STOP
ENDIFThe pending stop order fills only if price trades up through the 20-bar high, buying 50 shares at that level.
Common errors and gotchas
- Wrong unit for the market.
SHARESon a forex pair or a futures contract does not size the order as intended. UseCONTRACTfor futures and CFDs andLOTfor forex. - Fractional shares. Broker rules decide whether a fractional share quantity is accepted. A whole number is the safe choice for most instruments.
- Unintended stacking.
CumulateOrdersis enabled by default, so an entry that stays true over several bars adds shares on each of them. SetDEFPARAM CumulateOrders = falseor guard withNOT LongOnMarket. - Unit only, not the whole order.
SHARESis one part of an order line. It always follows a quantity and sits inside aBUYorSELLSHORTstatement with an order type.
Related instructions
CONTRACT, quantity unit for futures and CFDs.LOT, quantity unit for forex.BUY, opens a long position sized in a chosen unit.SELLSHORT, opens a short position sized in a chosen unit.SELL, closes a long position.EXITSHORT, closes a short position.MARKET,LIMIT,STOP, the order types a share-sized order can use.
