Merge branch 'dev' into main

This commit is contained in:
Miha Kralj
2026-03-16 12:46:19 -07:00
131 changed files with 1582 additions and 1583 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ Volume is market fuel. Price tells what happened; volume tells how hard the mark
| Indicator | Full Name | Description |
| :--- | :--- | :--- |
| [ADL](adl/Adl.md) | Accumulation/Distribution Line | Correlates price location within range to volume. Grandfather of volume flow analysis. |
| [AD](ad/Ad.md) | Accumulation/Distribution Line | Correlates price location within range to volume. Grandfather of volume flow analysis. |
| [ADOSC](adosc/Adosc.md) | Chaikin A/D Oscillator | Momentum indicator for AD Line. Predicts reversals by measuring acceleration of money flow. |
| [AOBV](aobv/Aobv.md) | Archer On-Balance Volume | Dual EMA smoothing of OBV for cleaner crossover signals. |
| [CMF](cmf/Cmf.md) | Chaikin Money Flow | Measures money flow volume over set period (typically 20-21 days). |
@@ -27,7 +27,7 @@ Volume is market fuel. Price tells what happened; volume tells how hard the mark
| [VF](vf/Vf.md) | Volume Force | Measures force of volume behind price movements using EMA smoothing. |
| [VO](vo/Vo.md) | Volume Oscillator | Difference between short and long volume moving averages. Shows volume momentum. |
| [VROC](vroc/Vroc.md) | Volume Rate of Change | Measures speed at which volume is changing over time. |
| [VWAD](vwad/Vwad.md) | Volume Weighted A/D | Similar to ADL but weights accumulation/distribution by volume. |
| [VWAD](vwad/Vwad.md) | Volume Weighted A/D | Similar to AD but weights accumulation/distribution by volume. |
| [VWAP](vwap/Vwap.md) | Volume Weighted Average Price | Average price weighted by volume. Common execution benchmark and intraday reference. |
| [VWMA](vwma/Vwma.md) | Volume Weighted Moving Average | Moving average where each price point is weighted by its volume over a sliding window. |
| [WAD](wad/Wad.md) | Williams Accumulation/Distribution | Measures cumulative buying/selling pressure using True Range and volume. |
@@ -5,35 +5,35 @@ using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
public sealed class AdlIndicator : Indicator, IWatchlistIndicator
public sealed class AdIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Adl _adl = null!;
private Ad _ad = null!;
private readonly LineSeries _series;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => "ADL";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/volume/adl/Adl.Quantower.cs";
public override string ShortName => "AD";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/volume/ad/Ad.Quantower.cs";
public AdlIndicator()
public AdIndicator()
{
OnBackGround = true;
SeparateWindow = true;
Name = "ADL - Accumulation/Distribution Line";
Name = "AD - Accumulation/Distribution Line";
Description = "Accumulation/Distribution Line";
_series = new LineSeries(name: "ADL", color: Color.Blue, width: 2, style: LineStyle.Solid);
_series = new LineSeries(name: "AD", color: Color.Blue, width: 2, style: LineStyle.Solid);
AddLineSeries(_series);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_adl = new Adl();
_ad = new Ad();
base.OnInit();
}
@@ -41,8 +41,8 @@ public sealed class AdlIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
TBar bar = this.GetInputBar(args);
TValue result = _adl.Update(bar, args.IsNewBar());
TValue result = _ad.Update(bar, args.IsNewBar());
_series.SetValue(result.Value, _adl.IsHot, ShowColdValues);
_series.SetValue(result.Value, _ad.IsHot, ShowColdValues);
}
}
+23 -23
View File
@@ -4,33 +4,33 @@ using System.Numerics;
namespace QuanTAlib;
/// <summary>
/// ADL: Accumulation/Distribution Line
/// AD: Accumulation/Distribution Line
/// </summary>
/// <remarks>
/// Cumulative indicator using volume and price to assess accumulation or distribution.
/// Rising ADL confirms accumulation; falling confirms distribution.
/// Rising AD confirms accumulation; falling confirms distribution.
///
/// Calculation: <c>MFM = [(Close - Low) - (High - Close)] / (High - Low)</c>,
/// <c>MFV = MFM × Volume</c>, <c>ADL = prev_ADL + MFV</c>. If High equals Low, MFM is 0.
/// <c>MFV = MFM × Volume</c>, <c>AD = prev_AD + MFV</c>. If High equals Low, MFM is 0.
/// </remarks>
/// <seealso href="Adl.md">Detailed documentation</seealso>
/// <seealso href="adl.pine">Reference Pine Script implementation</seealso>
/// <seealso href="Ad.md">Detailed documentation</seealso>
/// <seealso href="ad.pine">Reference Pine Script implementation</seealso>
[SkipLocalsInit]
public sealed class Adl : ITValuePublisher
public sealed class Ad : ITValuePublisher
{
private double _adl;
private double _p_adl;
private double _ad;
private double _p_ad;
private bool _isInitialized;
/// <summary>
/// Display name for the indicator.
/// </summary>
public static string Name => "ADL";
public static string Name => "AD";
public event TValuePublishedHandler? Pub;
/// <summary>
/// Current ADL value.
/// Current AD value.
/// </summary>
public TValue Last { get; private set; }
@@ -45,9 +45,9 @@ public sealed class Adl : ITValuePublisher
public bool IsHot => _isInitialized;
/// <summary>
/// Creates a new ADL indicator.
/// Creates a new AD indicator.
/// </summary>
public Adl()
public Ad()
{
_isInitialized = false;
}
@@ -58,8 +58,8 @@ public sealed class Adl : ITValuePublisher
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Reset()
{
_adl = 0;
_p_adl = 0;
_ad = 0;
_p_ad = 0;
_isInitialized = false;
Last = default;
}
@@ -69,11 +69,11 @@ public sealed class Adl : ITValuePublisher
{
if (isNew)
{
_p_adl = _adl;
_p_ad = _ad;
}
else
{
_adl = _p_adl;
_ad = _p_ad;
}
double highLowRange = input.High - input.Low;
@@ -85,19 +85,19 @@ public sealed class Adl : ITValuePublisher
}
double mfv = mfm * input.Volume;
_adl += mfv;
_ad += mfv;
_isInitialized = true;
Last = new TValue(input.Time, _adl);
Last = new TValue(input.Time, _ad);
Pub?.Invoke(this, new TValueEventArgs { Value = Last, IsNew = isNew });
return Last;
}
/// <summary>
/// Updates ADL with a TValue input.
/// Updates AD with a TValue input.
/// </summary>
/// <exception cref="NotSupportedException">
/// ADL requires OHLCV bar data to calculate the Money Flow Multiplier and Volume.
/// AD requires OHLCV bar data to calculate the Money Flow Multiplier and Volume.
/// Use Update(TBar) instead.
/// </exception>
#pragma warning disable S2325 // Method signature must match ITValuePublisher contract
@@ -105,7 +105,7 @@ public sealed class Adl : ITValuePublisher
#pragma warning restore S2325
{
throw new NotSupportedException(
"ADL requires OHLCV bar data to calculate the Money Flow Multiplier and Volume. " +
"AD requires OHLCV bar data to calculate the Money Flow Multiplier and Volume. " +
"Use Update(TBar) instead.");
}
@@ -219,9 +219,9 @@ public sealed class Adl : ITValuePublisher
}
}
public static (TSeries Results, Adl Indicator) Calculate(TBarSeries source)
public static (TSeries Results, Ad Indicator) Calculate(TBarSeries source)
{
var indicator = new Adl();
var indicator = new Ad();
TSeries results = indicator.Update(source);
return (results, indicator);
}
+16 -16
View File
@@ -1,4 +1,4 @@
# ADL: Accumulation/Distribution Line
# AD: Accumulation/Distribution Line
> *Volume precedes price.*
@@ -7,26 +7,26 @@
| **Category** | Volume |
| **Inputs** | OHLCV bar (TBar) |
| **Parameters** | None |
| **Outputs** | Single series (ADL) |
| **Outputs** | Single series (AD) |
| **Output range** | Unbounded |
| **Warmup** | 1 bar |
| **PineScript** | [adl.pine](adl.pine) |
| **PineScript** | [ad.pine](ad.pine) |
- The Accumulation/Distribution Line (ADL) is the bedrock of volume analysis.
- The Accumulation/Distribution Line (AD) is the bedrock of volume analysis.
- No configurable parameters; computation is stateless per bar.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Accumulation/Distribution Line (ADL) is the bedrock of volume analysis. It attempts to answer a single, vital question: "Are the big players buying or selling?"
The Accumulation/Distribution Line (AD) is the bedrock of volume analysis. It attempts to answer a single, vital question: "Are the big players buying or selling?"
Unlike On-Balance Volume (OBV), which treats every up-day as 100% buying, ADL is nuanced. It looks at *where* the price closed within the day's range. A close near the high on massive volume screams "Accumulation." A close near the low on massive volume screams "Distribution."
Unlike On-Balance Volume (OBV), which treats every up-day as 100% buying, AD is nuanced. It looks at *where* the price closed within the day's range. A close near the high on massive volume screams "Accumulation." A close near the low on massive volume screams "Distribution."
## Historical Context
Developed by Marc Chaikin, the ADL was originally designed to spot divergences. Chaikin noticed that if a stock made a new high but the ADL failed to make a new high, a crash was imminent. He essentially quantified the "smart money" flow.
Developed by Marc Chaikin, the AD was originally designed to spot divergences. Chaikin noticed that if a stock made a new high but the AD failed to make a new high, a crash was imminent. He essentially quantified the "smart money" flow.
## Architecture & Physics
ADL is a cumulative indicator, meaning it has infinite memory. Today's value depends on the sum of all yesterdays.
AD is a cumulative indicator, meaning it has infinite memory. Today's value depends on the sum of all yesterdays.
The core mechanic is the **Money Flow Multiplier (MFM)**, also known as the Close Location Value (CLV). This value ranges from -1 to +1:
@@ -50,23 +50,23 @@ $$
MFV = MFM \times Volume
$$
### 3. Accumulation/Distribution Line (ADL)
### 3. Accumulation/Distribution Line (AD)
$$
ADL_t = ADL_{t-1} + MFV_t
AD_t = AD_{t-1} + MFV_t
$$
## Performance Profile
### Operation Count (Streaming Mode)
ADL computes Money Flow Multiplier (MFM) from bar data, multiplies by volume, and accumulates cumulatively — O(1).
AD computes Money Flow Multiplier (MFM) from bar data, multiplies by volume, and accumulates cumulatively — O(1).
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MFM = ((C-L)-(H-C)) / (H-L) | 1 | 5 cy | ~5 cy |
| MFV = MFM * Volume | 1 | 3 cy | ~3 cy |
| ADL += MFV (cumulative sum) | 1 | 1 cy | ~1 cy |
| AD += MFV (cumulative sum) | 1 | 1 cy | ~1 cy |
| Zero guard on H-L | 1 | 2 cy | ~2 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~13 cy** |
@@ -89,12 +89,12 @@ O(1) cumulative indicator — no window, no buffer. Throughput ~4 ns/bar. Divisi
| :--- | :--- | :--- |
| **QuanTAlib** | ✅ | Validated. |
| **TA-Lib** | ✅ | Matches `TA_AD` exactly. |
| **Skender** | ✅ | Matches `GetAdl` exactly. |
| **Skender** | ✅ | Matches `GetAd` exactly. |
| **Tulip** | ✅ | Matches `ad` exactly. |
| **Ooples** | ✅ | Matches `CalculateAccumulationDistributionLine`. |
### Common Pitfalls
* **Gaps**: ADL ignores gaps. If a stock gaps up but closes near its low, ADL will register distribution, even if the price is higher than yesterday.
* **Scale**: The absolute value of ADL is meaningless; it depends on the start date of the data. Only the *trend* and *divergence* matter.
* **Volume Spikes**: A single bad data point with erroneous volume can permanently skew the ADL. Sanitize your data.
* **Gaps**: AD ignores gaps. If a stock gaps up but closes near its low, AD will register distribution, even if the price is higher than yesterday.
* **Scale**: The absolute value of AD is meaningless; it depends on the start date of the data. Only the *trend* and *divergence* matter.
* **Volume Spikes**: A single bad data point with erroneous volume can permanently skew the AD. Sanitize your data.
@@ -1,15 +1,15 @@
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Accumulation/Distribution Line (ADL)", "ADL", overlay=false)
indicator("Accumulation/Distribution Line (AD)", "AD", overlay=false)
//@function Calculates the Accumulation/Distribution Line (ADL), a volume-based indicator that measures money flow into and out of a security
//@function Calculates the Accumulation/Distribution Line (AD), a volume-based indicator that measures money flow into and out of a security
//@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)
//@returns The cumulative ADL value representing buying/selling pressure
adl(src_high = high, src_low = low, src_close = close, src_vol = volume) =>
//@returns The cumulative AD value representing buying/selling pressure
ad(src_high = high, src_low = low, src_close = close, src_vol = volume) =>
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)
@@ -22,7 +22,7 @@ adl(src_high = high, src_low = low, src_close = close, src_vol = volume) =>
// ---------- Inputs ----------
// ---------- Calculations ----------
adl_val = adl(high, low, close, volume)
ad_val = ad(high, low, close, volume)
// ---------- Plotting ----------
plot(adl_val, "ADL", color=color.yellow, linewidth=2)
plot(ad_val, "AD", color=color.yellow, linewidth=2)
@@ -3,39 +3,39 @@ using QuanTAlib;
namespace QuanTAlib.Tests;
public class AdlIndicatorTests
public class AdIndicatorTests
{
[Fact]
public void AdlIndicator_Constructor_SetsDefaults()
public void AdIndicator_Constructor_SetsDefaults()
{
var indicator = new AdlIndicator();
var indicator = new AdIndicator();
Assert.Equal("ADL - Accumulation/Distribution Line", indicator.Name);
Assert.Equal("AD - Accumulation/Distribution Line", indicator.Name);
Assert.True(indicator.SeparateWindow);
Assert.True(indicator.OnBackGround);
Assert.Equal(0, AdlIndicator.MinHistoryDepths);
Assert.Equal(0, AdIndicator.MinHistoryDepths);
}
[Fact]
public void AdlIndicator_ShortName_IsCorrect()
public void AdIndicator_ShortName_IsCorrect()
{
var indicator = new AdlIndicator();
Assert.Equal("ADL", indicator.ShortName);
var indicator = new AdIndicator();
Assert.Equal("AD", indicator.ShortName);
}
[Fact]
public void AdlIndicator_MinHistoryDepths_EqualsZero()
public void AdIndicator_MinHistoryDepths_EqualsZero()
{
var indicator = new AdlIndicator();
var indicator = new AdIndicator();
Assert.Equal(0, AdlIndicator.MinHistoryDepths);
Assert.Equal(0, AdIndicator.MinHistoryDepths);
Assert.Equal(0, ((IWatchlistIndicator)indicator).MinHistoryDepths);
}
[Fact]
public void AdlIndicator_Initialize_CreatesInternalAdl()
public void AdIndicator_Initialize_CreatesInternalAd()
{
var indicator = new AdlIndicator();
var indicator = new AdIndicator();
// Initialize should not throw
indicator.Initialize();
@@ -45,9 +45,9 @@ public class AdlIndicatorTests
}
[Fact]
public void AdlIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
public void AdIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
{
var indicator = new AdlIndicator();
var indicator = new AdIndicator();
indicator.Initialize();
// Add historical data
@@ -67,9 +67,9 @@ public class AdlIndicatorTests
}
[Fact]
public void AdlIndicator_ProcessUpdate_NewBar_ComputesValue()
public void AdIndicator_ProcessUpdate_NewBar_ComputesValue()
{
var indicator = new AdlIndicator();
var indicator = new AdIndicator();
indicator.Initialize();
var now = DateTime.UtcNow;
@@ -1,122 +1,122 @@
namespace QuanTAlib.Tests;
public class AdlTests
public class AdTests
{
[Fact]
public void Adl_BasicCalculation_ReturnsExpectedValues()
public void Ad_BasicCalculation_ReturnsExpectedValues()
{
// Arrange
var adl = new Adl();
var ad = new Ad();
var time = DateTime.UtcNow;
// Bar 1: Close=10, High=12, Low=8. Range=4.
// MFM = ((10-8) - (12-10)) / 4 = (2 - 2) / 4 = 0.
// Vol = 100. MFV = 0. ADL = 0.
// Vol = 100. MFV = 0. AD = 0.
var bar1 = new TBar(time, 10, 12, 8, 10, 100);
var val1 = adl.Update(bar1);
var val1 = ad.Update(bar1);
Assert.Equal(0, val1.Value);
// Bar 2: Close=12, High=12, Low=8. Range=4.
// MFM = ((12-8) - (12-12)) / 4 = (4 - 0) / 4 = 1.
// Vol = 200. MFV = 200. ADL = 0 + 200 = 200.
// Vol = 200. MFV = 200. AD = 0 + 200 = 200.
var bar2 = new TBar(time.AddMinutes(1), 10, 12, 8, 12, 200);
var val2 = adl.Update(bar2);
var val2 = ad.Update(bar2);
Assert.Equal(200, val2.Value);
// Bar 3: Close=8, High=12, Low=8. Range=4.
// MFM = ((8-8) - (12-8)) / 4 = (0 - 4) / 4 = -1.
// Vol = 100. MFV = -100. ADL = 200 - 100 = 100.
// Vol = 100. MFV = -100. AD = 200 - 100 = 100.
var bar3 = new TBar(time.AddMinutes(2), 12, 12, 8, 8, 100);
var val3 = adl.Update(bar3);
var val3 = ad.Update(bar3);
Assert.Equal(100, val3.Value);
}
[Fact]
public void Adl_IsNew_False_UpdatesSameBar()
public void Ad_IsNew_False_UpdatesSameBar()
{
var adl = new Adl();
var ad = new Ad();
var time = DateTime.UtcNow;
// Initial update
// MFM = 1, Vol = 100 -> ADL = 100
// MFM = 1, Vol = 100 -> AD = 100
var bar1 = new TBar(time, 10, 12, 8, 12, 100);
adl.Update(bar1, isNew: true);
Assert.Equal(100, adl.Last.Value);
ad.Update(bar1, isNew: true);
Assert.Equal(100, ad.Last.Value);
// Update same bar with different volume
// MFM = 1, Vol = 200 -> ADL = 200 (replaces previous 100)
// MFM = 1, Vol = 200 -> AD = 200 (replaces previous 100)
var bar1Update = new TBar(time, 10, 12, 8, 12, 200);
adl.Update(bar1Update, isNew: false);
Assert.Equal(200, adl.Last.Value);
ad.Update(bar1Update, isNew: false);
Assert.Equal(200, ad.Last.Value);
}
[Fact]
public void Adl_Reset_ClearsState()
public void Ad_Reset_ClearsState()
{
var adl = new Adl();
var ad = new Ad();
var bar = new TBar(DateTime.UtcNow, 10, 12, 8, 12, 100);
adl.Update(bar);
ad.Update(bar);
Assert.True(adl.IsHot);
Assert.NotEqual(0, adl.Last.Value);
Assert.True(ad.IsHot);
Assert.NotEqual(0, ad.Last.Value);
adl.Reset();
Assert.False(adl.IsHot);
Assert.Equal(0, adl.Last.Value);
ad.Reset();
Assert.False(ad.IsHot);
Assert.Equal(0, ad.Last.Value);
}
[Fact]
public void Adl_HighEqualsLow_HandlesDivisionByZero()
public void Ad_HighEqualsLow_HandlesDivisionByZero()
{
var adl = new Adl();
var ad = new Ad();
// High = Low = 10. Range = 0. MFM should be 0.
var bar = new TBar(DateTime.UtcNow, 10, 10, 10, 10, 100);
var val = adl.Update(bar);
var val = ad.Update(bar);
Assert.Equal(0, val.Value);
}
[Fact]
public void Adl_TValueUpdate_ThrowsNotSupportedException()
public void Ad_TValueUpdate_ThrowsNotSupportedException()
{
var adl = new Adl();
var ad = new Ad();
var bar = new TBar(DateTime.UtcNow, 10, 12, 8, 12, 100);
adl.Update(bar); // ADL = 100
ad.Update(bar); // AD = 100
// Update with TValue should throw since ADL requires OHLCV bar data
Assert.Throws<NotSupportedException>(() => adl.Update(new TValue(DateTime.UtcNow, 15)));
// Update with TValue should throw since AD requires OHLCV bar data
Assert.Throws<NotSupportedException>(() => ad.Update(new TValue(DateTime.UtcNow, 15)));
}
[Fact]
public void Adl_Name_IsCorrect()
public void Ad_Name_IsCorrect()
{
Assert.Equal("ADL", Adl.Name);
Assert.Equal("AD", Ad.Name);
}
[Fact]
public void Adl_PubEvent_FiresOnUpdate()
public void Ad_PubEvent_FiresOnUpdate()
{
var adl = new Adl();
var ad = new Ad();
bool eventFired = false;
adl.Pub += (object? sender, in TValueEventArgs args) => eventFired = true;
ad.Pub += (object? sender, in TValueEventArgs args) => eventFired = true;
adl.Update(new TBar(DateTime.UtcNow, 10, 12, 8, 10, 100));
ad.Update(new TBar(DateTime.UtcNow, 10, 12, 8, 10, 100));
Assert.True(eventFired);
}
[Fact]
public void Adl_UpdateTBarSeries_ReturnsCorrectSeries()
public void Ad_UpdateTBarSeries_ReturnsCorrectSeries()
{
var adl = new Adl();
var ad = new Ad();
var bars = new TBarSeries();
var time = DateTime.UtcNow;
// Add same bars as in BasicCalculation
bars.Add(new TBar(time, 10, 12, 8, 10, 100)); // ADL=0
bars.Add(new TBar(time.AddMinutes(1), 10, 12, 8, 12, 200)); // ADL=200
bars.Add(new TBar(time.AddMinutes(2), 12, 12, 8, 8, 100)); // ADL=100
bars.Add(new TBar(time, 10, 12, 8, 10, 100)); // AD=0
bars.Add(new TBar(time.AddMinutes(1), 10, 12, 8, 12, 200)); // AD=200
bars.Add(new TBar(time.AddMinutes(2), 12, 12, 8, 8, 100)); // AD=100
var result = adl.Update(bars);
var result = ad.Update(bars);
Assert.Equal(3, result.Count);
Assert.Equal(0, result[0].Value);
@@ -125,7 +125,7 @@ public class AdlTests
}
[Fact]
public void Adl_CalculateTBarSeries_ReturnsCorrectSeries()
public void Ad_CalculateTBarSeries_ReturnsCorrectSeries()
{
var bars = new TBarSeries();
var time = DateTime.UtcNow;
@@ -134,7 +134,7 @@ public class AdlTests
bars.Add(new TBar(time.AddMinutes(1), 10, 12, 8, 12, 200));
bars.Add(new TBar(time.AddMinutes(2), 12, 12, 8, 8, 100));
var result = Adl.Batch(bars);
var result = Ad.Batch(bars);
Assert.Equal(3, result.Count);
Assert.Equal(0, result[0].Value);
@@ -143,7 +143,7 @@ public class AdlTests
}
[Fact]
public void Adl_CalculateSpan_ReturnsCorrectValues()
public void Ad_CalculateSpan_ReturnsCorrectValues()
{
double[] high = { 12, 12, 12 };
double[] low = { 8, 8, 8 };
@@ -151,7 +151,7 @@ public class AdlTests
double[] volume = { 100, 200, 100 };
double[] output = new double[3];
Adl.Batch(high, low, close, volume, output);
Ad.Batch(high, low, close, volume, output);
Assert.Equal(0, output[0]);
Assert.Equal(200, output[1]);
@@ -159,7 +159,7 @@ public class AdlTests
}
[Fact]
public void Adl_CalculateSpan_ThrowsOnMismatchedLengths()
public void Ad_CalculateSpan_ThrowsOnMismatchedLengths()
{
double[] high = { 10, 11 };
double[] low = { 9, 10 };
@@ -168,19 +168,19 @@ public class AdlTests
double[] output = new double[2];
Assert.Throws<ArgumentException>(() =>
Adl.Batch(high, low, close, volume, output));
Ad.Batch(high, low, close, volume, output));
}
[Fact]
public void Adl_Calculate_EmptySeries_ReturnsEmpty()
public void Ad_Calculate_EmptySeries_ReturnsEmpty()
{
var bars = new TBarSeries();
var result = Adl.Batch(bars);
var result = Ad.Batch(bars);
Assert.Empty(result);
}
[Fact]
public void Adl_CalculateSpan_SimdPath_ReturnsCorrectValues()
public void Ad_CalculateSpan_SimdPath_ReturnsCorrectValues()
{
const int count = 100; // Enough to trigger SIMD
double[] high = new double[count];
@@ -190,7 +190,7 @@ public class AdlTests
double[] output = new double[count];
// Setup: High=12, Low=8, Close=12 (MFM=1), Vol=10
// Expected ADL increments by 10 each step.
// Expected AD increments by 10 each step.
for (int i = 0; i < count; i++)
{
high[i] = 12;
@@ -199,7 +199,7 @@ public class AdlTests
volume[i] = 10;
}
Adl.Batch(high, low, close, volume, output);
Ad.Batch(high, low, close, volume, output);
for (int i = 0; i < count; i++)
{
@@ -4,35 +4,35 @@ using OoplesFinance.StockIndicators.Models;
namespace QuanTAlib.Tests;
public class AdlValidationTests
public class AdValidationTests
{
private readonly ValidationTestData _data;
public AdlValidationTests()
public AdValidationTests()
{
_data = new ValidationTestData();
}
[Fact]
public void Adl_Matches_Skender()
public void Ad_Matches_Skender()
{
// Skender
var skenderResults = _data.SkenderQuotes.GetAdl();
var skenderValues = skenderResults.Select(x => x.Adl).ToArray();
// QuanTAlib
var adl = new Adl();
var ad = new Ad();
var quantalibValues = new List<double>();
foreach (var bar in _data.Bars)
{
quantalibValues.Add(adl.Update(bar).Value);
quantalibValues.Add(ad.Update(bar).Value);
}
ValidationHelper.VerifyData(quantalibValues.ToArray(), skenderValues, 0, 100, ValidationHelper.SkenderTolerance);
}
[Fact]
public void Adl_Matches_Talib()
public void Ad_Matches_Talib()
{
// TA-Lib
var high = _data.Bars.High.Values.ToArray();
@@ -45,18 +45,18 @@ public class AdlValidationTests
Assert.Equal(TALib.Core.RetCode.Success, retCode);
// QuanTAlib
var adl = new Adl();
var ad = new Ad();
var quantalibValues = new List<double>();
foreach (var bar in _data.Bars)
{
quantalibValues.Add(adl.Update(bar).Value);
quantalibValues.Add(ad.Update(bar).Value);
}
ValidationHelper.VerifyData(quantalibValues.ToArray(), talibValues, outRange, 0, 100, ValidationHelper.TalibTolerance);
}
[Fact]
public void Adl_Matches_Tulip()
public void Ad_Matches_Tulip()
{
// Tulip
var high = _data.Bars.High.Values.ToArray();
@@ -73,18 +73,18 @@ public class AdlValidationTests
var tulipValues = outputs[0];
// QuanTAlib
var adl = new Adl();
var ad = new Ad();
var quantalibValues = new List<double>();
foreach (var bar in _data.Bars)
{
quantalibValues.Add(adl.Update(bar).Value);
quantalibValues.Add(ad.Update(bar).Value);
}
ValidationHelper.VerifyData(quantalibValues.ToArray(), tulipValues, 0, 100, ValidationHelper.TulipTolerance);
}
[Fact]
public void Adl_Matches_Ooples()
public void Ad_Matches_Ooples()
{
// Ooples
var ooplesData = _data.SkenderQuotes.Select(q => new TickerData
@@ -102,11 +102,11 @@ public class AdlValidationTests
var oValues = oResult.OutputValues["Adl"];
// QuanTAlib
var adl = new Adl();
var ad = new Ad();
var quantalibValues = new List<double>();
foreach (var bar in _data.Bars)
{
quantalibValues.Add(adl.Update(bar).Value);
quantalibValues.Add(ad.Update(bar).Value);
}
ValidationHelper.VerifyData(quantalibValues.ToArray(), oValues.ToArray(), 0, 100, ValidationHelper.OoplesTolerance);
+4 -4
View File
@@ -16,7 +16,7 @@ namespace QuanTAlib;
[SkipLocalsInit]
public sealed class Adosc : ITValuePublisher
{
private readonly Adl _adl;
private readonly Ad _ad;
private readonly Ema _emaFast;
private readonly Ema _emaSlow;
@@ -64,7 +64,7 @@ public sealed class Adosc : ITValuePublisher
throw new ArgumentException("Fast period must be less than slow period", nameof(fastPeriod));
}
_adl = new Adl();
_ad = new Ad();
_emaFast = new Ema(fastPeriod);
_emaSlow = new Ema(slowPeriod);
WarmupPeriod = slowPeriod;
@@ -77,7 +77,7 @@ public sealed class Adosc : ITValuePublisher
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Reset()
{
_adl.Reset();
_ad.Reset();
_emaFast.Reset();
_emaSlow.Reset();
Last = default;
@@ -110,7 +110,7 @@ public sealed class Adosc : ITValuePublisher
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue Update(TBar input, bool isNew = true)
{
var adl = _adl.Update(input, isNew);
var adl = _ad.Update(input, isNew);
return Update(adl, isNew);
}
+1 -1
View File
@@ -27,7 +27,7 @@ public sealed class VwadIndicator : Indicator, IWatchlistIndicator
OnBackGround = true;
SeparateWindow = true;
Name = "VWAD - Volume Weighted Accumulation/Distribution";
Description = "Volume Weighted Accumulation/Distribution enhances ADL by weighting each bar's contribution based on relative volume";
Description = "Volume Weighted Accumulation/Distribution enhances AD by weighting each bar's contribution based on relative volume";
_series = new LineSeries(name: "VWAD", color: Color.Yellow, width: 2, style: LineStyle.Solid);
AddLineSeries(_series);
+1 -1
View File
@@ -8,7 +8,7 @@ namespace QuanTAlib;
/// each bar's contribution based on its volume relative to the rolling volume sum.
/// </summary>
/// <remarks>
/// VWAD enhances ADL by weighting volume contributions:
/// VWAD enhances AD by weighting volume contributions:
/// <c>MFM = [(Close - Low) - (High - Close)] / (High - Low)</c>,
/// <c>VolWeight = Volume / Σ(Volume, period)</c>,
/// <c>VWAD = Σ(Volume × MFM × VolWeight)</c>.