mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-09 06:27:45 +00:00
xml doc rewrite
This commit is contained in:
+41
-8
@@ -1,14 +1,47 @@
|
||||
using System;
|
||||
namespace QuanTAlib;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Chande Momentum Oscillator (CMO) calculator.
|
||||
/// CMO: Chande Momentum Oscillator
|
||||
/// A technical momentum indicator that measures the difference between upward and
|
||||
/// downward momentum. CMO helps identify overbought and oversold conditions, as
|
||||
/// well as trend strength and potential reversals.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The CMO calculation process:
|
||||
/// 1. Calculates price differences from previous period
|
||||
/// 2. Separates positive (upward) and negative (downward) movements
|
||||
/// 3. Sums upward and downward movements over period
|
||||
/// 4. Calculates: 100 * ((sumUp - sumDown) / (sumUp + sumDown))
|
||||
///
|
||||
/// Key characteristics:
|
||||
/// - Oscillates between -100 and +100
|
||||
/// - Values above +50 indicate overbought
|
||||
/// - Values below -50 indicate oversold
|
||||
/// - Zero line crossovers signal trend changes
|
||||
/// - High absolute values suggest strong trends
|
||||
///
|
||||
/// Formula:
|
||||
/// CMO = 100 * ((ΣUp - ΣDown) / (ΣUp + ΣDown))
|
||||
/// where:
|
||||
/// Up = positive price changes
|
||||
/// Down = absolute negative price changes
|
||||
///
|
||||
/// Sources:
|
||||
/// Tushar Chande - "The New Technical Trader" (1994)
|
||||
/// https://www.investopedia.com/terms/c/chandemomentumoscillator.asp
|
||||
///
|
||||
/// Note: Similar to RSI but with different scaling and calculation method
|
||||
/// </remarks>
|
||||
|
||||
public class Cmo : AbstractBase
|
||||
{
|
||||
private readonly CircularBuffer _sumH;
|
||||
private readonly CircularBuffer _sumL;
|
||||
private double _prevValue, _p_prevValue;
|
||||
|
||||
/// <param name="period">The number of periods used in the CMO calculation.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||
public Cmo(int period)
|
||||
{
|
||||
if (period < 1)
|
||||
@@ -16,15 +49,12 @@ public class Cmo : AbstractBase
|
||||
_sumH = new(period);
|
||||
_sumL = new(period);
|
||||
|
||||
WarmupPeriod = period+1;
|
||||
WarmupPeriod = period + 1;
|
||||
Name = $"CMO({period})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the CMO class with a data source.
|
||||
/// </summary>
|
||||
/// <param name="source">The source object that publishes data.</param>
|
||||
/// <param name="period">The number of data points to consider.</param>
|
||||
/// <param name="source">The data source object that publishes updates.</param>
|
||||
/// <param name="period">The number of periods used in the CMO calculation.</param>
|
||||
public Cmo(object source, int period) : this(period)
|
||||
{
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
@@ -53,9 +83,11 @@ public class Cmo : AbstractBase
|
||||
_prevValue = Input.Value;
|
||||
}
|
||||
|
||||
// Calculate price difference
|
||||
double diff = Input.Value - _prevValue;
|
||||
_prevValue = Input.Value;
|
||||
|
||||
// Separate upward and downward movements
|
||||
if (diff > 0)
|
||||
{
|
||||
_sumH.Add(diff, Input.IsNew);
|
||||
@@ -67,11 +99,12 @@ public class Cmo : AbstractBase
|
||||
_sumL.Add(-diff, Input.IsNew);
|
||||
}
|
||||
|
||||
// Calculate sums for the specified period only
|
||||
// Calculate sums for the specified period
|
||||
double sumH = _sumH.Sum();
|
||||
double sumL = _sumL.Sum();
|
||||
double divisor = sumH + sumL;
|
||||
|
||||
// Calculate CMO value
|
||||
return (Math.Abs(divisor) > double.Epsilon) ?
|
||||
100.0 * ((sumH - sumL) / divisor) :
|
||||
0.0;
|
||||
|
||||
Reference in New Issue
Block a user