Indicator · Pine Script v4 · On the chart

EMA-PSAR-ATR Indicators [Numchuck]

by DT021

This indicator combines three technical tools into a single price overlay: dual Exponential Moving Averages (EMA), Parabolic SAR (PSAR), and ATR-derived stop loss levels.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code85
Settings14inputs
LicenceGPL-3.0
Last update6 years ago10 Mar 2020

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

85 lines of Pine Script v4 from MyOldCode/EMA-PSAR-ATR-indicators-[Numchuck]-1.1.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

EMA-PSAR-ATR-indicators-[Numchuck]-1.1.pine
//@version=4
// Version 1.0 - jan 2020 - Bas Willemstijn
study(title="EMA-PSAR-ATR indicators [Numchuck]", shorttitle="EMA-PSAR-ATR", overlay=true)

// EMA indicator
dropn(src, n) =>
    na(src[n]) ? na : src

xema(src, len) =>
    mult = 2.0 / (len + 1.0)
    res = float(na)
    res := mult * src + (1.0 - mult) * nz(res[1], src)
    res

length1 = input(9, title="Very Fast Length", minval=1)
length2 = input(21, title="Fast Length", minval=1)
src = input(close, type=input.source, title="Source")
dropCandles = input(1, minval=0, title="Drop first N candles")

price = dropn(src, dropCandles)

sig1 = xema(price, length1)
sig2 = xema(price, length2)

plot(sig1, title="9 day EMA", color=color.red, transp=0, linewidth=2)
plot(sig2, title="21 day EMA", color=color.green, transp=0, linewidth=2)

// ATR indicator
length = input(14, minval=1)
src1 = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50)
maLen = input(7, title="maLength")
basis = sma(src1, length)
dev = mult * atr(length)
upper = basis + dev
lower = basis - dev
bbr = (src1 - lower) / (upper - lower)
bbe = ema(bbr, maLen)
up = bbe[1] > bbe and bbe[2] < bbe[1] ? bbe : na
bt = bbe[1] < bbe and bbe[2] > bbe[1] ? bbe : na

highest_1 = highest(3)
topH = na(up) == 0 ? highest_1 : na
lowest_1 = lowest(3)
bottomL = na(bt) == 0 ? lowest_1 : na

tf = fixnan(topH)
bf = fixnan(bottomL)

btop = close > open ? close : open
bbot = close > open ? open : close

plot(tf, color=color.blue, style=plot.style_circles, linewidth=1, offset=-1, title="Bearish SL")
plot(bf, color=color.blue, style=plot.style_circles, linewidth=1, offset=-1, title="Bullish SL")

// PSAR
//Simply Enhances Default Parabolic SAR by creating Two Color Options, One for UpTrend, Other for DownTrend
//Ability To Turn On/Off The Up Trending Parabolic SAR, And The Down Trending Parabolic SAR
start = input(2, minval=0, maxval=10, title="Start - Default = 2 - Multiplied by .01")
increment = input(2, minval=0, maxval=10, title="Step Setting (Sensitivity) - Default = 2 - Multiplied by .01")
maximum = input(2, minval=1, maxval=10, title="Maximum Step (Sensitivity) - Default = 2 - Multiplied by .10")
sus = input(true, "Show Up Trending Parabolic Sar")
sds = input(true, "Show Down Trending Parabolic Sar")
disc = input(false, title="Start and Step settings are *.01 so 2 = .02 etc, Maximum Step is *.10 so 2 = .2")
//"------Step Setting Definition------"
//"A higher step moves SAR closer to the price action, which makes a reversal more likely."
//"The indicator will reverse too often if the step is set too high."

//"------Maximum Step Definition-----")
//"The sensitivity of the indicator can also be adjusted using the Maximum Step."
//"While the Maximum Step can influence sensitivity, the Step carries more weight"
//"because it sets the incremental rate-of-increase as the trend develops"

startCalc = start * .01
incrementCalc = increment * .01
maximumCalc = maximum * .10

sarUp = sar(startCalc, incrementCalc, maximumCalc)
sarDown = sar(startCalc, incrementCalc, maximumCalc)

colUp = close >= sarDown ? color.lime : na
colDown = close <= sarUp ? color.red : na

plot(sus and sarUp ? sarUp : na, title="Up Trending SAR", style=plot.style_circles, linewidth=4, color=colUp)
plot(sds and sarDown ? sarDown : na, title="Up Trending SAR", style=plot.style_circles, linewidth=4, color=colDown)

Overview

EMA-PSAR-ATR Indicators [Numchuck] calculates fast and very fast EMAs (defaults 9 and 21) using a custom EMA function, plots color-coded Parabolic SAR dots for uptrends and downtrends with toggleable visibility, and computes upper and lower volatility bands using Average True Range (ATR) to mark potential bullish and bearish stop loss points directly on the chart.

Details

Published by

DT021 on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands, Support & resistance

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
Very Fast Lengthint9length1
Fast Lengthint21length2
Sourcesourceclosesrc
Drop first N candlesint1dropCandles
lengthint14length
Sourcesourceclosesrc1
multfloat2.0mult
maLengthint7maLen
Start - Default = 2 - Multiplied by .01int2start
Step Setting (Sensitivity) - Default = 2 - Multiplied by .01int2increment
Maximum Step (Sensitivity) - Default = 2 - Multiplied by .10int2maximum
Show Up Trending Parabolic Sarbooltruesus
Show all 14 settings
SettingTypeDefaultVariable
Show Down Trending Parabolic Sarbooltruesds
Start and Step settings are *.01 so 2 = .02 etc, Maximum Step is *.10 so 2 = .2boolfalsedisc
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

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)

Trend Compass 4H

by chris-c-thomas
14 stars

Trend Compass 4H plots a multi-EMA ribbon (10/21/50) along with higher-timeframe reference levels on the price chart. It classifies trend phase into six states and calculates a composite weighted trend score. The script detects RSI and MACD divergences, analyz

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Trend Compass 4H
10 stars

My Macro Cycle Indicator plots daily and weekly simple and exponential moving averages on the price chart, plus Pi Cycle and Mayer Multiple levels derived from the 200-day average. Optional toggles add support-band fills, a Keltner channel, CME futures gaps, a

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · None stated GitHub repository of My Macro Cycle Indicator

This indicator plots a double-smoothed Supertrend baseline on the price chart, combining a Supertrend midline with WMA and EMA smoothing to show trend direction. Direction uses an ATR-scaled baseline slope with hysteresis, while percentile-ranked slope magnitu

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Smooth Trend Radar [WavesUnchained]

SRI Indicator ft. MSB

by kingmalitha
7 stars

This indicator overlays an all-in-one technical analysis toolkit on the price chart. It plots multiple moving averages, including standard EMAs, SMAs, and a Trend Regularity Adaptive Moving Average, alongside Bollinger Bands, Supertrend, Nadaraya-Watson envelo

Indicator v5 Moving averagesTrend Repaints
Updated 3 years ago · None stated GitHub repository of SRI Indicator ft. MSB

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