Strategy · Pine Script v5 · On the chart

Supertrend + EMA rebound [Alorse]

by Alorse

This strategy plots a Supertrend line from ATR length and factor, plus a single EMA, on the price chart.

View on GitHub

GitHub stars330on the repository
Pine versionv5runs as is
Lines of code72
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago25 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

72 lines of Pine Script v5 from strategies/trend/Supertrend + EMA rebound [Alorse].pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Supertrend + EMA rebound [Alorse].pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alorse

//@version=5
strategy(title='Supertrend + EMA rebound [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=10000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)

// Backtesting
btGroup = "Backtesting"
startTime = input.time(title="Start time", defval=timestamp("Nov 01 2021 23:59:59"), group=btGroup)
endTime = input.time(title="End time", defval=timestamp("Feb 01 2099 23:59:59"), group=btGroup)

inDateRange = time >= startTime and time <= endTime

atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.1)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

inLong = direction < 0
inShort = direction > 0

upTrend = plot(inLong? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(inShort ? supertrend : na, "Down Trend", color = color.red, style=plot.style_linebr)

bodyMiddle = plot((open + close) / 2, display=display.none)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

// Moving Averages
len_a = input.int(20, minval=1, title='EMA A Length', group='Moving Average')
out_a = ta.ema(close, len_a)
plot(out_a, title='EMA A', color=color.yellow)

lastEntry = strategy.opentrades.entry_price(0)
// Strategy Conditions
stratGroup = 'Strategy'
showLong = input.bool(true, title='Long entries', group=stratGroup)
showShort = input.bool(true, title='Short entries', group=stratGroup)
entryLong = ta.change(direction) < 0
entryLong := entryLong or (inLong and close[1] < out_a and close > out_a and close < lastEntry)
exitLong = ta.change(direction) > 0

entryShort = ta.change(direction) > 0
entryShort := entryShort or (inShort and close[1] > out_a and close < out_a and close > lastEntry)
exitShort = ta.change(direction) < 0

tpGroup = 'Take Profit'
useTP = input.string(title='Type', defval='Supertrend', options=['Supertrend', '%'], group=tpGroup, tooltip='Supertrend: \nPercent (%): \nRatio:')
TPPercent = input.float(1.5, step=0.1, title='Percent/Ratio', group=tpGroup)

longTP = 99999999999.9
shortTP = 0.0

bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1]
entry_price = ta.valuewhen(bought, open, 0)

if useTP == '%'
    longTP := strategy.position_avg_price * (1 + (TPPercent * 0.01))
    shortTP := strategy.position_avg_price * (1 - (TPPercent * 0.01))
else
    longTP := na
    shortTP := na

if showLong and inDateRange
    strategy.entry("Long", strategy.long, when=entryLong)
    strategy.close("Long", when=exitLong)
    strategy.exit("Exit", "Long", limit=longTP)

if showShort and inDateRange
    strategy.entry("Short", strategy.short, when=entryShort)
    strategy.close("Short", when=exitShort)
    strategy.exit("Exit", "Short", limit=shortTP)

Overview

Supertrend + EMA rebound [Alorse] enters long when Supertrend turns bullish or while the trend is bullish and price crosses back above the EMA below the last entry price. Short entries mirror that logic. Positions close when Supertrend flips, and an optional percent take-profit limit can be set. Main settings change ATR length, factor, EMA length, trade direction, and take-profit type. There is no stop loss by default.

Details

Published by

Alorse on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

pinescriptpinescript-indicatorspinescript-strategiestrading-strategiestradingviewtradingview-alerttradingview-strategy

Settings

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

SettingTypeDefaultVariable
Start timetimetimestamp("Nov 01 2021 23:59:59")startTime
End timetimetimestamp("Feb 01 2099 23:59:59")endTime
ATR Lengthint10atrPeriod
Factorfloat3.0factor
EMA A Lengthint20len_a
Long entriesbooltrueshowLong
Short entriesbooltrueshowShort
TypestringSupertrenduseTP
Percent/Ratiofloat1.5TPPercent
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

257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA 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