← Back to Insights

The Time Traveler's Delusion: Automating Honest Backtests

2025-12-15

The easiest person to fool is yourself.

In trading, this manifests as Confirmation Bias. You look at a historical chart, point to a bottom, and say, "I would have bought there." No, you wouldn't have. You would have been scared.

Or worse, you engage in Overfitting. You take an indicator, tweak the settings to 14, 3, 5 until the past performance looks perfect. You have created a strategy that perfectly predicts the past. Unfortunately, you cannot trade the past.

When you take this "perfect" strategy to the live market, it fails immediately. Why? Because you didn't find an edge; you found noise. You tailored a suit for a mannequin, and now you are trying to wear it to play rugby.

The Mirror That Doesn't Lie

To survive, you need to destroy your ego. You need a mirror that shows you the ugly truth. That mirror is the Backtest Engine.

We do not use Pine Script just to draw lines; we use it to simulate PnL (Profit and Loss). But a backtest is only useful if it is rigorous. A backtest without Commission and Slippage is a video game, not a simulation.

The Logic: Strategy vs. Study

In TradingView, you must switch from indicator() to strategy(). This unlocks the "Strategy Tester" panel—the most important panel in your career.

We look for three metrics:

  1. Net Profit: obviously.
  2. Max Drawdown: The pain threshold. Can you survive a 20% dip?
  3. Profit Factor: Gross Profit / Gross Loss. If it's below 1.5, it's trash.

The Code: Pine Script v6 Strategy Template

This script acts as a reality check. It includes fees (0.05% per trade), which usually kills most scalping strategies.

//@version=6
strategy("Codon: Truth Serum Backtest", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05)

// --- Settings ---
int emaLen = input.int(50, "Trend Filter")
float tpPercent = input.float(3.0, "Take Profit %")
float slPercent = input.float(1.5, "Stop Loss %")

// --- Logic (Example: Pullback) ---
float ema = ta.ema(close, emaLen)
bool trendUp = close > ema
bool pullback = close[1] > close and close < high[1] // Simple red candle

// Entry
if trendUp and pullback
    strategy.entry("Long", strategy.long)

// Exit (Hard Exits are better for testing than dynamic ones)
strategy.exit("Exit Long", "Long", profit=close * (tpPercent/100), loss=close * (slPercent/100))

// --- Visualization ---
plot(ema, color=color.blue)

The Automation Layer (Paper Trading)

Once your code shows a profit factor > 1.5 over at least 100 trades, you are halfway there. The next step is Forward Testing.

Past data is static. Live data is chaotic. We use 3Commas Paper Trading accounts for this.

  1. Deploy: Connect your TradingView Strategy Alert to a 3Commas Paper Account.
  2. Run: Let it run for 2 weeks.
  3. Compare: Does the 3Commas Paper PnL match the TradingView Backtest PnL?

If they match, you have a robust system. If they don't, you were overfitting.

Most traders skip this step. They rush to put real money on a unproven theory. They pay the "Tuition Fee" to the market. Be smart. Pay the tuition fee in simulation, not in liquidation.

(Check the footer for the 3Commas Paper Trading setup)