Pine Script Daily Kill Switch for Prop Firms
Tracks session P&L and blocks new entries once losses reach a configured threshold — the single most important safety mechanism in an automated prop firm strategy.
//@version=5
strategy("Target Filled - Daily Kill Switch Example", overlay=true)
// --- Inputs ---------------------------------------------------
lossLimit = input.float(-800.0, "Daily Loss Limit ($)", step=50,
tooltip="New entries stop once session P&L hits this level. Set to roughly 80% of your firm's daily limit.")
// --- State ------------------------------------------------------
var float pnlToday = 0.0
var bool locked = false
// Reset at the start of each regular session
if session.isfirstbar_regular
pnlToday := 0.0
locked := false
// Add each closed trade's result into the running session total
if strategy.closedtrades > strategy.closedtrades[1]
pnlToday += strategy.closedtrades.profit(strategy.closedtrades - 1)
// Trip the switch once the threshold is breached
if pnlToday <= lossLimit
locked := true
// --- Sample signal — replace with your own entry logic ---------
fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)
canLong = ta.crossover(fastMA, slowMA) and not locked
canShort = ta.crossunder(fastMA, slowMA) and not locked
if canLong
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", profit=20, loss=10)
if canShort
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", profit=20, loss=10)
// Visual: red background confirms the switch is tripped
bgcolor(locked ? color.new(color.red, 90) : na, title="Kill Switch Active") How it works
The snippet keeps two values alive across bars with Pine's var keyword: pnlToday, a running total of closed-trade profit and loss for the session, and locked, a boolean that gates both entry conditions.
Every time a trade closes — spotted by comparing strategy.closedtrades to its previous-bar value — that trade's result gets added into pnlToday. Once the running total drops to or past lossLimit, locked flips to true, and from that point neither the long nor the short condition can fire for the rest of the session.
The background shading turns red the moment the switch trips, so there's an unmissable visual cue on the chart that no further entries are coming that day.
How to configure it for your firm
A workable rule of thumb is setting lossLimit to about 80% of whatever your firm's stated daily loss cap is. That leaves a buffer for slippage or an open position that hasn't fully closed out yet before the hard floor gets touched.
| Firm / Account | Daily Limit | Suggested Setting |
|---|---|---|
| Topstep 50k Eval | $1,000 | -$800 |
| Topstep 100k Eval | $2,000 | -$1,600 |
| FTMO $10k | $500 | -$400 |
| FTMO $100k | $5,000 | -$4,000 |
| MyFundedFutures 50k | $1,250 | -$1,000 |
| Apex (any size) | No hard daily limit | -$800 on a 50k (personal guardrail) |