Description
The Hurst oscillator is described in Jim Hurst's book "The Magic of Stock Transaction Timing".
This indicator can be used for identifying long trading zones when the indicator value is above the zero level, and for short trading zones when the indicator value is below the zero level.
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 mHurstOsc : Indicator
{
[Parameter("Main Period (10)", DefaultValue = 10, MinValue = 1)]
public int inpMainPeriod { get; set; }
[Parameter("Smooth Period (1)", DefaultValue = 1, MinValue = 1)]
public int inpSmoothPeriod { get; set; }
[Output("Hurst", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outHurst { get; set; }
private int _displacement;
private MovingAverage _pr, _smooth;
private IndicatorDataSeries _cma, _flow, _hurstoscillator;
protected override void Initialize()
{
_displacement = Convert.ToInt16(inpMainPeriod / 2.0 + 1.0);
_pr = Indicators.MovingAverage(Bars.MedianPrices, inpMainPeriod, MovingAverageType.Simple);
_cma = CreateDataSeries();
_flow = CreateDataSeries();
_smooth = Indicators.MovingAverage(_flow, inpSmoothPeriod, MovingAverageType.Simple);
_hurstoscillator = CreateDataSeries();
}
public override void Calculate(int i)
{
_cma[i] = i>inpMainPeriod ? _pr.Result[i-_displacement] : Bars.ClosePrices[i];
_flow[i] = Bars.ClosePrices[i] > Bars.ClosePrices[i-1] ? Bars.HighPrices[i] : Bars.ClosePrices[i] < Bars.ClosePrices[i-1] ? Bars.LowPrices[i] : (Bars.HighPrices[i] + Bars.LowPrices[i]) / 2;
_hurstoscillator[i] = (_smooth.Result[i] - _cma[i]) / Symbol.TickSize;
outHurst[i] = _hurstoscillator[i];
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mHurstOsc.algo
- Rating: 5
- Installs: 536
- Modified: 05/04/2023 12:28
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.