Category Trend  Published on 07/12/2023

Bollinger Squeeze+

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

This is a Bollinger Squeeze indicator, which is used in combination with Bollinger Bands.

 The indicator utilizes CCi, STD, and ATR. The column indicator is CCi(50), and the column changes color. 

When STD/ART<0.75, it squeezes and displays blue. 

When CCi>0, it displays LawnGreen, and when STD/ART>1.5, it displays Green. 

When CCi<0, it displays Pink, and when STD/ART>1.5, it displays Red. 

This indicator is very useful when combined with Bollinger Bands.

I hope it is helpful for you.

 

这是一个布林线挤扎指标。使用过程中结合Bollinger Bands 使用。指标使用了CCi ,STD,ATR。柱体指标为CCi(50),柱体是变色的。当STD/ART<0.75的时候挤扎,显示蓝色。当CCi>0时候显示LawnGreen,当STD/ART>1.5,显示Green。当CCi<0时候显示Pink,当STD/ART>1.5,显示Red。这个指标结合Bollinger Bands,是非常有用的。 希望对您有帮助。




LO
lordyy

Joined on 24.03.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Bollenger Squeeze.algo
  • Rating: 5
  • Installs: 730
  • Modified: 07/12/2023 03:26
Comments
Log in to add a comment.
YE
YesOrNot · 1 year ago

Great Job ! 

LO
lordyy · 1 year ago

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(-200, 0, 200)]
    [Indicator(AccessRights = AccessRights.None)]
    public class BollengerSqueeze : Indicator
    {
        [Parameter(DefaultValue = "Hello Ctrader!")]
        public string Message { get; set; }

        private CommodityChannelIndex _commodityChannelIndex;
        private StandardDeviation _standardDeviation;
        private AverageTrueRange _averageTrueRange;



        [Parameter("Periods", Group = "CCI", DefaultValue = 50)]
        public int CciPeriods { get; set; }

        [Parameter("Source", Group = "STD")]
        public DataSeries StdSource { get; set; }

        [Parameter("Periods", Group = "STD", DefaultValue = 14)]
        public int STDPeriods { get; set; }

        [Parameter("MA Type", Group = "STD", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType STDMAType { get; set; }

        [Parameter("Source", Group = "MovingAverage")]
        public DataSeries MvpSource { get; set; }

        [Parameter("Periods", Group = "MovingAverage", DefaultValue = 20)]
        public int MvPeriods { get; set; }


        [Parameter("Periods", Group = "ATR", DefaultValue = 14)]
        public int ATRPeriods { get; set; }

        [Parameter("MA Type", Group = "ATR", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType ATRMAType { get; set; }




        [Output("Histogramp1", LineColor = "LawnGreen", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries ResultHistogramPositive1 { get; set; }

        [Output("Histogramp2", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries ResultHistogramPositive2 { get; set; }

        [Output("HistogramN1", LineColor = "Pink", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries ResultHistogramNegative1 { get; set; }

        [Output("HistogramN2", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries ResultHistogramNegative2 { get; set; }

        [Output("HistogramSq", LineColor = "Blue", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries ResultHistogramSq { get; set; }


        [Output("Line", LineColor = "MidnightBlue")]
        public IndicatorDataSeries ResultLine { get; set; }

        protected override void Initialize()
        {

            Print(Message);
            _commodityChannelIndex = Indicators.CommodityChannelIndex(CciPeriods);
            _standardDeviation = Indicators.StandardDeviation(StdSource, STDPeriods, STDMAType);
            _averageTrueRange = Indicators.AverageTrueRange(ATRPeriods, ATRMAType);
        }
        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = 00


            ResultLine[index] = _commodityChannelIndex.Result[index];
            
            
            if (_standardDeviation.Result[index ] / _averageTrueRange.Result[index ] <= 0.75)
                ResultHistogramSq[index] = _commodityChannelIndex.Result[index];
            else

            if (_standardDeviation.Result[index ] / _averageTrueRange.Result[index ] >= 1.5)//是否>=1.5 深色
            {
                if (_commodityChannelIndex.Result[index] >= 0)
                    ResultHistogramPositive2[index] = _commodityChannelIndex.Result[index];
                else
                    ResultHistogramNegative2[index] = _commodityChannelIndex.Result[index];
            }
            else//<1.5浅色
            {
                if (_commodityChannelIndex.Result[index] >= 0)
                    ResultHistogramPositive1[index] = _commodityChannelIndex.Result[index];
                else
                    ResultHistogramNegative1[index] = _commodityChannelIndex.Result[index];
            }
            

        }
    }
}