Strategy Best Practices
To achieve a high match rate and precise slippage data, your Pine Script strategy should be optimized for real-world signal generation.
Supported Trade Types
Section titled “Supported Trade Types”Critical Settings
Section titled “Critical Settings”Add these parameters to your strategy() declaration to align historical backtesting with real-time alerts.
1. calc_on_every_tick=true
Section titled “1. calc_on_every_tick=true”By default, strategies only calculate at the close of a bar.
- Why: Live alerts fire intrabar. If this is
false, your backtest will assume perfect entry at the close, while your real signal might fire mid-candle, creating artificial “slippage.” - Action: Always set to
truefor strategies you intend to audit.
2. process_orders_on_close=false
Section titled “2. process_orders_on_close=false”- Why: Setting this to
trueforces backtest entries to the next bar open, which rarely matches real-time alert behavior. - Action: Leave at
false(default) to ensure signals are recorded the moment conditions are met.
3. calc_on_order_fills=false
Section titled “3. calc_on_order_fills=false”- Why: This setting forces the strategy to recalculate logic immediately after an order is filled intrabar. While precise, it can cause “repainting” where a signal appears and disappears within the same bar in backtesting, but fires permanently in real-time.
- Action: Generally keep this
falseunless your strategy specifically relies on intrabar pyramiding.
High-Fidelity Signal Integration
Section titled “High-Fidelity Signal Integration”When building your alert_message, use the positionDirection field and include complete metadata for the highest reconciliation accuracy. Basic & Pro
Recommended Entry Template
Section titled “Recommended Entry Template”longMessage = '{"auth_key":"YOUR_KEY","ticker":"' + syminfo.ticker + '","positionDirection":"entryLong","orderType":"market","marketPrice":' + str.tostring(close) + ',"qty":10,"metadata":{"timestamp":"' + str.tostring(time) + '","strategy":"My Strategy","signal":"Entry Signal"}}'
if longCondition strategy.entry("Long", strategy.long, alert_message=longMessage)Important Fields
Section titled “Important Fields”positionDirection: UseentryLong,exitLong,entryShort, orexitShortfor explicit trade intent.marketPrice: Always usestr.tostring(close)to capture the exact price at the moment of the signal. This is the baseline for slippage calculation.metadata.timestamp: Usestr.tostring(time)to help the AI reconcile latency gaps.metadata.strategy: Include your strategy name for grouping and reporting.metadata.signal: Describe the specific signal type for detailed analytics.
Testing for “Alert Stability”
Section titled “Testing for “Alert Stability””Before going live, verify your strategy’s Logic Stability without financial risk: All Plans
- Run the strategy on a 1-minute chart in TradingView.
- Set a webhook to the Hub.
- Let it run for 24 hours.
- Export the Strategy Tester CSV and compare it to your captured events in Backtest vs Alerts.
- A high match rate indicates stable logic. Low match rates suggest logical issues (repainting or lookahead) that must be fixed.