Files
Miha Kralj 75c6a9f135 Enhance validation tests for various indicators with external library comparisons
- Added detailed comments explaining the validation limitations for MMA and ZLEMA due to differences in algorithm implementations.
- Implemented validation tests for True Range against TALib and Tulip, ensuring directional agreement.
- Updated Ulcer Index validation to clarify differences in algorithmic approaches between QuanTAlib and Skender.
- Enhanced Ease of Movement tests to verify directional agreement with Tulip's EMV, noting differences in volume scaling.
- Expanded Klinger Volume Oscillator tests to validate against Skender and Tulip, focusing on directional agreement across multiple period configurations.
- Improved Negative Volume Index tests to compare percentage changes with Tulip, addressing differences in starting values.
- Updated Positive Volume Index tests to validate against Tulip, emphasizing percentage change comparisons.
- Enhanced Williams Accumulation/Distribution tests to verify directional agreement with Tulip, highlighting formula differences.
2026-02-11 14:46:56 -08:00

86 lines
2.3 KiB
C#

using System.Drawing;
using TradingPlatform.BusinessLayer;
using static QuanTAlib.IndicatorExtensions;
namespace QuanTAlib;
/// <summary>
/// MOM (Momentum) Quantower indicator.
/// Calculates absolute price change over a lookback period.
/// Formula: current - past
/// </summary>
public class MomIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", 0, 1, 999, 1, 0)]
public int Period { get; set; } = 10;
[DataSourceInput]
public SourceType Source { get; set; } = SourceType.Close;
[InputParameter("Show Cold Values", sortIndex: 100)]
public bool ShowColdValues { get; set; } = true;
private Mom? _mom;
private Func<IHistoryItem, double>? _selector;
public int MinHistoryDepths => Period + 1;
public override string ShortName => $"MOM({Period})";
public MomIndicator()
{
Name = "MOM - Momentum";
Description = "Calculates absolute price change: current - past";
SeparateWindow = true;
OnBackGround = false;
}
protected override void OnInit()
{
_mom = new Mom(Period);
_selector = Source.GetPriceSelector();
AddLineSeries(new LineSeries("MOM", IndicatorExtensions.Momentum, 2, LineStyle.Histogramm));
AddLineSeries(new LineSeries("Zero", Color.Gray, 1, LineStyle.Dot));
}
protected override void OnUpdate(UpdateArgs args)
{
if (_mom == null || _selector == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
double value = _selector(item);
bool isNew = args.IsNewBar();
TValue input = new(item.TimeLeft, value);
_mom.Update(input, isNew);
bool isHot = _mom.IsHot;
LinesSeries[0].SetValue(_mom.Last.Value, isHot, ShowColdValues);
LinesSeries[1].SetValue(0);
if (isHot || ShowColdValues)
{
double mom = _mom.Last.Value;
Color color;
if (mom > 0)
{
color = Color.Green;
}
else if (mom < 0)
{
color = Color.Red;
}
else
{
color = Color.Gray;
}
LinesSeries[0].SetMarker(0, new IndicatorLineMarker(color));
}
}
}