Snapshots




How it works
- Honest result: about +$298 before costs, but ~$411 of commission turned it into a -$112 loss. Test costs before you trust any backtest.
- Each trade risks 2 ATR (stop) to make 3 ATR (target), sized at 10% of equity.
- For automation, create a strategy alert and put {{strategy.order.alert_message}} in the message box; your webhook receives {"side":"buy","symbol":"SPX500USD"}.
Settings
| Setting | Default | What it does |
|---|---|---|
| Initial capital | 10,000 | Starting equity |
| Order size | 10% of equity | Per trade |
| Commission | 0.05% per order | Broker cost |
| Slippage | 2 ticks | Execution cost |
| Stop / Target | 2 ATR / 3 ATR | Set in strategy.exit |
Source code
In TradingView: open the Pine Editor, create a new strategy, paste the code, then click "Add to chart".
//@version=6 strategy("EMA Trend Strategy", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 2) fastEma = ta.ema(close, 9) slowEma = ta.ema(close, 21) trendEma = ta.ema(close, 200) atr = ta.atr(14) longSignal = ta.crossover(fastEma, slowEma) and close > trendEma shortSignal = ta.crossunder(fastEma, slowEma) and close < trendEma buyMsg = '{"side":"buy","symbol":"{{ticker}}"}' sellMsg = '{"side":"sell","symbol":"{{ticker}}"}' if longSignal strategy.entry("Long", strategy.long, alert_message = buyMsg) if shortSignal strategy.entry("Short", strategy.short, alert_message = sellMsg) if strategy.position_size > 0 strategy.exit("Long exit", "Long", stop = strategy.position_avg_price - 2 * atr, limit = strategy.position_avg_price + 3 * atr) if strategy.position_size < 0 strategy.exit("Short exit", "Short", stop = strategy.position_avg_price + 2 * atr, limit = strategy.position_avg_price - 3 * atr) plot(fastEma, "Fast EMA", color.teal) plot(slowEma, "Slow EMA", color.orange) plot(trendEma, "Trend EMA", color.gray, 2)
Watch it built
This script is written line by line in the TradingView Masterclass video.
Need a custom indicator or strategy?
Non-repainting Pine Script v6, backtested with real costs, alert and webhook ready. Fixed quote within 24 hours.