Files
Michael Schimmel a1d2e96f8a Initial commit
2026-01-28 09:10:52 +01:00

32 lines
1.1 KiB
C#

using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Indicators
{
// Calculates the difference or absolute distance between two data sources
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class DifferenceIndicator : Indicator
{
[Parameter("Source 1")]
public DataSeries Source1 { get; set; }
[Parameter("Source 2")]
public DataSeries Source2 { get; set; }
[Parameter("Use Absolute Distance", DefaultValue = false)]
public bool UseAbsoluteDistance { get; set; }
[Output("Result", LineColor = "MainColor", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Result { get; set; }
// Core calculation logic
public override void Calculate(int index)
{
double diff = Source1[index] - Source2[index];
// Result is either raw difference or absolute distance
Result[index] = UseAbsoluteDistance ? Math.Abs(diff) : diff;
}
}
}