Description
The Deviation Oscillator, as a sentiment volatility oscillator, represents the difference between the price and the price simple moving average, normalized within the selected range.
The indicator positive difference value in the indicator shows bullish market sentiment, while a negative difference value indicates bearish market sentiment.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class mDeviationOscillator : Indicator
{
[Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType inpSmoothType { get; set; }
[Parameter("Smooth Period (10)", DefaultValue = 10, MinValue = 1)]
public int inpPeriodSmooth { get; set; }
[Parameter("HH/LL Period (20)", DefaultValue = 20, MinValue = 2)]
public int inpPeriodHHLL { get; set; }
[Output("Deviation Oscillator", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDeviationOscillator { get; set; }
private MovingAverage _pricesmooth;
private IndicatorDataSeries _raw, _hh, _ll, _deviation;
protected override void Initialize()
{
_pricesmooth = Indicators.MovingAverage(Bars.ClosePrices, inpPeriodSmooth, inpSmoothType);
_raw = CreateDataSeries();
_hh = CreateDataSeries();
_ll = CreateDataSeries();
_deviation = CreateDataSeries();
}
public override void Calculate(int i)
{
_raw[i] = Bars.ClosePrices[i] - _pricesmooth.Result[i];
_hh[i] = i>inpPeriodHHLL ? _raw.Maximum(inpPeriodHHLL) : _raw[i];
_ll[i] = i>inpPeriodHHLL ? _raw.Minimum(inpPeriodHHLL) : _raw[i];
_deviation[i] = _hh[i] != _ll[i] ? (200 / (_hh[i] - _ll[i])) * (_raw[i] - _ll[i]) - 100.0 : 0;
outDeviationOscillator[i] = _deviation[i];
}
}
}

mfejza
Joined 25.01.2022
- Type: free
- Language: C#
- Trading Platform: cTrader Automate
- Filename: mDeviationOscillator.algo
- Rating: 0
- Downloads: 184
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Comments
Only logged in users can post a comment
Comments not found