Squeeze Momentum Indicator free

by cysecsbin.01 in category Trend at 13/02/2020
Description

Conversion from LazyBear's script: 

 

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 SqueezeMomentumIndicator : Indicator
    {
        [Parameter("BB Period", DefaultValue = 20)]
        public int length { get; set; }
        [Parameter("BB Deviation", DefaultValue = 2)]
        public double mult { get; set; }
        [Parameter("KC Period", DefaultValue = 20)]
        public int lengthKC { get; set; }
        [Parameter("KC Deviation", DefaultValue = 1.5)]
        public double multKC { get; set; }

        [Output("Main", PlotType = PlotType.Points, Thickness = 0, LineColor = "Black")]
        public IndicatorDataSeries Result { get; set; }
        [Output("Bullish Exp", PlotType = PlotType.Histogram, Thickness = 3, LineColor = "Lime")]
        public IndicatorDataSeries BullExp { get; set; }
        [Output("Bullish Con", PlotType = PlotType.Histogram, Thickness = 3, LineColor = "Green")]
        public IndicatorDataSeries BullCon { get; set; }
        [Output("Bearish Exp", PlotType = PlotType.Histogram, Thickness = 3, LineColor = "Red")]
        public IndicatorDataSeries BearExp { get; set; }
        [Output("Bearish Con", PlotType = PlotType.Histogram, Thickness = 3, LineColor = "DarkRed")]
        public IndicatorDataSeries BearCon { get; set; }

        [Output("Squeeze On", PlotType = PlotType.Points, Thickness = 3, LineColor = "Yellow")]
        public IndicatorDataSeries SqueezeOn { get; set; }
        [Output("Squeeze Off", PlotType = PlotType.Points, Thickness = 3, LineColor = "Blue")]
        public IndicatorDataSeries SqueezeOff { get; set; }

        BollingerBands BB;
        KeltnerChannels KC;
        IndicatorDataSeries Difference;
        TimeSeriesMovingAverage TSMA;

        protected override void Initialize()
        {
            BB = Indicators.BollingerBands(Bars.ClosePrices, length, mult, MovingAverageType.Simple);
            KC = Indicators.KeltnerChannels(lengthKC, MovingAverageType.Simple, lengthKC, MovingAverageType.Simple, multKC);
            Difference = CreateDataSeries();
            TSMA = Indicators.TimeSeriesMovingAverage(Difference, lengthKC);
        }

        public override void Calculate(int index)
        {
            bool sqzOn = BB.Bottom[index] > KC.Bottom[index] && BB.Top[index] < KC.Top[index];
            bool sqzOff = BB.Bottom[index] < KC.Bottom[index] && BB.Top[index] > KC.Top[index];
            bool noSqz = !sqzOn && !sqzOff;

            double HLAverage = (Bars.HighPrices.Maximum(lengthKC) + Bars.LowPrices.Minimum(lengthKC)) / 2;
            double SecondAverage = (HLAverage + KC.Main[index]) / 2;

            Difference[index] = Bars.ClosePrices[index] - SecondAverage;

            Result[index] = TSMA.Result[index];

            if (Result[index] > 0)
                if (Result[index] > Result[index - 1])
                    BullExp[index] = Result[index];
                else
                    BullCon[index] = Result[index];

            if (Result[index] <= 0)
                if (Result[index] > Result[index - 1])
                    BearCon[index] = Result[index];
                else
                    BearExp[index] = Result[index];

            if (sqzOn)
                SqueezeOn[index] = 0;
            if (sqzOff)
                SqueezeOff[index] = 0;
        }
    }
}
Comments
0