Category Oscilators  Published on 21/02/2023

Hi/Lo Swing Index indicator

Description

This indicator illustrates the High-to-Low variation. It works nicely on shorter time frames.
The index value is calculated based on the observation length. By changing this input, you can have a wider or shorter observation range.
There is an additional smoothing function to make the output even smoother.


using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0, 20, 80, 100)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mHiLoSwingIndex : Indicator
    {
        [Parameter("Periods (10)", DefaultValue = 10)]
        public int inpPeriods { get; set; }
        [Parameter("History Periods (200)", DefaultValue = 200)]
        public int inpHistoryPeriods { get; set; }
        [Parameter("Smooth Periods (7)", DefaultValue = 7)]
        public int inpSmoothPeriods { get; set; }

        [Output("High/Low Swing Index", IsHistogram = false, LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSwingIndex { get; set; }
        [Output("Signalw", IsHistogram = false, LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSignal { get; set; }
        
        private IndicatorDataSeries _diff, _ratio, _normalized;
        private MovingAverage _smooth, _signal;
                

        protected override void Initialize()
        {
            _diff = CreateDataSeries();
            _ratio = CreateDataSeries();
            _normalized = CreateDataSeries();
            _smooth = Indicators.MovingAverage(_ratio, inpPeriods, MovingAverageType.Exponential);
            _signal = Indicators.MovingAverage(_normalized, inpSmoothPeriods, MovingAverageType.Weighted);
        }

        public override void Calculate(int i)
        {
            _diff[i] = Bars.HighPrices[i] - Bars.LowPrices[i];
            _ratio[i] = Bars.MedianPrices[i] / _diff[i];
            _normalized[i] = 100 * (_smooth.Result[i] - _smooth.Result.Minimum(inpHistoryPeriods)) / (_smooth.Result.Maximum(inpHistoryPeriods) - _smooth.Result.Minimum(inpHistoryPeriods));
            
            outSwingIndex[i] = _normalized[i];
            outSignal[i] = _signal.Result[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mHiLoSwingIndex.algo
  • Rating: 5
  • Installs: 841
  • Modified: 21/02/2023 13:02
Comments
Log in to add a comment.
JH
jhonflakes862 · 1 year ago

Air Conditioning Installation Beat the summer heat with Snow Flakes AC! Our team of experienced professionals offers quick and easy installation of air conditioning units plus maintenance and repair services to keep it running smoothly. Enjoy cool, clean air for your home or business - no matter the size. With Snow Flakes AC, you'll stay comfortable all summer long at an affordable price.