Description
The indicator shows the DIFFERENCE of ema 1 and 2 to show if they ae widening or closing in. if it is 0 they are crossing
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class EMADifferenceIndicator : Indicator
{
[Parameter("EMA1 Period", DefaultValue = 12)]
public int Ema1Period { get; set; }
[Parameter("EMA2 Period", DefaultValue = 26)]
public int Ema2Period { get; set; }
[Parameter("Multiplier", DefaultValue = 1111)]
public double Multiplier { get; set; }
[Output("Difference", LineColor = "Blue")]
public IndicatorDataSeries DifferenceResult { get; set; }
protected override void Initialize()
{
// Calculate EMAs
var ema1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, Ema1Period);
var ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, Ema2Period);
// Calculate the difference and normalize it between 0 and 1
for (int i = 0; i < MarketSeries.Close.Count; i++)
{
double diff = ema1.Result[i] - ema2.Result[i];
double normalizedDiff = Math.Abs(diff) / (Symbol.PipSize * Multiplier);
DifferenceResult[i] = Math.Min(normalizedDiff, 1) * 100;
}
}
public override void Calculate(int index)
{
// The calculation is done in the Initialize method, as it doesn't require ongoing calculations.
}
}
}
DA
davidmwabuka
Joined on 07.03.2023
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: EMA sensorr.algo
- Rating: 0
- Installs: 409
- Modified: 11/03/2024 10:55
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.