Strategy · Pine Script v6 · On the chart

Crude Oil CL Strategy [trugurpala]

by trugurpala

This strategy trades crude oil futures only during the New York session from 09:00 to 14:30.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code62
Settings5inputs
LicenceMIT
Last update2 months ago3 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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/04_cl_crude_oil.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

04_cl_crude_oil.pine
//@version=6
// Crude Oil Futures (CL) Strategy
// github.com/trugurpala/pinescriptv6 — Author: Ugur Pala
//
// TR: Sembol: NYMEX:CL1!
// EN: Symbol: NYMEX:CL1!
//
// Seans: 09:00–14:30 ET (en aktif)
// UYARI: Çarşamba 10:30 ET EIA stok verisi = yüksek volatilite
// WARNING: Wednesday 10:30 ET EIA inventory = high volatility
// Tick: $10/tick — pozisyon boyutunu küçük tut!
strategy("Crude Oil CL Strategy [trugurpala]",
    overlay           = true,
    initial_capital   = 10000,
    default_qty_type  = strategy.fixed,
    default_qty_value = 1,
    commission_type   = strategy.commission.cash_per_contract,
    commission_value  = 5.0,
    slippage          = 2)

// ── 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(2.0, "SL Mult",  step=0.1)
float tpMult    = input.float(2.5, "TP Mult",  step=0.1)

// ── En Aktif Seans: 09:00–14:30 ET ───────────────────────────────────────────
bool inSession = not na(time(timeframe.period, "0900-1430", "America/New_York"))

// ── Hesaplamalar ──────────────────────────────────────────────────────────────
float fastEma  = ta.ema(close, fastLen)
float slowEma  = ta.ema(close, slowLen)
float atrVal   = ta.atr(atrLen)

bool bullCross = ta.crossover(fastEma,  slowEma) and inSession
bool bearCross = ta.crossunder(fastEma, slowEma) and inSession

// ── Günlük Kapanış ────────────────────────────────────────────────────────────
bool sesEnd = inSession[1] and not inSession
if sesEnd
    strategy.close_all(comment="Session End")

// ── Entries ──────────────────────────────────────────────────────────────────
if bullCross
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long",
        stop  = close - slMult * atrVal,
        limit = close + tpMult * atrVal)

if bearCross
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short",
        stop  = close + slMult * atrVal,
        limit = close - tpMult * atrVal)

// ── Visuals ──────────────────────────────────────────────────────────────────
bgcolor(inSession ? na : color.new(color.gray, 96))
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)
plotshape(bearCross, "Short", shape.triangledown, location.abovebar, color.red)

Overview

Crude Oil CL Strategy [trugurpala] enters long when a fast EMA crosses above a slow EMA and short on the opposite cross, and only while that session is open. Each entry sets an ATR-based stop loss and take profit. All open positions close when the session ends. EMA lengths and ATR multipliers change signal timing and exit distance. It plots both EMAs and entry markers on the price chart and shades bars outside the session.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands, Sessions & time

Markets

Oil & commodities

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fast EMAint9fastLen
Slow EMAint21slowLen
ATRint14atrLen
SL Multfloat2.0slMult
TP Multfloat2.5tpMult
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.

Similar Pine Scripts

Session Wicks

by g-moe
3 stars

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

Strategy v5 TrendMoving averages Repaints
Updated 5 months ago · None stated GitHub repository of Session Wicks

3Commas Bot

by regalouisei
2 stars

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

Strategy v5 TrendMoving averages
Updated 8 months ago · None stated GitHub repository of 3Commas Bot
1 stars

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

Strategy v6 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of IBKR Safe Forex Strategy
1 stars

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

Strategy v6 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Tn Sovereign MTF Intraday v6

Strategy Template

by MoDarK-MK
1 stars

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,

Strategy v6 TrendMoving averages
Updated 7 weeks ago · MPL-2.0 GitHub repository of Strategy Template

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

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers