Skip to main content
ATK Pine Script®

strategy() Parameter Reference

Reference for all strategy() declaration parameters in ATK PyneScript V6 — overlay, process_orders_on_close, slippage, commission, margin, pyramiding, and more.

strategy() Declaration#

The strategy() call declares that the module is an execution script. It registers the script name, sets runtime flags, and controls backtest realism parameters.

from source import strategy

strategy(
    "My Strategy Name",
    overlay=True,
    process_orders_on_close=True,
    max_bars_back=240,
)

Core Parameters#

ParameterTypeDefaultDescription
titlestrrequiredHuman-readable strategy name shown in the platform UI.
overlayboolFalseTrue renders outputs on the price chart. False creates a separate sub-panel.
process_orders_on_closeboolFalseMost practical timing flag in the current runtime. Use True for the vast majority of strategies.
max_bars_backint240Maximum lookback the strategy needs. Set high enough for the longest TA calculation.
precisionint4Decimal precision used in the platform display.

Execution Realism Parameters#

These parameters control backtest simulation accuracy. Each has a dedicated example script to keep the teaching focused.

ParameterTypeDescriptionExample file
slippagefloatFill realism — models spread or market impact on entries.pynescript_slippage_strategy.py
commission_typestrFee basis: "percent", "cash", or "cash_per_contract".pynescript_commission_strategy.py
commission_valuefloatFee amount, interpreted relative to commission_type.pynescript_commission_strategy.py
default_qty_typestr"fixed" or "percent_of_equity" — controls how default_qty_value is interpreted.pynescript_margin_strategy.py
default_qty_valuefloatDefault position size when quantity and size_pct are not set per row.pynescript_margin_strategy.py
margin_longfloatMargin ratio for long positions as a decimal (e.g. 0.1 = 10% margin).pynescript_margin_strategy.py
margin_shortfloatMargin ratio for short positions.pynescript_margin_strategy.py
pyramidingintMaximum number of add-on entries allowed in the same direction. Default 1.pynescript_pyramiding_strategy.py
backtest_fill_limits_assumptionboolWhen True, assumes limit orders fill at the limit price during backtesting.pynescript_limit_fill_assumption_strategy.py

Execution Realism Examples#

Slippage#

from source import strategy

strategy("Slippage Demo", overlay=True, process_orders_on_close=True, slippage=0.5)

Commission#

strategy(
    "Commission Demo",
    overlay=True,
    process_orders_on_close=True,
    commission_type="percent",
    commission_value=0.05,
)

Margin and Percent Sizing#

strategy(
    "Margin Demo",
    overlay=True,
    process_orders_on_close=True,
    default_qty_type="percent_of_equity",
    default_qty_value=10.0,
    margin_long=0.1,
    margin_short=0.1,
)

Pyramiding#

strategy(
    "Pyramiding Demo",
    overlay=True,
    process_orders_on_close=True,
    pyramiding=3,
)

Execution realism lives in the declaration too. Treat slippage, commission_type, commission_value, margin_long, margin_short, pyramiding, and backtest_fill_limits_assumption as real authoring features, not hidden runtime flags.

strategy_alert_message()#

Registers a template string for strategy alerts. Uses {{...}} tokens that the ATK alert dispatch surface substitutes at runtime.

from source import strategy, strategy_alert_message

strategy("Alert Template Strategy", overlay=True, process_orders_on_close=True)
strategy_alert_message("{{ticker}} {{strategy.order.id}} {{strategy.order.action}}")

Per-row alert text is set via the alert_message column in build_signal_frame:

frame["alert_message"] = np.where(buy_signal | sell_signal, "ema crossover fired", "")

Download strategy alert template example

See also: