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.

Pine Script v5 Free · TradingView free plan
Pine Script
//@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 / AccountDaily LimitSuggested 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)
Apex is the exception. Trader Funding doesn't enforce a hard daily loss limit at any size — risk is managed through the overall trailing drawdown instead. Setting a personal kill switch anyway is still good practice; -$800 on a 50k account is a reasonable starting point.

Frequently Asked Questions

What is a kill switch in Pine Script?
It is a block of code that keeps a running total of closed-trade P&L for the session and flips a boolean once losses cross a threshold you set. Every entry condition checks that flag, so once it trips, the strategy stops opening new positions — the single most important safety mechanism for any automated strategy running on a funded account.
Does Apex have a daily loss limit?
No — Apex Trader Funding does not enforce a hard daily loss limit at any account size; risk is controlled through the overall trailing drawdown instead. That said, running a personal kill switch around -$800 on a 50k account is still a reasonable guardrail even when the firm itself doesn't require one.
How does the kill switch reset each day?
It watches session.isfirstbar_regular to catch the first bar of each new regular session. At that moment it zeroes out the running P&L total and clears the locked flag, so the strategy is free to take entries again from the start of the next trading day.

Get a Pine Script tuned to your prop firm.

Invite-only on TradingView within 24 hours. From $19/mo, cancel anytime.