Indicator · Pine Script v4 · On the chart

200 EMA + Stochastic + Triple Supertrend

by krosenfeld7

This indicator combines a 200-period Exponential Moving Average (EMA), a Stochastic RSI oscillator, and three distinct Supertrend lines utilizing different ATR periods and multipliers.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code168
Settings16inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

168 lines of Pine Script v4 from 200_EMA+Triple_Supertrend+Stochastic/200_EMA+Triple_Supertrend+Stochastic.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

200_EMA+Triple_Supertrend+Stochastic.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

//@version=4
study("200 EMA + Stochastic + Triple Supertrend", shorttitle="200 EMA + Stochastic + Triple Supertrend", overlay=true)
// 200 period EMA Section
len1 = input(200, minval=1, title="EMA Length")
src1 = input(close, title="EMA Source")
offset = input(title="EMA Offset", type=input.integer, defval=0, minval=-500, maxval=500)
ema200 = ema(src1, len1)
plot(ema200, title="EMA", color=color.white, offset=offset, linewidth=3)

emaLong = close > ema200
emaShort = close < ema200

// Stochastic RSI Section
smoothK = input(3, "Stochastic K", minval=1)
smoothD = input(3, "Stochastic D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src2 = input(close, title="RSI Source")
rsi1 = rsi(src2, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)

stoLong = k < 20 and d < 20 and crossover(k, d)
stoShort = k > 80 and d > 80 and crossunder(k, d)

// Supertrend 1: Settings: ATR Period = 12, Multiplier = 3
Periods1 = input(title="Long ATR Period", type=input.integer, defval=12)
src3 = input(hl2, title="ATR Source")
Multiplier1 = input(title="Long ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change Long ATR Calculation Method ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods1)
atr1= changeATR ? atr(Periods1) : atr2
up=src3-(Multiplier1*atr1)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src3+(Multiplier1*atr1)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend1 = 1
trend1 := nz(trend1[1], trend1)
trend1 := trend1 == -1 and close > dn1 ? 1 : trend1 == 1 and close < up1 ? -1 : trend1
upPlot = plot(trend1 == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend1 == 1 and trend1[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
dnPlot = plot(trend1 == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend1 == -1 and trend1[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
mPlot = plot(ohlc4, title="Open/High/Low/Close", style=plot.style_circles, linewidth=0)

// Supertrend 2: Settings: ATR Period = 11, Multiplier = 2
Periods2 = input(title="Intermediate ATR Period", type=input.integer, defval=11)
Multiplier2 = input(title="Intermediate ATR Multiplier", type=input.float, step=0.1, defval=2.0)
atr4 = sma(tr, Periods2)
atr3= changeATR ? atr(Periods2) : atr4
up2=src3-(Multiplier2*atr3)
up3 = nz(up2[1],up2)
up2 := close[1] > up3 ? max(up2,up3) : up2
dn2=src3+(Multiplier2*atr3)
dn3 = nz(dn2[1], dn2)
dn2 := close[1] < dn3 ? min(dn2, dn3) : dn2
trend2 = 1
trend2 := nz(trend2[1], trend2)
trend2 := trend2 == -1 and close > dn3 ? 1 : trend2 == 1 and close < up3 ? -1 : trend2
upPlot2 = plot(trend2 == 1 ? up2 : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal2 = trend2 == 1 and trend2[1] == -1
plotshape(buySignal2 ? up2 : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
dnPlot2 = plot(trend2 == 1 ? na : dn2, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal2 = trend2 == -1 and trend2[1] == 1
plotshape(sellSignal2 ? dn2 : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
mPlot2 = plot(ohlc4, title="Open/High/Low/Close", style=plot.style_circles, linewidth=0)

// Supertrend 3: Settings: ATR Period = 10, Multiplier = 1
Periods3 = input(title="Short ATR Period", type=input.integer, defval=10)
Multiplier3 = input(title="Short ATR Multiplier", type=input.float, step=0.1, defval=1.0)
atr6 = sma(tr, Periods3)
atr5= changeATR ? atr(Periods3) : atr6
up4=src3-(Multiplier3*atr5)
up5 = nz(up4[1],up4)
up4 := close[1] > up5 ? max(up4,up5) : up4
dn4=src3+(Multiplier3*atr5)
dn5 = nz(dn4[1], dn4)
dn4 := close[1] < dn5 ? min(dn4, dn5) : dn4
trend3 = 1
trend3 := nz(trend3[1], trend3)
trend3 := trend3 == -1 and close > dn5 ? 1 : trend3 == 1 and close < up5 ? -1 : trend3
upPlot3 = plot(trend3 == 1 ? up4 : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal3 = trend3 == 1 and trend3[1] == -1
plotshape(buySignal3 ? up4 : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
dnPlot3 = plot(trend3 == 1 ? na : dn4, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal3 = trend3 == -1 and trend3[1] == 1
plotshape(sellSignal3 ? dn4 : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
mPlot3 = plot(ohlc4, title="Open/High/Low/Close", style=plot.style_circles, linewidth=0)

// Bullish (Long)
// Price > 200 EMA
// Stochastic < 20 (oversold) with K crossup
// Case 1: At least 2 supertrend lines below price (close), supertrend lines are upPlot, upPlot2, upPlot3
// Case 2: If only 1 supertrend line below price:
//         Wait until 2 supertrend lines below and enter, but only if Stochastic (k or d) < 50
// Stop loss at 2 supertrend lines below price

longPlot1 = trend1 == 1 ? up : na
longPlot2 = trend2 == 1 ? up2 : na
longPlot3 = trend3 == 1 ? up4 : na
longValid1 = not na(longPlot1) and close > longPlot1
longValid2 = not na(longPlot2) and close > longPlot2
longValid3 = not na(longPlot3) and close > longPlot3
longValidNum = 0
longValidNum += longValid1 ? 1 : 0
longValidNum += longValid2 ? 1 : 0
longValidNum += longValid3 ? 1 : 0

// Case 1: 1 supertrend line is below price
conditionallyValidLong = longValidNum == 1 and stoLong and emaLong

// Case 2: 2 supertrend lines are below price
superLong = (longValid1 and longValid2) or (longValid1 and longValid3) or (longValid2 and longValid3)
tempLong = emaLong and stoLong and superLong

// Case 1: EMA is valid, stochastic is not, but still less than 50 and there are now 2 supertrend lines
if emaLong and (not stoLong and (d < 50 or k < 50)) and (superLong and barssince(conditionallyValidLong) < 10)
    tempLong := true

long = tempLong ? 1 : 0

// Bearish (Short)
// Price < 200 EMA
// Stochastic > 80 (overbought) with K crossdown
// Case 1: At least 2 supertrend lines above price (close), supertrend lines are dnPlot, dnPlot2, dnPlot3
// Case 2: If only 1 supertrend line above price:
//         Wait until 2 supertrend lines above and enter, but only if Stochastic (either k or d) > 50
// Stop loss at 2 supertrend lines above price

shortPlot1 = trend1 == 1 ? na : dn
shortPlot2 = trend2 == 1 ? na : dn2
shortPlot3 = trend3 == 1 ? na : dn4
shortValid1 = not na(shortPlot1) and close < shortPlot1
shortValid2 = not na(shortPlot2) and close < shortPlot2
shortValid3 = not na(shortPlot3) and close < shortPlot3
shortValidNum = 0
shortValidNum += shortValid1 ? 1 : 0
shortValidNum += shortValid2 ? 1 : 0
shortValidNum += shortValid3 ? 1 : 0

// Case 1: 1 supertrend line is above price
conditionallyValidShort = shortValidNum == 1 and stoShort and emaShort

// Case 2: 2 supertrend lines are above price
superShort = (shortValid1 and shortValid2) or (shortValid1 and shortValid3) or (shortValid2 and shortValid3)
tempShort = emaShort and stoShort and superShort

// Case 1: EMA is valid, stochastic is not, but still greater than 50 and there are now 2 supertrend lines
if emaShort and (not stoShort and (d > 50 or k > 50)) and (superShort and barssince(conditionallyValidShort) < 10)
    tempShort := true
    
short = tempShort ? 1 : 0

if long
    label.new(x = bar_index, y = na, text = "Long", yloc = yloc.abovebar, color = color.green)
if short
    label.new(x = bar_index, y = na, text = "Short", yloc = yloc.abovebar, color = color.red)

// Alerts
alertcondition(long, title = "Long Signal", message = "Long @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")
alertcondition(short, title = "Short Signal", message = "Short @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")

Overview

200 EMA + Stochastic + Triple Supertrend overlays the EMA and Supertrend tracking lines directly onto the price chart along with trend change markers. Internal conditions check price relative to the 200 EMA, Stochastic RSI crossover levels in extreme zones, and Supertrend agreement. Inputs allow full customization of EMA parameters, Stochastic RSI periods, and ATR settings.

Details

Published by

krosenfeld7 on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

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 Lengthint200len1
EMA Sourcesourceclosesrc1
EMA Offsetint0offset
Stochastic Kint3smoothK
Stochastic Dint3smoothD
RSI Lengthint14lengthRSI
Stochastic Lengthint14lengthStoch
RSI Sourcesourceclosesrc2
Long ATR Periodint12Periods1
ATR Sourcesourcehl2src3
Long ATR Multiplierfloat3.0Multiplier1
Change Long ATR Calculation Method ?booltruechangeATR
Show all 16 settings
SettingTypeDefaultVariable
Intermediate ATR Periodint11Periods2
Intermediate ATR Multiplierfloat2.0Multiplier2
Short ATR Periodint10Periods3
Short ATR Multiplierfloat1.0Multiplier3
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

114 stars

ADX Strategy (original) is an overlay indicator that identifies trend-following trade signals using the Average Directional Index (ADX) combined with a Simple Moving Average filter. A long signal is generated when the ADX rises above a user-defined trend level

Indicator v4 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Strategy (original)
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision
24 stars

This indicator plots Bollinger Bands on the price chart alongside a baseline moving average to identify trend-aligned swing setups. It calculates trend bias by comparing the Bollinger Bands basis to a customizable moving average, such as a 200 EMA. Trade signa

Indicator v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Bollinger Band Swing

Index Intraday Analyst

by chris-c-thomas
14 stars

Index Intraday Analyst overlays CBOE cash indices such as SPX, NDX, RUT, and DJX. It plots a multi-EMA ribbon, a session-anchored TWAP with standard-deviation bands, and session levels such as prior-day high, low, and close, the opening range, and the high and

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · MIT GitHub repository of Index Intraday Analyst

RePaNoCHa V4

by wocclyl
9 stars

RePaNoCHa V4 is an overlay alert indicator that plots a Tillson T3 moving average on the price chart and colors it by whether the line is rising or falling. It combines that slope with a range filter, ADX, parabolic SAR, RSI, and MACD to mark long and short si

Indicator v4 TrendOscillators & momentum
Updated 7 years ago · MIT GitHub repository of RePaNoCHa V4

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers