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#
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Human-readable strategy name shown in the platform UI. |
overlay | bool | False | True renders outputs on the price chart. False creates a separate sub-panel. |
process_orders_on_close | bool | False | Most practical timing flag in the current runtime. Use True for the vast majority of strategies. |
max_bars_back | int | 240 | Maximum lookback the strategy needs. Set high enough for the longest TA calculation. |
precision | int | 4 | Decimal 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.
| Parameter | Type | Description | Example file |
|---|---|---|---|
slippage | float | Fill realism — models spread or market impact on entries. | pynescript_slippage_strategy.py |
commission_type | str | Fee basis: "percent", "cash", or "cash_per_contract". | pynescript_commission_strategy.py |
commission_value | float | Fee amount, interpreted relative to commission_type. | pynescript_commission_strategy.py |
default_qty_type | str | "fixed" or "percent_of_equity" — controls how default_qty_value is interpreted. | pynescript_margin_strategy.py |
default_qty_value | float | Default position size when quantity and size_pct are not set per row. | pynescript_margin_strategy.py |
margin_long | float | Margin ratio for long positions as a decimal (e.g. 0.1 = 10% margin). | pynescript_margin_strategy.py |
margin_short | float | Margin ratio for short positions. | pynescript_margin_strategy.py |
pyramiding | int | Maximum number of add-on entries allowed in the same direction. Default 1. | pynescript_pyramiding_strategy.py |
backtest_fill_limits_assumption | bool | When 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: