Skip to content

Strategy Configuration Guide

The #1 frustration: Your TradingView backtest shows 20% returns, but live trading barely breaks even.

This guide explains exactly why this happens and how to configure your PineScript strategies to minimize the gap between backtesting and live execution.

Backtesting engines make several assumptions that don’t match real trading:

  • Perfect fills at exact signal prices
  • Zero slippage and execution delays
  • Instant execution at bar close
  • No network latency or platform delays
  • Perfect timing with no human errors

Live trading introduces reality:

  • Slippage: Price moves between signal and fill
  • Latency: Network and platform delays
  • Partial fills: Orders may not fill completely
  • Market gaps: Price jumps over stop levels
  • Human factors: Manual intervention and errors

Most Important Configuration for Live Trading

//@version=5
strategy("My Strategy", overlay=true, calc_on_every_tick=true)
  • false (default): Strategy calculates only on bar close
  • true: Strategy calculates on every price tick

With calc_on_every_tick=false:

  • ✅ Faster backtesting
  • ✅ Cleaner signals
  • Signals only at bar close (major execution delay)
  • Missed intrabar opportunities
  • Poor fill prices due to delay

With calc_on_every_tick=true:

  • Real-time signals as price moves
  • Better fill prices
  • Matches live alert behavior
  • ❌ Slower backtesting
  • ❌ More noisy signals

Always use calc_on_every_tick=true for strategies you plan to trade live.

strategy("My Strategy", overlay=true, process_orders_on_close=true)
  • false (default): Orders processed when signal occurs
  • true: Orders processed at bar close only

Use process_orders_on_close=false to match real-time alert behavior.

Location: Chart settings → Symbol → Enable “Magnifier”

  • Enabled: Uses higher resolution data for calculations
  • Disabled: Uses chart timeframe only
  • Enabled: More accurate intrabar calculations
  • Disabled: May miss important price action

Enable magnifier for strategies that depend on intrabar price action.

// ❌ BAD: Signal only at bar close
if ta.crossover(fast_ma, slow_ma)
strategy.entry("Long", strategy.long)
// ✅ GOOD: Real-time signal detection
longCondition = ta.crossover(fast_ma, slow_ma)
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
// Send immediate alert for live trading
alert("BUY signal at " + str.tostring(close))
// ❌ BAD: Assumes perfect stop loss execution
strategy.exit("Exit", "Long", stop=low[1])
// ✅ GOOD: Account for slippage and gaps
stopPrice = strategy.position_avg_price * 0.98 // 2% stop loss
strategy.exit("Exit", "Long", stop=stopPrice)
// ❌ BAD: Fixed position size
strategy.entry("Long", strategy.long, qty=1000)
// ✅ GOOD: Risk-based position sizing
riskAmount = strategy.equity * 0.02 // Risk 2% of equity
stopDistance = close - stopPrice
positionSize = riskAmount / stopDistance
strategy.entry("Long", strategy.long, qty=positionSize)

Before going live:

  1. Enable paper trading in TradingView
  2. Run strategy for 2-4 weeks minimum
  3. Compare paper results with backtest
  4. Identify discrepancies and adjust

Test your alerts thoroughly:

  • Alert timing: Do alerts fire when expected?
  • Alert accuracy: Do prices match your calculations?
  • Alert frequency: No duplicate or missing alerts?
  • Network reliability: Consistent alert delivery?

3. Algo Trade Analytics Validation Process

Section titled “3. Algo Trade Analytics Validation Process”

Use Algo Trade Analytics to validate your setup:

  1. Import signals via CSV or webhook
  2. Compare with paper trading results
  3. Identify execution gaps
  4. Adjust strategy settings
  5. Re-test and validate

Problem: Default PineScript settings optimize for backtesting, not live trading Solution: Always configure for live execution

Problem: Backtests assume perfect fills Solution: Add realistic slippage to your strategy

// Add slippage simulation
strategy.entry("Long", strategy.long, qty=qty, comment="Long Entry")
// Simulate 0.1% slippage
strategy.exit("Exit", "Long", limit=strategy.position_avg_price * 1.001)

Problem: Curve-fitting to historical data Solution: Use out-of-sample testing

Problem: Signals outside trading hours can’t be executed Solution: Add market hour filters

// Only trade during market hours
inMarketHours = time(timeframe.period, "0930-1600:1234567")
if longCondition and inMarketHours
strategy.entry("Long", strategy.long)

Understanding the difference:

  • Backtest: Uses final bar close price
  • Live: May execute anywhere within the bar

Solution: Test with realistic fill assumptions

// Simulate realistic fill price (not exact close)
fillPrice = close + (high - low) * 0.1 // Assume 10% slippage from close

Special considerations:

  • Data alignment: Ensure timeframes sync properly
  • Signal timing: Higher timeframes may lag
  • Execution timing: Use shortest timeframe for entries

High volatility periods:

  • Increased slippage risk
  • Faster price movements
  • Higher gap risk

Low volatility periods:

  • Slower fills
  • Reduced profit targets
  • Extended consolidation

Using Algo Trade Analytics, monitor:

  1. Signal-to-Execution Lag: Time between signal and fill
  2. Price Slippage: Difference between signal price and fill price
  3. Missed Signals: Signals that didn’t result in trades
  4. Execution Rate: Percentage of successful signal executions

Compare these metrics between:

  • Backtest results
  • Paper trading results
  • Live trading results
  1. Identify gaps in Algo Trade Analytics
  2. Adjust PineScript settings
  3. Re-test in paper trading
  4. Validate with Algo Trade Analytics
  5. Implement in live trading

Configure your strategy to export detailed signals:

if longCondition
strategy.entry("Long", strategy.long)
// Export for Algo Trade Analytics analysis
alert('{"action":"BUY","price":' + str.tostring(close) + ',"time":"' + str.tostring(time) + '","confidence":' + str.tostring(rsi) + '}')

Use Algo Trade Analytics to:

  • Import your signals (CSV or webhook)
  • Compare with actual executions
  • Identify configuration issues
  • Optimize for live performance

Regular validation cycle:

  1. Weekly: Review signal vs execution performance
  2. Monthly: Adjust strategy parameters
  3. Quarterly: Major strategy configuration review