HomePine Script Snippets › Drawdown Tracker

Pine Script Drawdown Tracker

Tracks peak strategy equity and blocks new entries when trailing drawdown approaches your prop firm’s limit.

//@version=6
strategy("Drawdown Tracker", overlay=true, calc_on_every_tick=false)

// ── Inputs ──────────────────────────────────────────────
ddLimit = input.float(2000.0, "Trailing Drawdown Limit ($)", step=100,
     tooltip="Block new entries when drawdown from peak equity reaches this. Set below your firm's hard limit.")

// ── Peak equity tracking ─────────────────────────────────
var float peakEq = strategy.equity
peakEq := math.max(peakEq, strategy.equity)
dd = peakEq - strategy.equity

lockActive = dd >= ddLimit

// ── Entry logic (replace with your own conditions) ───────
longCondition  = ta.crossover(ta.ema(close, 9), ta.ema(close, 21)) and not lockActive
shortCondition = ta.crossunder(ta.ema(close, 9), ta.ema(close, 21)) and not lockActive

if longCondition
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", profit=20, loss=10)

if shortCondition
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short", profit=20, loss=10)

// Visuals
bgcolor(lockActive ? color.new(color.red, 88) : na, title="DD Lock Active")
plot(dd, "Drawdown ($)", display=display.data_window)

Settings

How to use

Frequently Asked Questions

How do I track drawdown in Pine Script?

Keep a persistent var of peak strategy.equity, update it with math.max on every bar, and subtract current equity from the peak. That difference is your trailing drawdown in dollars. Compare it against a limit input to gate entries or fire an alert.

What is trailing drawdown for prop firms?

Trailing drawdown is a loss limit that follows your equity peak upward instead of staying fixed at the starting balance. On an Apex 50k the limit trails $2,500 behind peak equity until it locks at breakeven plus $100. Because it ratchets up with every new high, one bad run right after a good one can breach it — check the rules database for each firm’s exact numbers.

Related

Want a complete eval-ready strategy that respects trailing drawdown?

This snippet is a building block. Our paid scripts are complete strategies — entries, drawdown guards, kill switch, session filter, and EOD flatten tested on 3 years of MES/NQ data. Instant delivery from $50.

View Plans — From $50