Skip to content
Algo Trade Analytics Docs

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.

Add these parameters to your strategy() declaration to align historical backtesting with real-time alerts.

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 true for strategies you intend to audit.
  • Why: Setting this to true forces 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.
  • 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 false unless your strategy specifically relies on intrabar pyramiding.

When building your alert_message, use the positionDirection field and include complete metadata for the highest reconciliation accuracy. Basic & Pro

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)
  • positionDirection: Use entryLong, exitLong, entryShort, or exitShort for explicit trade intent.
  • marketPrice: Always use str.tostring(close) to capture the exact price at the moment of the signal. This is the baseline for slippage calculation.
  • metadata.timestamp: Use str.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.

Before going live, verify your strategy’s Logic Stability without financial risk: All Plans

  1. Run the strategy on a 1-minute chart in TradingView.
  2. Set a webhook to the Hub.
  3. Let it run for 24 hours.
  4. Export the Strategy Tester CSV and compare it to your captured events in Backtest vs Alerts.
  5. A high match rate indicates stable logic. Low match rates suggest logical issues (repainting or lookahead) that must be fixed.