1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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.
Average Directional Index calculation
Configurable ADX smoothing and DI length
Adjustable minimum and maximum threshold lines
Multi-timeframe security requests with lookahead toggle
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
HL Time Frame
timeframe
hlTimeframe
HL Gaps
bool
true
hlGaps
HL Lookahead
bool
true
hlLookahead
ADX Smoothing
int
1
adxlen
DI Length
int
5
dilen
Minimum Line
int
25
adxTarget
Maximum Line
int
75
adxMaximum
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.
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
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
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
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
This strategy plots a comparative relative strength line against a benchmark symbol in a separate pane. It calculates price and volume simple moving averages alongside a multi-period highest high. Long trades enter using full equity when price exceeds its movi
This strategy calculates two simple moving averages using periods 34 and 68 on the close price. It detects bullish crossovers to enter long positions of 10 contracts and bearish crossovers to enter short positions of 10 contracts after the 100th bar. Opposite