Strategy · Pine Script v5 · On the chart

ADX Trend Strength - Eterna

by EternaHybridExchange

Calculates the Average Directional Index (ADX), Directional Movement Index (DMI), and an Exponential Moving Average to trade strong directional momentum.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code68
Settings7inputs
LicenceMIT
Last update7 months ago12 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

68 lines of Pine Script v5 from strategies/trend-following/adx-trend-strength/strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

strategy.pine
//@version=5
strategy("ADX Trend Strength - Eterna", 
         overlay=true, 
         initial_capital=10000,
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=10,
         commission_type=strategy.commission.percent,
         commission_value=0.075)

// ==================== Parameters ====================
adxLength = input.int(14, "ADX Length", minval=1)
adxThreshold = input.int(25, "ADX Threshold", minval=1)
diLength = input.int(14, "DI Length", minval=1)
emaLength = input.int(50, "Trend EMA", minval=1)
leverage = input.int(5, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, step=0.001)

webhookMessage = input.string('{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}", "size":' + str.tostring(positionSize) + ', "leverage":' + str.tostring(leverage) + '}', 
                               "Webhook JSON", group="Webhook")

// ==================== ADX Calculation ====================
[diPlus, diMinus, adx] = ta.dmi(diLength, adxLength)
trendEMA = ta.ema(close, emaLength)

// ==================== Entry Conditions ====================
// Strong trend: ADX above threshold
strongTrend = adx > adxThreshold

// Bullish: DI+ crosses above DI- with strong ADX and price above EMA
bullishDI = ta.crossover(diPlus, diMinus)
longCondition = bullishDI and strongTrend and close > trendEMA

// Bearish: DI- crosses above DI+ with strong ADX and price below EMA
bearishDI = ta.crossover(diMinus, diPlus)
shortCondition = bearishDI and strongTrend and close < trendEMA

// Exit when DI crosses opposite or ADX drops below threshold
exitLong = ta.crossunder(diPlus, diMinus) or adx < adxThreshold * 0.7
exitShort = ta.crossover(diPlus, diMinus) or adx < adxThreshold * 0.7

// ==================== Strategy Execution ====================
if longCondition
    strategy.entry("Long", strategy.long, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "buy"))

if shortCondition
    strategy.entry("Short", strategy.short, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "sell"))

if exitLong
    strategy.close("Long", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

if exitShort
    strategy.close("Short", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

// ==================== Plotting ====================
plot(trendEMA, "Trend EMA", color=color.orange, linewidth=2)

// Plot ADX in separate pane (will appear as overlay labels)
plotshape(longCondition, "Long Signal", shape.triangleup, location.belowbar, color.green, size=size.normal, 
          text="ADX:" + str.tostring(adx, "#.#"))
plotshape(shortCondition, "Short Signal", shape.triangledown, location.abovebar, color.red, size=size.normal,
          text="ADX:" + str.tostring(adx, "#.#"))

// Background color based on trend strength
bgcolor(strongTrend ? (diPlus > diMinus ? color.new(color.green, 92) : color.new(color.red, 92)) : color.new(color.gray, 95))

// Show DI crossovers
plotshape(bullishDI and strongTrend, "DI+ Cross", shape.circle, location.belowbar, color.new(color.green, 50), size=size.tiny)
plotshape(bearishDI and strongTrend, "DI- Cross", shape.circle, location.abovebar, color.new(color.red, 50), size=size.tiny)

Overview

ADX Trend Strength - Eterna enters long when the DI+ line crosses above DI- while ADX exceeds a threshold and price is above the EMA. Short positions trigger under mirrored conditions. Trades exit when directional indicators cross back or ADX falls below a fraction of the threshold. It plots the EMA, background trend highlights, and signal markers on the price chart, operating without a hard stop loss.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages

Markets

Crypto

Timeframes

M15-H1, H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
ADX Lengthint14adxLength
ADX Thresholdint25adxThreshold
DI Lengthint14diLength
Trend EMAint50emaLength
Leverageint5leverage
Position Sizefloat0.01positionSize
Webhook JSONstring'{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}webhookMessage
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