Category Oscilators  Published on 05/04/2023

Hurst Oscillator Range Filter

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.

Range and range average values are used as extreme indicator values. These range values are then used as filter confluence indicator values to trigger events

Here you can find the original version.


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 mHurstRangeFilter : 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; }
        [Parameter("Range Periods (25)", DefaultValue = 25)]
        public int inpRangePeriods { get; set; }
        [Parameter("Result Type (MinMax)", DefaultValue = enumResultTypes.MinMax)]
        public enumResultTypes inpResultType { get; set; }

        [Output("Hurst", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outHurst { get; set; }
        [Output("Hurst Range Min", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outRangeMin { get; set; }
        [Output("Hurst Range Max", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outRangeMax { get; set; }
        
        private int _displacement;
        private MovingAverage _pr, _smooth;
        private IndicatorDataSeries _cma, _flow, _hurstoscillator, _rangemin, _rangemax;
        

        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();
            _rangemin = CreateDataSeries();
            _rangemax = 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;
            _rangemin[i] = i>inpRangePeriods ? _hurstoscillator.Minimum(inpRangePeriods) : _hurstoscillator[i];
            _rangemax[i] = i>inpRangePeriods ? _hurstoscillator.Maximum(inpRangePeriods) : _hurstoscillator[i];
            
            outHurst[i] = _hurstoscillator[i];
            outRangeMin[i] = i>inpRangePeriods && inpResultType == enumResultTypes.MinMax ? _rangemin[i] : _rangemin.Sum(inpRangePeriods)/inpRangePeriods;
            outRangeMax[i] = i>inpRangePeriods && inpResultType == enumResultTypes.MinMax ? _rangemax[i] : _rangemax.Sum(inpRangePeriods)/inpRangePeriods;
        }
    }
    
    public enum enumResultTypes
    {
        MinMax,
        Average
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mHurstRangeFilter.algo
  • Rating: 5
  • Installs: 625
Comments
Log in to add a comment.
No comments found.