Skip to main content
ATK Pine Script®

Strategy Authoring Overview

How to build PyneScript strategies without leaking logic across stages. Covers stage split, canonical flow, and safe authoring patterns.

How to Build Strategies Without Leaking Logic Across Stages#

This handbook focuses on the most common PyneScript strategy mistakes in ATK: putting logic in the wrong stage, treating trade-frame fields as an afterthought, and sneaking MTF or risk calculations into build_trade_frame(...). The safe pattern is simple once the stage ownership is explicit.

Core ruleSignals first, mapping second
MTF rulerequest.security stays in signal stage
Risk ruleSL/TP/trailing are strategy intent
Starter examplesStrategy starter and MTF confirmation

Separate Strategy Thinking from Trade Mapping#

StageOwnsMust not do
build_signal_frameIndicators, filters, entries, exits, MTF context, canonical trade-frame fields.Defer strategy intent into later stages.
build_trade_frameThin normalization, usually build_mapped_trade_frame(signal_df) or equivalent canonical normalizer.Compute TA, call request.security, or invent stop/target/sizing logic.

Practical test: if you can explain your strategy only by reading build_signal_frame, the design is healthy. If the behavior is split across both builders, the contract is already drifting.

PyneScript Strategy to Backtest to Live: One Canonical Flow#

build_signal_frame(...)
  -> emit entry_* / sl / tp / trail_offset
  -> build_trade_frame(...) returns build_mapped_trade_frame(signal_df)
  -> normalize_strategy_trade_frame(...)
  -> execution core builds OrderIntent
  -> ExecutionPolicyEngine pre_trade_check(...)
  -> batch backtest / replay / live session submit path
  -> unified order primitives and reports

What is unified already#

The strategy layer uses one canonical trade-frame schema, one normalizer, and one execution-domain intent model before dispatch. That is the core contract shared by batch simulation, replay, and live signal execution.

What to keep explicit#

PyneScript strategy authors should target the canonical trade-frame schema first, not adapter-specific order factories. That keeps strategy code portable across backtest, replay, and live execution paths.