HomePine Script Snippets › Daily Kill Switch

Pine Script Daily Kill Switch for Prop Firms

Tracks session P&L and blocks new entries once losses hit your configured threshold. The most important prop firm safety mechanism in any automated strategy.

//@version=5
strategy("Daily Kill Switch", overlay=true)

// ── Inputs ──────────────────────────────────────────────
dailyLossLimit = input.float(-800.0, "Daily Loss Limit ($)", step=50,
     tooltip="Strategy stops new entries when session P&L hits this level. Set to 80% of firm's daily limit.")

// ── State ────────────────────────────────────────────────
var float sessionPnL   = 0.0
var bool  killActive   = false

// Reset at each session open
if session.isfirstbar_regular
    sessionPnL  := 0.0
    killActive  := false

// Accumulate closed-trade P&L within the session
if strategy.closedtrades > strategy.closedtrades[1]
    sessionPnL += strategy.closedtrades.profit(strategy.closedtrades - 1)

// Activate kill switch when threshold is breached
if sessionPnL <= dailyLossLimit
    killActive := true

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

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)

// Visual indicator
bgcolor(killActive ? color.new(color.red, 90) : na, title="Kill Switch Active")

How it works

The snippet maintains two persistent variables using Pine Script's var keyword: sessionPnL (a running total of closed-trade profit/loss for the session) and killActive (a boolean flag that gates all entry conditions).

Each time a trade closes — detected by comparing strategy.closedtrades to its previous value — the profit from that trade is added to sessionPnL. Once sessionPnL drops to or below dailyLossLimit, the killActive flag is set to true. From that point forward, both the long and short entry conditions include and not killActive, which blocks any new entries for the rest of the session.

The chart background turns red when the kill switch is active, giving you an immediate visual confirmation that no more trades will fire that day.

How to configure it for your firm

Set dailyLossLimit to 80% of your firm's stated daily loss cap. This gives you a buffer before hitting the hard floor and leaves room for any slippage or fill variance on open positions.

Firm / AccountDaily LimitRecommended Setting
Topstep 50k Eval$1,000-$800
Topstep 100k Eval$2,000-$1,600
FTMO $10k$500-$400
FTMO $100k$5,000-$4,000
Apex 50k (no hard daily limit)N/A-$800 (personal guardrail)
MyFundedFutures 50kCheck firm rules80% of stated limit
Apex Trader Funding does not enforce a hard daily loss limit on most accounts — their drawdown is trailing overall. Still set a daily kill switch as a personal risk management practice. -$800 on a 50k account is a reasonable default.

Frequently Asked Questions

What is a kill switch in Pine Script?

A Pine Script kill switch is a code block that accumulates your cumulative session P&L and sets a boolean flag to block all new entries once losses exceed a configured threshold. It is the most critical safety mechanism for automated prop firm trading because it prevents a strategy from digging through the firm's hard daily loss floor during a bad session.

Does Apex have a daily loss limit?

Apex Trader Funding does not enforce a hard daily loss limit on most of their evaluation or PA accounts — they use an overall trailing drawdown instead. However, it is still strongly recommended to set a daily kill switch at around -$800 on a 50k account as a personal risk management guardrail, even when the firm does not require it.

How does the kill switch reset each day?

The kill switch uses session.isfirstbar_regular to detect the first bar of each new regular trading session. At that point it resets both sessionPnL to 0.0 and killActive to false, so the strategy resumes taking entries at the start of each fresh trading day.

Related

Want a complete strategy with the kill switch pre-wired?

Our scripts include the kill switch, session filter, bar-close entries, and EOD flatten — tested on 3 years of MES/NQ data and ready for TradersPost automation. Instant delivery from $50.

View Plans — From $50