Klinger Volume Oscillator free

by kaneida84 in category Oscilator at 16/06/2021
Description

The Klinger oscillator was developed by Stephen Klinger to determine the long-term trend of money flow while remaining sensitive enough to detect short-term fluctuations. The indicator compares the volume flowing through securities with the security's price movements and then converts the result into an oscillator.

 

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.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class KlingerVolumeOscillator : Indicator
    {
        [Parameter("Fast Length", DefaultValue = 34.0)]
        public int fastLength { get; set; }
        [Parameter("Slow Length", DefaultValue = 55.0)]
        public int slowLength { get; set; }
        [Parameter("KVO Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType kvoType { get; set; }

        [Parameter("Signal Smooth Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType signalType { get; set; }
        [Parameter("Signal Smooth Length", DefaultValue = 13.0)]
        public int signalLength { get; set; }




        [Output("KVO", Color = Colors.LightGreen)]
        public IndicatorDataSeries kvo { get; set; }
        [Output("Signal", Color = Colors.Red)]
        public IndicatorDataSeries signal { get; set; }

        private IndicatorDataSeries vf, mom, trend, dm, cm;
        private MovingAverage fastMa, slowMa;
        private MovingAverage signalMA;
        // private Bars.TickVolumes volume;


        protected override void Initialize()
        {
            vf = CreateDataSeries();
            mom = CreateDataSeries();
            trend = CreateDataSeries();
            dm = CreateDataSeries();
            cm = CreateDataSeries();
            fastMa = Indicators.MovingAverage(vf, fastLength, kvoType);
            slowMa = Indicators.MovingAverage(vf, slowLength, kvoType);
            signalMA = Indicators.MovingAverage(kvo, signalLength, signalType);



        }

        public override void Calculate(int index)
        {
            mom[index] = Bars.TypicalPrices[index] - Bars.TypicalPrices[index - 1];
            trend[index] = 0;

            if (double.IsNaN(trend[index - 1]))
            {
                trend[index] = 0;

            }
            else
            {
                trend[index] = mom[index] > 0 ? 1 : mom[index] < 0 ? -1 : trend[index - 1];

            }

            dm[index] = Bars.HighPrices[index] - Bars.LowPrices[index];

            cm[index] = 0;

            cm[index] = double.IsNaN(cm[index - 1]) ? 0 : (trend[index] == trend[index - 1] ? cm[index - 1] + dm[index] : dm[index] + dm[index - 1]);
            double volume = Bars.TickVolumes[index];
            cm[index] = double.IsNaN(cm[index - 1]) ? 0 : (trend[index] == trend[index - 1] ? cm[index - 1] + dm[index] : dm[index] + dm[index - 1]);
            vf[index] = cm[index] != 0 ? 100 * volume * trend[index] * Math.Abs(2 * dm[index] / cm[index] - 1) : 0;

            kvo[index] = fastMa.Result[index] - slowMa.Result[index];

            signal[index] = signalMA.Result[index];



        }



    }
}
Comments
0