1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
62 lines of Pine Script v6 from global-markets/01_es_sp500.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
01_es_sp500.pine
//@version=6
// E-mini S&P 500 (ES) / Micro E-mini (MES) Strategy
// github.com/trugurpala/pinescriptv6 — Author: Ugur Pala
//
// TR: Semboller: CME_MINI:ES1! (tam lot) / CME_MICRO:MES1! (mikro)
// EN: Symbols: CME_MINI:ES1! (full) / CME_MICRO:MES1! (micro)
//
// Seans / Session: 09:30–16:00 ET (14:30–21:00 UTC)
// Kontrat değeri / Tick value: ES=$12.50/tick | MES=$1.25/tick
// Komisyon / Commission: ~$2–5/side (tam) | ~$0.25–0.50 (mikro)
strategy("ES S&P500 Strategy [trugurpala]",
overlay = true,
initial_capital = 25000,
default_qty_type = strategy.fixed,
default_qty_value = 1,
commission_type = strategy.commission.cash_per_contract,
commission_value = 4.0, // ~$4/side for ES
slippage = 1)
// ── Inputs ───────────────────────────────────────────────────────────────────
int fastLen = input.int(9, "Fast EMA", minval=1)
int slowLen = input.int(21, "Slow EMA", minval=1)
int atrLen = input.int(14, "ATR", minval=1)
float slMult = input.float(1.5, "SL Mult", step=0.1)
float tpMult = input.float(3.0, "TP Mult", step=0.1)
bool longOnly = input.bool(false, "Long Only")
// ── ES Seans Filtresi: 09:30–16:00 ET (UTC-4/UTC-5) ──────────────────────────
// EN: RTH (Regular Trading Hours) filter for ES
bool inRTH = not na(time(timeframe.period, "0930-1600", "America/New_York"))
// ── Hesaplamalar / Calculations ───────────────────────────────────────────────
float fastEma = ta.ema(close, fastLen)
float slowEma = ta.ema(close, slowLen)
float atrVal = ta.atr(atrLen)
bool bullCross = ta.crossover(fastEma, slowEma) and inRTH
bool bearCross = ta.crossunder(fastEma, slowEma) and inRTH
// ── RTH sonu tüm pozisyonları kapat / Close all at RTH end ──────────────────
bool rthEnd = inRTH[1] and not inRTH
if rthEnd
strategy.close_all(comment="RTH End")
// ── Entries ──────────────────────────────────────────────────────────────────
if bullCross
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long",
stop = close - slMult * atrVal,
limit = close + tpMult * atrVal)
if bearCross and not longOnly
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short",
stop = close + slMult * atrVal,
limit = close - tpMult * atrVal)
// ── Visuals ──────────────────────────────────────────────────────────────────
bgcolor(inRTH ? na : color.new(color.gray, 96), title="Outside RTH")
plot(fastEma, "Fast", fastEma > slowEma ? color.green : color.red, linewidth=2)
plot(slowEma, "Slow", fastEma > slowEma ? color.lime : color.orange, linewidth=2)
plotshape(bullCross, "Long", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(bearCross, "Short", shape.triangledown, location.abovebar, color.red, size=size.small)
Overview
ES S&P500 Strategy [trugurpala] enters long when a fast EMA crosses above a slow EMA during New York regular trading hours, and enters short on the opposite cross unless long-only mode is on. Each entry places an ATR-based stop and take profit. All open positions close when the session ends. Fast and slow lengths, ATR length, stop and target multiples, and the long-only switch are the main settings. One contract is used by default.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Fast EMA
int
9
fastLen
Slow EMA
int
21
slowLen
ATR
int
14
atrLen
SL Mult
float
1.5
slMult
TP Mult
float
3.0
tpMult
Long Only
bool
false
longOnly
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy executes long and short trades on the price chart by combining multi-timeframe smoothed Heikin-Ashi trends, higher-timeframe Hull Moving Average variations, and an ATR-based trailing stop. Users can adjust timeframes, smoothing lengths, Hull form
This strategy draws two moving averages on the price chart and uses their bias to open long or short trades. It places the stop beyond a swing high or low using an ATR risk multiple, then sets a limit exit from the reward-to-risk ratio. An optional ATR trail c
The IBKR Safe Forex Strategy is a Pine Script v6 strategy that trades forex pairs using crossovers of 10-period and 50-period EMAs, filtered by a 200-period EMA and restricted to London or New York session overlap. It enters long positions on fast EMA above sl
This Pine Script v6 strategy uses multi-timeframe analysis to identify intraday trends and generate trading signals. It requests higher-timeframe data for trend context via EMAs and Supertrend direction. On the local timeframe it plots EMA cross signals for lo
This strategy template provides a modular foundation for building TradingView v6 backtests. It uses a placeholder Exponential Moving Average crossover signal combined with customizable filters for higher-timeframe trend alignment, volatility regime thresholds,
This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries