The "Cost Autopsy" Pine Script (v5)
Here is a Pine Script I wrote to demonstrate this exact phenomenon. It’s a standard M1 EMA Crossover strategy, but I’ve built the realistic costs directly into the strategy() function and added the "Rescue Filters" (HTF Trend + Volatility Floor) you can toggle on and off.
Run this on an M1 chart, look at the Strategy Tester, and toggle the filters to see how raw M1 signals get shredded by commissions, while filtered signals survive.
Code: Select all
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Trading_Autopsy
//@version=5
strategy("M1 Reality Check: Cost Autopsy", overlay=true,
margin_long=100, margin_short=100,
commission_type=strategy.commission.cash_per_order,
commission_value=3.5, // $7 round trip per lot
slippage=2, // 2 ticks slippage
initial_capital=10000)
// ==========================================
// 1. INPUTS
// ==========================================
grp1 = "M1 Trigger (The Bait)"
fastLen = input.int(9, title="Fast EMA", group=grp1)
slowLen = input.int(21, title="Slow EMA", group=grp1)
grp2 = "The Rescue Filters (Toggle to survive costs)"
useHtfFilter = input.bool(true, title="Use 15m Trend Filter?", group=grp2)
useAtrFilter = input.bool(true, title="Use Volatility Floor?", group=grp2)
minAtrPips = input.float(3.0, title="Min M1 ATR (Pips) to Trade", group=grp2)
// ==========================================
// 2. INDICATOR MATH
// ==========================================
// M1 Trigger logic (Standard Retail Trap)
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
longTrigger = ta.crossover(fastEMA, slowEMA)
shortTrigger = ta.crossunder(fastEMA, slowEMA)
// HTF Filter logic (Location)
htfEMA = request.security(syminfo.tickerid, "15", ta.ema(close, 200))
htfBullish = close > htfEMA
htfBearish = close < htfEMA
// Volatility Floor logic (Can we pay the broker?)
// Converting ATR to pips for forex/crypto generalization
m1Atr = ta.atr(14)
pipSize = syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)
atrInPips = m1Atr / pipSize
volatilityIsHighEnough = atrInPips >= minAtrPips
// ==========================================
// 3. FILTER LOGIC COMPILATION
// ==========================================
// If filters are disabled via inputs, they return 'true' to allow raw signals
validLongEnv = (useHtfFilter ? htfBullish : true) and (useAtrFilter ? volatilityIsHighEnough : true)
validShortEnv = (useHtfFilter ? htfBearish : true) and (useAtrFilter ? volatilityIsHighEnough : true)
finalLongSignal = longTrigger and validLongEnv
finalShortSignal = shortTrigger and validShortEnv
// ==========================================
// 4. EXECUTION
// ==========================================
if finalLongSignal
strategy.entry("Long", strategy.long)
if finalShortSignal
strategy.entry("Short", strategy.short)
// Simple trailing exit for demonstration
exitLong = ta.crossunder(fastEMA, slowEMA)
exitShort = ta.crossover(fastEMA, slowEMA)
if exitLong
strategy.close("Long")
if exitShort
strategy.close("Short")
// ==========================================
// 5. VISUALS
// ==========================================
plot(fastEMA, color=color.blue, title="Fast M1 EMA")
plot(slowEMA, color=color.orange, title="Slow M1 EMA")
plot(useHtfFilter ? htfEMA : na, color=color.white, linewidth=2, title="15m HTF Filter")
// Highlight background when volatility is dead (eating costs)
bgcolor(useAtrFilter and not volatilityIsHighEnough ? color.new(color.red, 90) : na, title="Low Volatility Zone")
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.