Description
Slope Direction Line indicator is displayed as a colored average line indicating the average market movement direction.
Use it in multi timeframe to identify trend direction.
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class mSlopeDirectionLine : Indicator
{
[Parameter("Period (55)", DefaultValue = 55)]
public int inpPeriod { get; set; }
[Parameter("Smooth Type (ema)", DefaultValue = MovingAverageType.Exponential)]
public MovingAverageType inpSmoothType { get; set; }
[Output("SlopeDirectionLine", LineColor = "Transparent", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries outSDL { get; set; }
[Output("SlopeDirectionLine bullish", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries outSDLp { get; set; }
[Output("SlopeDirectionLine bearish", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries outSDLn { get; set; }
private MovingAverage _ma, _ma2, _sdl;
private IndicatorDataSeries _raw, _trend;
protected override void Initialize()
{
_ma = Indicators.MovingAverage(Bars.ClosePrices, inpPeriod, inpSmoothType);
_ma2 = Indicators.MovingAverage(Bars.ClosePrices, (int)inpPeriod/2, inpSmoothType);
_raw = CreateDataSeries();
_trend = CreateDataSeries();
_sdl = Indicators.MovingAverage(_raw, (int)Math.Sqrt(inpPeriod), inpSmoothType);
}
public override void Calculate(int i)
{
_raw[i] = 2.0 * _ma2.Result[i] - _ma.Result[i];
_trend[i] = i>inpPeriod ? (_sdl.Result[i] > _sdl.Result[i-1] ? +1 : _sdl.Result[i] < _sdl.Result[i-1] ? -1 : _trend[i-1]) : +1;
outSDL[i] = _sdl.Result[i];
outSDLp[i] = _trend[i] == +1 ? _sdl.Result[i] : double.NaN;
outSDLn[i] = _trend[i] == -1 ? _sdl.Result[i] : double.NaN;
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mSlopeDirectionLine.algo
- Rating: 5
- Installs: 1086
- Modified: 25/02/2023 11:24
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.