Strategy · Pine Script v5 · On the chart

Slow & Steady - Swing Strategy

by Basant1Saini· code credited to TradingTools

Slow & Steady is a swing trading strategy that identifies trend direction using aligned EMAs of 50, 100, and 200 periods.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code90
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update7 months ago4 Mar 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

90 lines of Pine Script v5 from 4_Slow_and_Steady/4_Slow_and_Steady.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

4_Slow_and_Steady.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © TradingTools

//@version=5
strategy("Slow & Steady - Swing Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ─── Inputs ───
ema50Len        = input.int(50, "EMA 50 Length", group="Moving Averages")
ema100Len       = input.int(100, "EMA 100 Length", group="Moving Averages")
ema200Len       = input.int(200, "EMA 200 Length", group="Moving Averages")
macdFast        = input.int(12, "MACD Fast", group="MACD")
macdSlow        = input.int(26, "MACD Slow", group="MACD")
macdSignal      = input.int(9, "MACD Signal", group="MACD")
adxLength       = input.int(14, "ADX Length", group="ADX Filter")
adxSmoothing    = input.int(14, "ADX Smoothing", group="ADX Filter")
adxThreshold    = input.float(20, "ADX Threshold", group="ADX Filter")
useAdxFilter    = input.bool(true, "Use ADX Filter", group="ADX Filter")
atrLength       = input.int(14, "ATR Length", group="Risk Management")
atrMult         = input.float(2.5, "ATR Multiplier for SL", step=0.1, group="Risk Management")
trailAtrMult    = input.float(3.0, "Trailing Stop ATR Mult", step=0.1, group="Risk Management")
useTrailStop    = input.bool(true, "Use Trailing Stop", group="Risk Management")

// ─── Calculations ───
ema50   = ta.ema(close, ema50Len)
ema100  = ta.ema(close, ema100Len)
ema200  = ta.ema(close, ema200Len)

[macdLine, signalLine, hist] = ta.macd(close, macdFast, macdSlow, macdSignal)

atrVal = ta.atr(atrLength)

// ─── ADX Calculation ───
[diPlus, diMinus, adxVal] = ta.dmi(adxLength, adxSmoothing)
adxOK = useAdxFilter ? adxVal >= adxThreshold : true

// ─── Trend Alignment ───
// Bullish: EMA 50 > EMA 100 > EMA 200 (all aligned upward)
// Bearish: EMA 50 < EMA 100 < EMA 200 (all aligned downward)
bullTrend = ema50 > ema100 and ema100 > ema200
bearTrend = ema50 < ema100 and ema100 < ema200

// ─── Entry Conditions ───
// Long:  Aligned bull trend + MACD crosses above signal + ADX confirms strength
// Short: Aligned bear trend + MACD crosses below signal + ADX confirms strength
longCondition  = bullTrend and ta.crossover(macdLine, signalLine) and adxOK and close > ema50
shortCondition = bearTrend and ta.crossunder(macdLine, signalLine) and adxOK and close < ema50

// ─── Pullback Entry (price touches EMA 50 in a trend) ───
pullbackLong  = bullTrend and low <= ema50 and close > ema50 and macdLine > signalLine and adxOK
pullbackShort = bearTrend and high >= ema50 and close < ema50 and macdLine < signalLine and adxOK

// ─── Execute Trades ───
if (longCondition or pullbackLong) and strategy.position_size == 0
    sl = close - atrVal * atrMult
    strategy.entry("Steady Long", strategy.long)
    if useTrailStop
        strategy.exit("Steady Long Exit", "Steady Long", stop=sl, trail_offset=atrVal * trailAtrMult, trail_points=atrVal * trailAtrMult)
    else
        strategy.exit("Steady Long Exit", "Steady Long", stop=sl)

if (shortCondition or pullbackShort) and strategy.position_size == 0
    sl = close + atrVal * atrMult
    strategy.entry("Steady Short", strategy.short)
    if useTrailStop
        strategy.exit("Steady Short Exit", "Steady Short", stop=sl, trail_offset=atrVal * trailAtrMult, trail_points=atrVal * trailAtrMult)
    else
        strategy.exit("Steady Short Exit", "Steady Short", stop=sl)

// ─── Exit on Trend Break ───
if strategy.position_size > 0 and (ema50 < ema100 or close < ema200)
    strategy.close("Steady Long", comment="Trend Break")
if strategy.position_size < 0 and (ema50 > ema100 or close > ema200)
    strategy.close("Steady Short", comment="Trend Break")

// ─── Plotting ───
plot(ema50, "EMA 50", color=color.new(color.blue, 0), linewidth=2)
plot(ema100, "EMA 100", color=color.new(color.orange, 0), linewidth=2)
plot(ema200, "EMA 200", color=color.new(color.red, 0), linewidth=3)

// Trend ribbon fill
ema50Plot  = plot(ema50, display=display.none)
ema200Plot = plot(ema200, display=display.none)
fill(ema50Plot, ema200Plot, color=bullTrend ? color.new(color.green, 88) : bearTrend ? color.new(color.red, 88) : color.new(color.gray, 95), title="Trend Ribbon")

plotshape(longCondition or pullbackLong, title="Long", location=location.belowbar, style=shape.arrowup, color=color.green, size=size.small)
plotshape(shortCondition or pullbackShort, title="Short", location=location.abovebar, style=shape.arrowdown, color=color.red, size=size.small)

// ─── Alerts ───
alertcondition(longCondition or pullbackLong, title="Slow & Steady Long", message="Slow & Steady: Long entry — trend aligned with momentum")
alertcondition(shortCondition or pullbackShort, title="Slow & Steady Short", message="Slow & Steady: Short entry — trend aligned with momentum")

Overview

Slow & Steady - Swing Strategy generates buy and sell signals when the MACD line crosses its signal line within a confirmed trend, filtered by ADX strength. Entries can also occur on pullbacks to the 50 EMA. Stop losses are calculated using ATR multiples, with an option for trailing stops. The strategy plots buy and sell signals along with stop losses on the price chart. Main inputs adjust the periods for moving averages, MACD, ADX, and ATR parameters. It supports position sizing as a percentage of equity.

Details

Published by

Basant1Saini on GitHub

Code credit

TradingTools, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Stocks

Timeframes

H4 and above

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.

Settings

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

SettingTypeDefaultVariable
EMA 50 Lengthint50ema50Len
EMA 100 Lengthint100ema100Len
EMA 200 Lengthint200ema200Len
MACD Fastint12macdFast
MACD Slowint26macdSlow
MACD Signalint9macdSignal
ADX Lengthint14adxLength
ADX Smoothingint14adxSmoothing
ADX Thresholdfloat20adxThreshold
Use ADX FilterbooltrueuseAdxFilter
ATR Lengthint14atrLength
ATR Multiplier for SLfloat2.5atrMult
Show all 14 settings
SettingTypeDefaultVariable
Trailing Stop ATR Multfloat3.0trailAtrMult
Use Trailing StopbooltrueuseTrailStop
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

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

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