Skip to content
Algo Trade Analytics Docs

strategy.default_entry_qty() - Pine Script Function

Calculates the default quantity, in units, of an entry order from strategy.entry or strategy.order if it were to fill at the specified fill_price value. The calculation depends on several strategy properties, including default_qty_type, default_qty_value, currency, and other parameters in the strategy function and their representation in the “Properties” tab of the strategy’s settings.

strategy.default_entry_qty(fill_price) → series float
NameTypeDescription
fill_priceseries int/floatThe fill price for which to calculate the default order quantity.
  • This function does not consider open positions simulated by a strategy. For example, if a strategy script has an open position from a long order with a qty of 10 units, using the strategy.entry function to simulate a short order with a qty of 5 will prompt the script to sell 15 units to reverse the position. This function will still return 5 in such a case since it doesn’t consider an open trade.
//@version=6
strategy("Supertrend Strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 15)//@variable The length of the ATR calculation.atrPeriod = input(10, "ATR Length")//@variable The ATR multiplier.factor = input.float(3.0, "Factor", step = 0.01)//@variable The tick offset of the stop order.stopOffsetInput = input.int(100, "Tick offset
for entry stop")// Get the direction of the SuperTrend.[_, direction] =
ta.supertrend(factor, atrPeriod)
if ta.change(direction) < 0 //@variable The stop price of the entry order. stopPrice = close + syminfo.mintick * stopOffsetInput //@variable The expected default fill quantity at the `stopPrice`. This value may not reflect actual qty of the filled order, because fill price may be different. calculatedQty =
strategy.default_entry_qty(stopPrice)
strategy.entry("My Long Entry Id", strategy.long, stop = stopPrice)
label.new(bar_index, stopPrice, str.format("Stop set at {0}\nExpected qty at {0}: {1}", math.round_to_mintick(stopPrice), calculatedQty))
if ta.change(direction) > 0
strategy.close_all()