Category Oscilators  Published on 08/09/2024

The CCI v2.0

Description

Introducing the cTrader Indicator "The CCI v2.0"

The The CCI v2.0 indicator is a custom-built tool for cTrader that combines the Commodity Channel Index (CCI) with smoothing through exponential and triangular moving averages. This indicator is designed to help traders identify overbought and oversold conditions while providing additional signals via a result cloud and histograms. In this article, we’ll explain how it works, the logic behind its calculations, and its practical applications.

1. Indicator Parameters

TheCCI202 offers several configurable parameters that allow traders to customize the indicator to fit their trading strategies:

  • CCI Period: The period over which the CCI is calculated. The default value is 55.
  • Smoothing: Defines the smoothing period for the CCI. The default value is 3.
  • Moving Average Type (MA Type): The type of moving average used to smooth the results (Exponential by default for the CCI and Triangular for the signal).
  • Signal Period: The period for the moving average of the signal (default is 3).
  • Shift: Offsets the calculated signals for better visualization (default is 3).
  • Level Up and Level Down: These levels define the horizontal lines for overbought and oversold conditions (100 and -100 by default).

2. Visual Output

TheCCI202 produces several visual elements to aid analysis:

Result Cloud: Comprising ResultHigh and ResultLow, this cloud is calculated using the CCI of high and low prices respectively. It indicates whether the market is in an upward or downward trend.

Histograms:

  • Up Rising: Shows when the result cloud is rising (green bars).
  • Down Falling: Displays when the result cloud is falling (red bars).
  • Up Falling and Down Rising: Signals divergence between high and low results (blue bars).

Signal Points:

  • Above Signal: Indicates that the result cloud is above the signal line.
  • Below Signal: Indicates that the result cloud is below the signal line.

3. Detailed Calculations

At the heart of the indicator is the CalculateCustomCCI function, which computes the CCI through the following steps:

Typical Price: The CCI is calculated using the typical price (usually the average of high, low, and close prices). However, this version simplifies the typical price by using only high and low prices.

Simple Moving Average (SMA): The typical price is smoothed by calculating the SMA over a specified period.

Mean Deviation: The mean deviation of the typical price from the SMA is calculated to measure volatility.

CCI Formula: Finally, the CCI is derived by dividing the difference between the typical price and the SMA by the mean deviation, scaled by a constant factor (0.015).

4. Result and Signal Cloud Functionality

The result cloud is used to determine the overall trend (up or down), while the signal points (Above Signal and Below Signal) highlight whether the result cloud aligns with the signal lines.

Histograms offer an easy visual representation of divergence, showing when the market signals simultaneous upward and downward movement in high and low results, which can serve as an early warning for trend reversals.

5. Application and Strategy

This indicator can be applied in several trading scenarios:

  • Trend Identification: It helps identify whether the market is in an upward or downward trend through the result cloud.
  • Divergence Trading: Divergences spotted via the histograms (Up Falling, Down Rising) can signal potential trend reversals.
  • Confirmation of Levels: The overbought and oversold levels (Level Up/Down) provide confirmation of reversal points in combination with signal points.

Conclusion

The CCI v2.0 is a powerful tool that enhances the traditional CCI with visual signal enhancements. It helps traders identify overbought/oversold conditions, market divergence, and provides signal lines for greater accuracy in trading decisions.


Telegram group : https://t.me/cTraderStrategyTesterProject

GitHub : https://github.com/YesOrNotCtrader/Ctrader-Stragegy-Tester-Project

Enjoy for Free =) 
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 



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
{
    [Cloud("ResultHigh", "ResultLow", Opacity = 100)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class Thecci20 : Indicator
    {
        [Parameter("Period", DefaultValue = 55, Group = "CCI")]
        public int KPeriod { get; set; }
        [Parameter("Smooth", DefaultValue = 3, Group = "CCI")]
        public int KSlowing { get; set; }
        [Parameter("Ma Type", DefaultValue = MovingAverageType.Exponential, Group = "CCI")]
        public MovingAverageType KSlowingMaType { get; set; }
        [Parameter("Period", DefaultValue = 3, Group = "SIGNAL")]
        public int DPeriod { get; set; }
        [Parameter("Ma Type", DefaultValue = MovingAverageType.Triangular, Group = "SIGNAL")]
        public MovingAverageType DPeriodMaType { get; set; }
        [Parameter("Shift", DefaultValue = 3, Group = "SIGNAL")]
        public int Shift { get; set; }

        [Parameter("Level Up", DefaultValue = 100, Group = "LEVEL")]
        public int LevelUp { get; set; }
        [Parameter("Level Down", DefaultValue = -100, Group = "LEVEL")]
        public int LevelDown { get; set; }

        [Output("Up Rising", IsHistogram = true, LineColor = "Lime", Thickness = 3)]
        public IndicatorDataSeries UpRising { get; set; }
        [Output("Down Falling", IsHistogram = true, LineColor = "Red", Thickness = 3)]
        public IndicatorDataSeries DownFalling { get; set; }
        [Output("Up Falling", IsHistogram = true, LineColor = "DeepSkyBlue", Thickness = 1)]
        public IndicatorDataSeries UpFalling { get; set; }
        [Output("Down Rising", IsHistogram = true, LineColor = "DeepSkyBlue", Thickness = 1)]
        public IndicatorDataSeries DownRising { get; set; }
        [Output("Above Signal", PlotType = PlotType.Points, LineColor = "Lime", Thickness = 5)]
        public IndicatorDataSeries AboveSignal { get; set; }
        [Output("Below Signal", PlotType = PlotType.Points, LineColor = "Red", Thickness = 5)]
        public IndicatorDataSeries BelowSignal { get; set; }

        [Output("ResultHigh", LineColor = "FF013861", Thickness = 1)]
        public IndicatorDataSeries ResultHigh { get; set; }
        [Output("ResultLow", LineColor = "FF013861", Thickness = 1)]
        public IndicatorDataSeries ResultLow { get; set; }
        [Output("SignalHigh", LineColor = "Gold", Thickness = 1)]
        public IndicatorDataSeries SignalHigh { get; set; }
        [Output("SignalLow", LineColor = "Gold", Thickness = 1)]
        public IndicatorDataSeries SignalLow { get; set; }

        [Output("Line Up", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "FF999999", Thickness = 1)]
        public IndicatorDataSeries LineUp { get; set; }
        [Output("Line Midd", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "FF999999", Thickness = 1)]
        public IndicatorDataSeries LineMidd { get; set; }
        [Output("Line Down", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "FF999999", Thickness = 1)]
        public IndicatorDataSeries LineDown { get; set; }

        private IndicatorDataSeries highData, lowData;
        private MovingAverage kslowHigh, kslowLow, DslowHigh, DslowLow;

        protected override void Initialize()
        {
            highData = CreateDataSeries();
            lowData = CreateDataSeries();

            kslowHigh = Indicators.MovingAverage(highData, KSlowing, KSlowingMaType);
            kslowLow = Indicators.MovingAverage(lowData, KSlowing, KSlowingMaType);
            DslowHigh = Indicators.MovingAverage(kslowHigh.Result, DPeriod, DPeriodMaType);
            DslowLow = Indicators.MovingAverage(kslowLow.Result, DPeriod, DPeriodMaType);
        }

        public override void Calculate(int index)
        {
            //Level Lines
            LineUp[index] = LevelUp;
            LineMidd[index] = 0;
            LineDown[index] = LevelDown;

            //Result Cloud
            highData[index] = CalculateCustomCCI(index, KPeriod, Bars.HighPrices);
            lowData[index] = CalculateCustomCCI(index, KPeriod, Bars.LowPrices);

            //Result Cloud
            ResultHigh[index] = kslowHigh.Result.Last(0);
            ResultLow[index] = kslowLow.Result.Last(0);

            //Signal Cloud
            SignalHigh[index + Shift] = DslowHigh.Result.Last(0);
            SignalLow[index + Shift] = DslowLow.Result.Last(0);

            //Histogram : If RESULT CLOUD is Rising or Falling
            UpRising[index] = ResultHigh.IsRising() && ResultLow.IsRising() ? 25 : double.NaN;
            DownFalling[index] = ResultHigh.IsFalling() && ResultLow.IsFalling() ? -25 : double.NaN;
            UpFalling[index] = ResultHigh.IsRising() && ResultLow.IsFalling() ? 25 : double.NaN;
            DownRising[index] = ResultHigh.IsFalling() && ResultLow.IsRising() ? -25 : double.NaN;

            //Signal Point : If RESULT CLOUD is above or bellow SIGNAL LINES
            AboveSignal[index] = SignalHigh[index] < ResultHigh[index] && SignalLow[index] < ResultLow[index] ? 100 : double.NaN;
            BelowSignal[index] = SignalHigh[index] > ResultHigh[index] && SignalLow[index] > ResultLow[index] ? -100 : double.NaN;

        }

        private double CalculateCustomCCI(int index, int period, DataSeries Source)
        {
            // 1. Calculate the typical price (TP) = (High + Low + Close) / 3
            double typicalPrice = Source[index];

            // 2. Calculate the Simple Moving Average (SMA) of the typical price over the specified period
            double sma = 0;
            for (int i = 0; i < period; i++)
            {
                sma += Source[index - i];
            }
            sma /= period;

            // 3. Calculate the Mean Deviation (MD)
            double meanDeviation = 0;
            for (int i = 0; i < period; i++)
            {
                double currentTypicalPrice = Source[index - i];
                meanDeviation += Math.Abs(currentTypicalPrice - sma);
            }
            meanDeviation /= period;

            // 4. Calculate the CCI
            double cci = (typicalPrice - sma) / (0.015 * meanDeviation);

            return cci;
        }
    }
}

YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: The cci 2.0.algo
  • Rating: 5
  • Installs: 180
  • Modified: 08/09/2024 01:09
Comments
Log in to add a comment.
No comments found.