mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-08 14:07:44 +00:00
ADO with tests and fixed abstracts
This commit is contained in:
@@ -145,16 +145,21 @@ public abstract class Single_TBars_Indicator : TSeries
|
||||
}
|
||||
|
||||
// overridable Add() method to add/update a single item at the end of the list
|
||||
public virtual void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar, bool update) => base.Add((TBar.t, TBar.c), update);
|
||||
public virtual void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar, bool update) => base.Add((TBar.t, 0.0), update);
|
||||
|
||||
// potentially overridable Add() method for the whole series (could be replaced with faster bulk algo)
|
||||
// potentially overridable Add() method for the whole bars or series (could be replaced with faster bulk algo)
|
||||
public virtual void Add(TBars bars)
|
||||
{
|
||||
for (int i = 0; i < bars.Count; i++) { this.Add(TBar: bars[i], update: false); }
|
||||
}
|
||||
|
||||
public new void Add((System.DateTime t, double v) TValue)
|
||||
=> this.Add(TValue: TValue, update: false);
|
||||
public virtual void Add(TSeries data)
|
||||
{
|
||||
for (int i = 0; i < data.Count; i++) { base.Add(TValue: data[i], update: false); }
|
||||
}
|
||||
|
||||
public new void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar)
|
||||
=> this.Add(TBar: TBar, update: false);
|
||||
public void Add(bool update)
|
||||
=> this.Add(TBar: this._bars[this._bars.Count - 1], update: update);
|
||||
public void Add()
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace QuanTAlib;
|
||||
using System;
|
||||
|
||||
/* <summary>
|
||||
ADO: Chaikin Accumulation/Distribution Oscillator
|
||||
ADO measures the momentum of ADL using the difference between slow (10-day) EMA(ADL)
|
||||
and fast (3-day) EMA(ADL):
|
||||
|
||||
Chaikin A/D Oscillator = (3-day EMA of ADL) - (10-day EMA of ADL)
|
||||
|
||||
Sources:
|
||||
https://school.stockcharts.com/doku.php?id=technical_indicators:chaikin_oscillator
|
||||
|
||||
</summary> */
|
||||
|
||||
public class ADO_Series : Single_TBars_Indicator
|
||||
{
|
||||
private readonly ADL_Series _TSadl;
|
||||
|
||||
private readonly EMA_Series _TSslow;
|
||||
private readonly EMA_Series _TSfast;
|
||||
private readonly SUB_Series _TSado;
|
||||
|
||||
public ADO_Series(TBars source, bool useNaN = false) : base(source, period: 0, useNaN)
|
||||
{
|
||||
_TSadl = new(source: source, useNaN: false);
|
||||
_TSslow = new(source: _TSadl, period: 10, useNaN: false);
|
||||
_TSfast = new(source: _TSadl, period: 3, useNaN: false);
|
||||
_TSado = new(_TSfast, _TSslow);
|
||||
|
||||
if (source.Count > 0)
|
||||
{ base.Add(_TSado); }
|
||||
Console.WriteLine(base.Count);
|
||||
}
|
||||
|
||||
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update)
|
||||
{
|
||||
if (update)
|
||||
{ _TSadl.Add(TBar, true); }
|
||||
|
||||
double _ado = this._TSado[(this.Count < this._TSado.Count) ? this.Count : this._TSado.Count - 1].v;
|
||||
var result = (TBar.t, _ado);
|
||||
base.Add(result, update);
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,14 @@ public class TA_LIB
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADO()
|
||||
{
|
||||
ADO_Series QL = new(this.bars, false);
|
||||
Core.AdOsc(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATR()
|
||||
|
||||
Reference in New Issue
Block a user