feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
2026-03-09 13:45:46 -07:00
|
|
|
// Licensed under the Apache License, Version 2.0
|
2026-01-31 11:21:09 -08:00
|
|
|
// © mihakralj
|
|
|
|
|
//@version=6
|
2026-03-16 12:45:13 -07:00
|
|
|
indicator("Accumulation/Distribution Line (AD)", "AD", overlay=false)
|
2026-01-31 11:21:09 -08:00
|
|
|
|
2026-03-16 12:45:13 -07:00
|
|
|
//@function Calculates the Accumulation/Distribution Line (AD), a volume-based indicator that measures money flow into and out of a security
|
2026-01-31 11:21:09 -08:00
|
|
|
//@param src_high The high price (default: built-in high)
|
|
|
|
|
//@param src_low The low price (default: built-in low)
|
|
|
|
|
//@param src_close The close price (default: built-in close)
|
|
|
|
|
//@param src_vol The volume (default: built-in volume)
|
2026-03-16 12:45:13 -07:00
|
|
|
//@returns The cumulative AD value representing buying/selling pressure
|
|
|
|
|
ad(src_high = high, src_low = low, src_close = close, src_vol = volume) =>
|
2026-01-31 11:21:09 -08:00
|
|
|
float mfm = 0.0
|
|
|
|
|
if not na(src_high) and not na(src_low) and not na(src_close)
|
|
|
|
|
mfm := (src_close - src_low) - (src_high - src_close)
|
|
|
|
|
mfm := src_high != src_low ? mfm / (src_high - src_low) : 0.0
|
|
|
|
|
float mfv = na(src_vol) ? 0.0 : src_vol * mfm
|
|
|
|
|
var float cumulativeSum = 0.0
|
|
|
|
|
cumulativeSum := na(mfv) ? cumulativeSum : cumulativeSum + mfv
|
|
|
|
|
cumulativeSum
|
|
|
|
|
|
|
|
|
|
// ---------- Inputs ----------
|
|
|
|
|
|
|
|
|
|
// ---------- Calculations ----------
|
2026-03-16 12:45:13 -07:00
|
|
|
ad_val = ad(high, low, close, volume)
|
2026-01-31 11:21:09 -08:00
|
|
|
|
|
|
|
|
// ---------- Plotting ----------
|
2026-03-16 12:45:13 -07:00
|
|
|
plot(ad_val, "AD", color=color.yellow, linewidth=2)
|