Warning! This section will be deprecated on February 1st 2025. Please move all your Indicators to the cTrader Store catalogue.
Description
Absolute strength of averages with added histogram for better visability
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AbsoluteStrengthAverages : Indicator
{
[Parameter("Periods", DefaultValue = 14)]
public int per { get; set; }
[Parameter("Smoothing", DefaultValue = 4)]
public int smt { get; set; }
[Parameter("Mode", DefaultValue = 1)]
public int mode { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType maType { get; set; }
[Parameter("Histo", DefaultValue = false)]
public bool histo { get; set; }
[Output("Up Histogram", LineColor = "Aqua", PlotType = PlotType.Histogram)]
public IndicatorDataSeries uRes { get; set; }
[Output("Down Histogram", PlotType = PlotType.Histogram, LineColor = "Red")]
public IndicatorDataSeries dRes { get; set; }
[Output("Bulls", Color = Colors.DarkGreen)]
public IndicatorDataSeries BullsSma { get; set; }
[Output("Bears", Color = Colors.Red)]
public IndicatorDataSeries BearsSma { get; set; }
private IndicatorDataSeries bulls, bears;
private MovingAverage avgBulls, avgBears, smtBulls, smtBears;
protected override void Initialize()
{
mode = mode > 2 ? 2 : mode < 1 ? 1 : mode;
bulls = CreateDataSeries();
bears = CreateDataSeries();
avgBulls = Indicators.MovingAverage(bulls, per, maType);
avgBears = Indicators.MovingAverage(bears, per, maType);
smtBulls = Indicators.MovingAverage(avgBulls.Result, smt, maType);
smtBears = Indicators.MovingAverage(avgBears.Result, smt, maType);
}
public override void Calculate(int index)
{
bulls[index] = mode == 1 ? 0.5 * (Math.Abs(MarketSeries.Close[index] - MarketSeries.Close[index - 1]) + (MarketSeries.Close[index] - MarketSeries.Close[index - 1])) : MarketSeries.Close[index] - MarketSeries.Low.Minimum(per);
bears[index] = mode == 1 ? 0.5 * (Math.Abs(MarketSeries.Close[index] - MarketSeries.Close[index - 1]) - (MarketSeries.Close[index] - MarketSeries.Close[index - 1])) : MarketSeries.High.Maximum(per) - MarketSeries.Close[index];
if (histo == true)
{
if (smtBulls.Result[index] > smtBears.Result[index])
{
uRes[index] = smtBulls.Result[index];
}
if (smtBulls.Result[index] < smtBears.Result[index])
{
dRes[index] = smtBears.Result[index];
}
BullsSma[index] = smtBulls.Result[index];
BearsSma[index] = smtBears.Result[index];
}
else
{
BullsSma[index] = smtBulls.Result[index];
BearsSma[index] = smtBears.Result[index];
}
}
}
}
KA
kaneida84
Joined on 25.04.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Absolute Strength Averages.algo
- Rating: 5
- Installs: 1800
- Modified: 13/10/2021 09:54
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.