Description
Directional Volatility indicator. The indicator displays two volatility lines; bullish (green component) and bearish (red component).
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AutoRescale = false, AccessRights = AccessRights.None)]
public class mDirectionalVolatility : Indicator
{
[Parameter("Periods (14)", DefaultValue = 14)]
public int inpPeriods { get; set; }
[Parameter("Deviation (3.0)", DefaultValue = 3.0)]
public double inpDeviation { get; set; }
[Output("DirectionalVolatility Bullish", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDirectionalVolatilityBullish { get; set; }
[Output("DirectionalVolatility Bearish", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDirectionalVolatilityBearish { get; set; }
private IndicatorDataSeries _pricelong, _priceshort;
private MovingAverage _malong, _mashort;
private StandardDeviation _stddevmalong, _stddevmashort;
protected override void Initialize()
{
_pricelong = CreateDataSeries();
_priceshort = CreateDataSeries();
_malong = Indicators.MovingAverage(_pricelong, inpPeriods, MovingAverageType.Exponential);
_mashort = Indicators.MovingAverage(_priceshort, inpPeriods, MovingAverageType.Exponential);
_stddevmalong = Indicators.StandardDeviation(_malong.Result, inpPeriods, MovingAverageType.Simple);
_stddevmashort = Indicators.StandardDeviation(_mashort.Result, inpPeriods, MovingAverageType.Simple);
}
public override void Calculate(int i)
{
_priceshort[i] = Bars.ClosePrices[i-1] - Bars.LowPrices[i];
_pricelong[i] = Bars.HighPrices[i] - Bars.ClosePrices[i-1];
outDirectionalVolatilityBullish[i] = (_malong.Result[i] + inpDeviation * _stddevmalong.Result[i]) / Symbol.TickSize;
outDirectionalVolatilityBearish[i] = (_mashort.Result[i] + inpDeviation * _stddevmashort.Result[i]) / Symbol.TickSize;
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mDirectionalVolatility.algo
- Rating: 5
- Installs: 719
- Modified: 09/01/2023 00:33
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.