Indicator · Pine Script v5 · On the chart

EMA and ADX v1

by aofwittawat

This indicator calculates an Exponential Moving Average (EMA) and an Average Directional Index (ADX) to signal trend entries and exits directly on the price chart.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code71
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago8 Jun 2022

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

71 lines of Pine Script v5 from EMA and ADX indicator.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

EMA and ADX indicator.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aofwittawat

//@version=5
indicator("EMA_and_Adx_v1", overlay=true)

//User input
ema_len = input.int(title="EMA length", defval= 18 )
adxlen  = input.int(title="ADX Smoothing", defval= 25)
dilen   = input.int(title="DI Length", defval =25)
ADXlower = input.float(title = "Lower level", defval = 10)
ADXupper = input.float(title = "Upper level", defval = 20)
ADXuse  = input.bool(title = "USE ADX or not?", defval = true) 

//Get EMA and ADX
ema             = ta.ema(close, ema_len)
dirmov(len) =>
    up          = ta.change(high)
    down        = -ta.change(low)
    plusDM      = na(up) ? na : (up > down and up > 0 ? up : 0)
    minusDM     = na(down) ? na : (down > up and down > 0 ? down : 0)
    truerange   = ta.rma(ta.tr, len)
    plus        = fixnan(100 * ta.rma(plusDM, len) / truerange)
    minus       = fixnan(100 * ta.rma(minusDM, len) / truerange)
    [plus, minus]
adx_sig(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx = adx_sig(dilen, adxlen)

// Check filter
readyTotrade = not na(ema) and not na(adx)
var int inTrade = 0

// Get criteria
validLong = false
validShort = false
if ADXuse 
    validLong       := (close > ema) and (adx >=ADXlower and adx <= ADXupper) and inTrade == 0
    validShort      := (close < ema) and (adx >=ADXlower and adx <= ADXupper) and inTrade == 0
else
    validLong   := close > ema and inTrade == 0
    validShort  := close < ema and inTrade == 0

//Check order
if (validLong or validShort) and inTrade == 0
    inTrade := validLong ? 1 : -1
if inTrade == 1
    if close < ema
        inTrade := 0
if inTrade == -1
    if close > ema
        inTrade := 0
        
// Exit
exitLong    = false
exitShort   = false
if inTrade[1] == 1 and inTrade == 0
    exitLong := true
if inTrade[1] == -1 and inTrade == 0
    exitShort := true

// Draw data 
plot(ema, title="EMA", linewidth =2)
plotshape(validLong, style=shape.triangleup, color=color.green, location=location.belowbar, text="Long", textcolor = color.white, title="Long")
plotshape(exitLong, style=shape.triangledown, color=color.red, location=location.abovebar, text="ExitLong", textcolor = color.white, title="ExitLong")
plotshape(validShort, style=shape.triangledown, color=color.red, location=location.abovebar, text="Short", textcolor = color.white, title="Short")
plotshape(exitShort, style=shape.triangleup, color=color.green, location=location.belowbar, text="ExitShort", textcolor = color.white, title="ExitShort")
bgcolor((inTrade == 1) ? color.new(color.green, 90) :na)
bgcolor((inTrade == -1)? color.new(color.red,90) :na)

Overview

EMA and ADX v1 triggers a long signal when the close is above the EMA and a short signal when below, optionally filtered to bars where ADX is bounded between specified upper and lower thresholds. Exits trigger when price crosses back over the EMA. The script plots the EMA line, entry and exit shape labels, and tints the background while a trade state is active.

Details

Published by

aofwittawat on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

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 lengthint18ema_len
ADX Smoothingint25adxlen
DI Lengthint25dilen
Lower levelfloat10ADXlower
Upper levelfloat20ADXupper
USE ADX or not?booltrueADXuse
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

948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average
218 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist

Daily Trend Filter

by agutinbaigo28
147 stars

Calculates market regime conditions by combining RSI, MACD, and ADX/DMI indicators. It evaluates whether the market is in a strong bullish, strong bearish, neutral, or non-trending regime. The script plots a colored line overlaying the close price to reflect t

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Daily Trend Filter

AAPP

by capissimo
114 stars

This indicator plots an adaptive moving average or scaled RSI divergence line directly on the price chart. It calculates dual RSI series to measure momentum divergence, scales the values to the chart's price range, and constructs an adaptive average filtered b

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of AAPP

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m
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

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