Strategy · Pine Script v5 · Own pane

Average Directional Index

by hasnocool

This script calculates and plots the Average Directional Index alongside directional movement values in a separate pane.

View on GitHub

Repaints

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code28
Settings7inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

28 lines of Pine Script v5 from Average Directional Index v2.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Average Directional Index v2.pine
//@version=5
strategy("Average Directional Index", shorttitle="ADXx", format=format.price, precision=2, calc_on_every_tick=true)
hlTimeframe = input.timeframe("", title="HL Time Frame")
// https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html
hlGaps = input.bool(true, "HL Gaps")
hlLookahead = input.bool(true, "HL Lookahead")
adxlen = input(1, title="ADX Smoothing")
dilen = input(5, title="DI Length")
adxTarget = input(25, title="Minimum Line")
hline(adxTarget, title="Minimum Line", color=color.green, linestyle=hline.style_solid)
adxMaximum = input(75, title="Maximum Line")
hline(adxMaximum, title="Maximum Line", color=color.red, linestyle=hline.style_solid)
dirmov(len) =>
    up = ta.change(request.security(syminfo.tickerid, hlTimeframe, high, gaps=hlGaps ? barmerge.gaps_on : barmerge.gaps_off, lookahead=hlLookahead ? barmerge.lookahead_on : barmerge.lookahead_off))
    down = -ta.change(request.security(syminfo.tickerid, hlTimeframe, low, gaps=hlGaps ? barmerge.gaps_on : barmerge.gaps_off, lookahead=hlLookahead ? barmerge.lookahead_on : barmerge.lookahead_off))
    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(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
plot(sig, color=color.teal, title="ADXx")
Expand (35 lines)

Overview

Although declared as a strategy, it only plots the indicator oscillator against customizable minimum and maximum threshold levels without defined entry, exit, or stop-loss rules. Users can adjust the directional movement smoothing, index length, and target thresholds, as well as request higher-timeframe data. By enabling higher-timeframe lookahead and tick-level calculation by default, the script introduces repainting and future bias.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time
  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
HL Time FrametimeframehlTimeframe
HL GapsbooltruehlGaps
HL LookaheadbooltruehlLookahead
ADX Smoothingint1adxlen
DI Lengthint5dilen
Minimum Lineint25adxTarget
Maximum Lineint75adxMaximum
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

HA UnivLong&Short Futures calculates Heikin Ashi candles and builds a channel using simple moving averages of Heikin Ashi highs and lows. It enters long positions when the upper channel line crosses above the lower channel line and opens short positions on the

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of HA UnivLong&Short Futures

Q-Trend + KVO Strategy

by TradersPost
218 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

BTC MACD Basic Tests

by iamrichardD
57 stars

BTC MACD Basic Tests implements a Pine Script unit-testing framework designed to validate components of a long-only Bitcoin MACD trading system. It constructs structured test cases to evaluate mock functions for MACD crossover calculations, volume threshold ch

Strategy v6 Oscillators & momentumTrend
Updated 1 year ago · Apache-2.0 GitHub repository of BTC MACD Basic Tests

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