strategy.default_entry_qty() - Pine Script Function
strategy.default_entry_qty()
Section titled “strategy.default_entry_qty()”Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”strategy.default_entry_qty(fill_price) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| fill_price | series int/float | The fill price for which to calculate the default order quantity. |
Remarks
Section titled “Remarks”- 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.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("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 offsetfor 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) > 0strategy.close_all()