Files
QuanTAlib/lib/volume/adosc/adosc.pine
T
Miha Kralj 24e86d762a Add documentation links for various volatility indicators and channels
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links.
- Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
2026-02-18 11:55:48 -08:00

40 lines
1.7 KiB
Plaintext

// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Chaikin A/D Oscillator (ADOSC)", "ADOSC", overlay=false)
//@function Calculates the Chaikin Accumulation/Distribution Oscillator (ADOSC), a momentum indicator derived from the ADL
//@param shortPeriod (simple int) Length of the short-term EMA applied to the ADL
//@param longPeriod (simple int) Length of the long-term EMA applied to the ADL
//@returns (float) The ADOSC value for the current bar (difference between short and long EMAs of ADL)
adosc(simple int shortPeriod, simple int longPeriod) =>
float EPSILON = 1e-10
if shortPeriod <= 0 or longPeriod <= 0
runtime.error("Periods must be greater than 0")
short_alpha = 2.0 / (shortPeriod + 1)
long_alpha = 2.0 / (longPeriod + 1)
one_minus_long_alpha = 1.0 - long_alpha
float rng = high - low
float mf = rng != 0.0 ? ((2 * close - high - low) / rng) * volume : 0.0
var float cum = 0.0
var float e = 1.0
cum := bar_index == 0 ? mf : cum + mf
var float short_raw_ema = 0.0
short_raw_ema := short_alpha * (cum - short_raw_ema) + short_raw_ema
float short_ema = e > EPSILON ? short_raw_ema / (1.0 - e) : short_raw_ema
var float long_raw_ema = 0.0
long_raw_ema := long_alpha * (cum - long_raw_ema) + long_raw_ema
float long_ema = e > EPSILON ? long_raw_ema / (1.0 - e) : long_raw_ema
e := one_minus_long_alpha * e
short_ema - long_ema
// ---------- Inputs ----------
shortPeriod = input.int(3, "Short Period", minval=1)
longPeriod = input.int(10, "Long Period", minval=1)
// ---------- Calculations ----------
osc = adosc(shortPeriod, longPeriod)
// ---------- Plotting ----------
plot(osc, "ADOSC", color.new(color.yellow, 0, color=color.yellow, linewidth=2), linewidth=2)