Русский 中文 Español Deutsch 日本語 Português 한국어 Français Italiano Türkçe
Learn how to design a trading system by CCI

Learn how to design a trading system by CCI

MetaTrader 5Trading | 6 April 2022, 10:15
15 182 6
Mohamed Abdelmaaboud
Mohamed Abdelmaaboud

Introduction

This is a new article from our series in which we learn how to design trading systems based on simple strategies using the most commonly used technical indicators. This time we will discuss the Commodity Channel Index (CCI) indicator. As always, I will try to explain the fundamentals of the topic to help you understand the idea and usage. Ultimately, this way may give you insights and new ideas which you can use in your trading.

In this article, we will design a trading system for CCI. Topics to be covered:

We will start with detailed information about what the Commodity Channel Index (CCI), what it measures, how we can calculate it. When we understand the fundamentals and the roots of what we are doing, we will be able to use the tools more efficiently and find more ideas and insights about it. This is what we are going to discuss in the "CCI Definition" topic. Then, we will work on a simple strategy that can be used with CCI during different market trends or conditions — this is what we will learn in the "CCI Strategy" part. Then, we will learn how we can design a trading system based on this strategy by planning what we need to design and what we want the computer to do — part "CCI trading system blueprint". Then, we will learn how to design what we planned by the trading system blueprint — part "CCI trading system".

We will use the MetaTrader 5 trading platform and MetaQuotes Language Editor in this article. You can download MetaTrader 5 from this link: https://www.metatrader5.com/en/download

Once you download and install MetaTrader 5, you will see the terminal as in the following picture:

MT5 terminal

Then, you can open MetaQuotes Language editor by pressing F4 while the trading terminal is open or by selecting Tools menu in the terminal and then clicking on MetaQuotes Language Editor:

 MQL opening

Or press on IDE button in the MetaTrader 5 toolbar:

MT5 IDE button

Here I need to mention the benefit of programming in trading, as it can help us to be disciplined. The discipline is an important factor to our trading success, because emotions can be harmful to trading: the right decision should be taken according to winning trading plan but it happens to most of traders that they cannot take the right action or decision because of fear, greed, or other emotions.

The programming features come as we can program our trading plan according to our conditions and execute it. The program will do what we need according to our rules without involving emotions that can affect our trading, which means that programming will help us to be disciplined. This is where MQL5 comes in handy as it help us to program our trading conditions and plans in a way which can be executed automatically in the trading terminal. These program can be from very simple to complex ones, depending on our trading plan.

Disclaimer: All content of this article is made for the purpose of education only not for anything else. So, you will be responsible for any action you take based on the content of this article, as the content of this article does not guarantee any kind of results.

Now, we are ready to start our article to build a new block in our learning journey. So, let us do that... 


CCI definition

In this part, we will learn about the Commodity Channel Index (CCI) indicator in more detail: what it measures, how it is calculated and how to use it. 

Commodity Channel index (CCI) indicator created by Donald Lambert is a momentum indicator which measures the current price relative to an average of price of a given period of time. When Lambert created this indicator, the initial objective was to measure cyclical movements in commodities but it can measure also other financial instruments. CCI can be used to spot the trend strength and reversals and this is a normal result according to its nature as a momentum indicator.

According to the calculation of CCI and what it measures, when CCI is high this means that the prices are far above its average and vice versa, when CCI is low this means that the prices are far below its average.

The CCI is calculated in the following steps:

  • Get Typical Price (TP):

TP = (High + Low + Close)/3

  • Get Simple Moving Average of TP:

SMA of TP = Sum of TP/n

  • Get Mean deviation:

Mean Deviation = Sum of Abs(TP-SMA)/n

  • Get CCI:

CCI =  (TP-SMA of TP)/(0.015*Mean Deviation)

Now, let us take an example to apply this calculation:

Suppose, we have the following data for an instrument for a period of 14 days:

Days High Low Close
1 100 90 110
2 130 100 120
3 140 110 130
4 130 100 120
5 120 95 110
6 140 120 130
7 160 130 150
8 170 150 160
9 155 130 140
10 140 120 130
11 160 140 150
12   180 160 170
13   190 170 190
14   200 180 210

Here is how we can calculate CCI using this data:

  • First we will calculate Typical price (TP):

TP = (High + Low + Close)/3

So, after the calculation of Typical price, it will be as follows:

Example CCI1

  • Then, we need to calculate the Simple Moving Average (SMA) of the calculated TP:

SMA of TP = Sum of TP/n

The result is as follows:

Example CCI2

  • Then, we will calculate the difference between TP and SMA in absolute values to calculate the mean deviation:

Abs (TP-SMA)

Here it is:

Example CCI3

  • Now, we need to calculate Mean deviation:

Mean Deviation = Sum of Abs(TP-SMA)/n

Example CCI4

  • Now, it is time to calculate CCI:
CCI =  (TP-SMA of TP)/(0.015*Mean Deviation)

CCI = (196.67-141.19)/(0.015*22.86)

CCI = 55.48/0.3429

CCI = 161.80

Nowadays, we do not need to calculate indicators manually because MetaTrader 5 offers ready-to-use built-in indicators. You can use it immediately by selecting the CCI indicator in the platform as is shown in the following picture:

CCI insert

After selecting CCI the following window will be appeared:

 CCI window

The previous window of the indicator shows its parameters:

  • 1: to determine the period of the indicator.
  • 2: to set price type that will be used in indicator calculation and here we will choose Typical price.
  • 3: to set the indicator style: CCI color, CCI line type, and CCI line thickness.

After specifying all parameters press Ok, and the indicator will appear on the chart:

CCI indicator on the chart

CCI is an oscillator which oscillates around and between 100 and -100


CCI strategy

In this part, we will talk about two simple strategies which can be used with CCI. One of the strategies can be used according to market trend or direction (uptrend, downtrend and sideways). The other one is a simple crossover between CCI value with both of zero and 100 or -100. Before we talk about these strategies, I need to mention that there are many strategies which can be used with CCI. You should test every strategy by yourself on a demo account to see if it is useful or not in your trading before using it on a real account with real money.

So, the strategies are as follows.

First strategy: Using CCI according to market trend

    • During uptrend:

      Uptrend is the market direction during which prices create higher lows and higher highs which means that there is a control from buyers as prices move up. In this market condition we can use CCI as a signal provider to generate a buying signal when CCI line breaks above 100 level. So, CCI > 100. Then we can use another effective tool like price action for example to take profit.

      CCI > 100 = buy

      Take profit signal can be used from another tool which can be more useful, such as price action by breaking below previous low
        • During downtrend:

          Downtrend is the trend that it is the opposite of uptrend: prices create lower highs and lower lows which means that there is a control from sellers and prices move down. In such a market, CCI can also be used to generate signals: a shorting signal appears when CCI line breaks below - 100 level. Price action can be used to take profits.

          CCI < -100 = short

          Take profit signal can be taken from another tool which can be more useful, such as price action by breaking above previous high
            • During sideways:

              During sideways movements, we can find that there is a balance between buyers and sellers so no one visually prevails on the market. It is any situation except uptrend and downtrend.

              During sideways we can use CCI to generate signals. When CCI line breaks below -100 level, this will be a buy signal and when CCI line breaks above 100, this will be a take profit. Or when CCI line breaks above 100, this will be a short signal and when CCI line breaks below -100, this will be a take profit.

              CCI < -100 = buy
              CCI > 100 = take profit
              CCI > 100 = short

              CCI < -100 = take profit

                Second strategy: Zero crossover signals:

                  In this article, we can use CCI in a different way as we can take the action of entering the market according to the crossover with zero level and take profits according to the crossover with 100 and -100 values as per our position type (buy or short).

                    • For buy signal:

                      Watch CCI value ralive to the zero level. When CCI value breaks above zero level, this will be a buy signal and we can take profit when CCI value breaks above 100.

                      CCI > 0 = Buy
                      CCI > 100 = take profit 

                        • For short signal:

                          Watch CCI value ralive to the zero level. When CCI value breaks below zero level, this will be a short signal and we can take profit when CCI value break below -100.

                          CCI < 0 = Buy
                          CCI < 100 = take profit 

                          CCI trading system blueprint

                          Now, we come to the most interesting part in this article as we need to program these mentioned strategies to automate signals when observing CCI manually.

                          So, we need now to code these mentioned strategies and inform the computer what to do according to what we need exactly. We will start step by step by designing a blueprint for that.

                            First strategy: Using CCI according to market trend:
                              • During uptrend:

                                We need the program to check CCI value every tick and do something according to the CCI value.

                                If CCI above 100, give buy and if not do nothing.

                                CCI uptrend blueprint

                                  • During downtrend:

                                    Check CCI value every tick and take an action according to this value.

                                    If CCI value below -100, give a short signal and if not do nothing.

                                    CCI downtrend blueprint

                                      • During sideways:

                                        During sideways, we need the program to check CCI value then do something according to that.

                                        If CCI value below -100, give a buy signal, give a take profit. If CCI is not below -100, check if CCI above -100 and below 100 do nothing (hold) and if not check if CCI above 100, give short then check if CCI is below -100, give a take profit and if not check if CCI value below 100 and above -100 do nothing (hold).

                                        CCI sideway blueprint

                                          Second strategy: Zero crossover signals:
                                            • For buy signal:

                                              Check every tick CCI value and Zero level. When CCI value becomes greater than zero, generate a buy signal on the chart, and when CCI value become above 100 show a take profit signal on the chart.

                                              Zero crossover CCI strategy - buy blueprint

                                                • For short signal:
                                                  Check every tick CCI value and Zero level and when CCI value becomes below zero level show a short signal on the chart, and when CCI value becomes below -100 give a take profit signal.

                                                  Zero crossover CCI strategy - short blueprint

                                                  CCI trading system

                                                  Now, we need to write the mentioned strategy as a code for the computer to do what we need.

                                                  First, we need to code a simple program which shows CCI values on the chart. The programming consists of the following steps:

                                                  1. Creating an array of prices.
                                                  2. Sorting price array from current data.
                                                  3. Defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Charting CCI values and showing these values on the chart.

                                                  The following is how to code the previous steps to create a program which can let the computer display CCI values on the chart automatically:

                                                  //+------------------------------------------------------------------+
                                                  //|                                            Simple CCI System.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //Charting CCI values
                                                     Comment ("CCI Value = ",CCIValue);
                                                    }
                                                  //+------------------------------------------------------------------+

                                                  After that we can find this program (Simple CCI System) in the Navigator, select it and execute in the trading platform:

                                                  Updated CCI navigator

                                                  The program (Simple CCI System) can be opened by double click or drag and drop on the chart. After that the following window will be opened:

                                                  Simple CCI System window

                                                  After enabling the "Allow Algo Trading" option and pressing ok, the program (EA) Simple CCI System will be attached to the chart and CCI value will be visualized on the chart:

                                                  Simple CCI System attach 

                                                  Now, we will learn how to code the two mentioned strategies:

                                                  • First strategy: Using CCI according to market trend:
                                                    • During uptrend:

                                                  CCI > 100 = buy


                                                  We will do the following steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition CCI signals during uptrend.

                                                  Here is how to code these steps:

                                                  //+------------------------------------------------------------------+
                                                  //|                                         Uptrend CCI Strategy.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals for uptrend
                                                     if(CCIValue> 100)
                                                     Comment ("UPTREND CCI - BUY SIGNAL ");
                                                     
                                                    }
                                                  //+------------------------------------------------------------------+
                                                  

                                                  After that we can find this program Uptrend CCI Strategy in the Navigator:

                                                  Uptrend strategy CCI navigator

                                                  Again open this program CCI Uptrend Strategy by double click or drag and drop on the chart. The following window will open:

                                                  Uptrend CCI strategy window

                                                  After enabling "Allow Algo Trading" and pressing ok, the program (EA) - Uptrend CCI Strategy - will be attached to the chart:

                                                  Uptrend CCI strategy attach

                                                  Signals of Uptrend CCI Strategy will be displayed according to this strategy:

                                                  Uptrend CCI Strategy - Buy Signal

                                                  • During downtrend:

                                                  CCI < -100 = short

                                                  We will code the following steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition CCI signals during downtrend.

                                                  Below is the code of the program which can be launched in the trading platform and execute what we need automatically:

                                                  //+------------------------------------------------------------------+
                                                  //|                                       Downtrend CCI Strategy.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals
                                                     if(CCIValue< -100)
                                                     Comment ("DOWNTREND CCI - SHORT SIGNAL ");
                                                    }
                                                  //+------------------------------------------------------------------+
                                                  

                                                  Find this program Downtrend CCI Strategy in the Navigator:

                                                  Downtrend strategy CCI navigator

                                                  Open this program Downtrend CCI Strategy by double click or drag and drop on the chart. The following window will be opened:

                                                  Downtrend CCI strategy window

                                                  Enable "Allow Algo Trading" and press ok, the program (EA) -  Downtrend CCI Strategy - will be attached to the chart:

                                                  Downtrend CCI strategy attach

                                                  The ignals of Downtrend CCI Strategy program will appear according to this strategy the same like the following picture:

                                                  Downtrend CCI Strategy - Short Signal

                                                  • During sideways:
                                                    • For buy signals:

                                                  CCI < -100 = buy

                                                  CCI > 100 = take profit

                                                  Steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. Defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition CCI buy signal during sideways.

                                                  Code these steps to create a program which can do what we need:

                                                  //+------------------------------------------------------------------+
                                                  //|                                  Sideways CCI Strategy - Buy.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals
                                                     if(CCIValue< -100)
                                                     Comment ("SIDEWAYS CCI - BUY SIGNAL ");
                                                     
                                                     if(CCIValue> 100)
                                                     Comment ("SIDEWAYS CCI - TAKE PROFIT");
                                                    }
                                                  //+------------------------------------------------------------------+

                                                  Find this program Sideways CCI Strategy - Buy in the Navigator:

                                                   Sideways buy strategy CCI navigator

                                                  Open it by double click or drag and drop. The following window will be opened:


                                                  Sideways CCI buy strategy window

                                                  Enable "Allow Algo Trading" and press ok, the program (EA) -  Sideways CCI Strategy - Buy - will be attached to the chart:

                                                  Sideways CCI buy strategy attach

                                                  Then, we can find signals appear according to this strategy Sideways CCI Strategy - Buy:

                                                  Sideways CCI - Buy

                                                  Take profit signal is at CCI > 100 = take profit. Example:

                                                  Sideways CCI - Buy - TP

                                                    • For short signals:

                                                  CCI > 100 = short

                                                  CCI < -100 = take profit

                                                  We will code that through the following steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. Defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition CCI short signal during sideways.

                                                  And the following is how to code these steps to create the program Sideways CCI Strategy - Short:

                                                  //+------------------------------------------------------------------+
                                                  //|                                Sideways CCI Strategy - Short.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals
                                                     if(CCIValue> 100)
                                                     Comment ("SIDEWAYS CCI - SHORT SIGNAL ");
                                                     
                                                     if(CCIValue< -100)
                                                     Comment ("SIDEWAYS CCI - TAKE PROFIT");
                                                    }
                                                  //+------------------------------------------------------------------+

                                                  After that we the program Sideways CCI Strategy - Short can be found in the Navigator:

                                                  Sideways short strategy CCI navigator

                                                  Open Sideways CCI Strategy - Short by double click or drag and drop on the chart. The following window will be opened:

                                                  Sideways CCI short strategy window

                                                  After enabling "Allow Algo Trading" and pressing ok, the program (EA) - Sideways CCI Strategy - Short - will be attached to the chart and it will be the same like the following:

                                                  Sideways CCI short strategy attach

                                                  Signals will appear according to this strategy Sideways CCI Strategy - Short:

                                                  Sideways CCI - Short

                                                  We can take profit signal when  CCI < -100 = take profit:

                                                  Sideways CCI - Short - TP

                                                  • Second strategy: Zero crossover signals:
                                                    • For buy signal:

                                                  CCI > 0 = Buy
                                                  CCI > 100 = take profit 

                                                  We will code that through the following steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. Defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition for CCI value and zero level crossover.

                                                  Steps to create the program Zero crossover CCI Strategy - Buy:

                                                  //+------------------------------------------------------------------+
                                                  //|                            Zero crossover CCI Strategy - Buy.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                    
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals
                                                     if(CCIValue > 0)
                                                     Comment ("Zero crossover CCI - BUY SIGNAL ");
                                                     
                                                     if(CCIValue > 100)
                                                     Comment ("Zero crossover CCI - TAKE PROFIT");
                                                    }
                                                  //+------------------------------------------------------------------+
                                                  

                                                  Find this program Zero crossover CCI Strategy - Buy in the Navigator:

                                                  Zero crossover buy strategy CCI navigator

                                                  Open this program by double click or drag and drop on the chart. The following window will be opened:

                                                  Zero crossover CCI strategy - Buy window


                                                  After enabling "Allow Algo Trading" and pressing ok, the program (EA) - Zero crossover CCI Strategy - Buy - will be attached to the chart:

                                                  Zero crossover CCI strategy - Buy attach

                                                  Signals will appear according to this strategy Zero crossover CCI Strategy - Buy:

                                                  Zero crossover CCI strategy - Buy

                                                  We can take profit signal when  CCI > 100 = take profit and the following picture is an example for it:

                                                  Zero crossover CCI strategy - Buy - TP

                                                    • For short signal:

                                                  CCI < 0 = Buy
                                                  CCI < -100 = take profit 

                                                  We will code that through the following steps:

                                                  1. Creating an array for prices.
                                                  2. Sorting price array from current data.
                                                  3. Defining CCI properties.
                                                  4. Sorting results.
                                                  5. Getting value of current data.
                                                  6. Setting condition for CCI value and zero level crossover.

                                                  Coding steps to create the program Zero crossover CCI Strategy - Short:

                                                  //+------------------------------------------------------------------+
                                                  //|                          Zero crossover CCI Strategy - Short.mq5 |
                                                  //|                                  Copyright 2022, MetaQuotes Ltd. |
                                                  //|                                             https://www.mql5.com |
                                                  //+------------------------------------------------------------------+
                                                  #property copyright "Copyright 2022, MetaQuotes Ltd."
                                                  #property link      "https://www.mql5.com"
                                                  #property version   "1.00"
                                                  //+------------------------------------------------------------------+
                                                  void OnTick()
                                                    {
                                                     //Creating an array of prices
                                                     double ArrayOfPrices[];
                                                     
                                                     //Sorting price array from current data
                                                     ArraySetAsSeries(ArrayOfPrices,true);
                                                     
                                                     //CCI properties Definition
                                                     int CCIDef = iCCI(_Symbol,_Period,14,PRICE_CLOSE);
                                                     
                                                     //Storing results
                                                     CopyBuffer(CCIDef,0,0,3,ArrayOfPrices);
                                                     
                                                     //Getting value of current data
                                                     double CCIValue = (ArrayOfPrices[0]);
                                                     
                                                     //CCI signals
                                                     if(CCIValue < 0)
                                                     Comment ("Zero crossover CCI - SHORT SIGNAL ");
                                                     
                                                     if(CCIValue < -100)
                                                     Comment ("Zero crossover CCI - TAKE PROFIT");
                                                    }
                                                  //+------------------------------------------------------------------+
                                                  

                                                  After that find this program Zero crossover CCI Strategy - Short in the Navigator:

                                                  Zero crossover short strategy CCI navigator

                                                  Open this program Zero crossover CCI Strategy - Short by double click on it or drag it and drop on the chart. The following window will be opened:

                                                  Zero crossover CCI strategy - Short window

                                                  After enabling "Allow Algo Trading" and pressing ok, the program (EA)-  Zero crossover CCI Strategy - Short - will be attached to the chart:

                                                  Zero crossover CCI strategy - Short attach

                                                  Signals will appear according to this strategy -  Zero crossover CCI Strategy - Short:

                                                  Zero crossover CCI strategy - Short

                                                  We can take profit signal when  CCI < -100 = take profit and the following picture is an example for it:

                                                  Zero crossover CCI strategy - Short - TP

                                                  Conclusion

                                                  The Commodities Channel Index indicator - CCI - is another tool which can be used in our favor to be beneficial to our trading and get better results after testing every strategy of CCI and optimize it in case of being profitable after testing. and you can consider this article is an introduction to a new tool that can be used in your trading if it is suitable for your trading plan and style. 

                                                  As we knew at this article what is CCI indicator and what does it mean and what does it measure and how can we calculate it and saw an example for that to deepen our knowledge and awareness toward this tool which can a reason to open our eyes to more insights and new ideas.

                                                  Then, we knew simple strategies which can be used by CCI during different market conditions (uptrend, downtrend, and sideways) and Zero crossover strategy and like what I mentioned that there many strategies can be used by CCI and you can learn more to know which of them can be useful for your trading but I believe that when you know basics of something, your usage will be more effective.

                                                  Then, we knew how to design a blueprint for this strategy which can be helpful to write our program to design a trading system by CCI. Then, we knew how to code this strategy by MQL5 and how to attach and execute this trading system to our Meta Trader 5 trading platform to generate signals automatically and then we knew how signals can be generated on our charts.

                                                  What I need to confirm now, is you must test any new strategy before you use it live on your real account. And I hope that you find this article useful for you and your trading by included information or by opening your eyes to a new ideas or insights which can be used in your trading.


                                                  Last comments | Go to discussion (6)
                                                  Mohamed Abdelmaaboud
                                                  Mohamed Abdelmaaboud | 12 Apr 2022 at 18:59
                                                  Toto Sarono #:

                                                  Hello Mohamed...

                                                  Nice to meet you again here. I've tried your CCI signal. I compared the value generated by your CCI_simple_system is different with bulit-in CCI as you you can see on the attached picture.

                                                  Could you please explain why the values are difference? I saw that the period used is the same, 14.


                                                  Thank you very much for your kind attention and support.


                                                  Cheers,

                                                  Toto S

                                                  Hello Toto,

                                                  Thanks for your comment and nice to meet you again.

                                                  First thing, I appreciate that you try applying and testing everything. About your question, the answer is that I wrote the code using PRICE_CLOSE only and this is one of options of the default CCI on Metatrader 5 and if you changed parameters of the default CCI to be Apply to Close, you will find that it will be the same value. If you preferred to use Typical for this code you can update it to PRICE_TYPICAL in the code line of CCIDef.


                                                  Thanks,

                                                  Mohamed

                                                  Toto Sarono
                                                  Toto Sarono | 12 Apr 2022 at 22:15
                                                  Mohamed Abdelmaaboud #:

                                                  Hello Toto,

                                                  Thanks for your comment and nice to meet you again.

                                                  First thing, I appreciate that you try applying and testing everything. About your question, the answer is that I wrote the code using PRICE_CLOSE only and this is one of options of the default CCI on Metatrader 5 and if you changed parameters of the default CCI to be Apply to Close, you will find that it will be the same value. If you preferred to use Typical for this code you can update it to PRICE_TYPICAL in the code line of CCIDef.


                                                  Thanks,

                                                  Mohamed

                                                  Hi...

                                                  Thanks a lot for your explanation, already corrected and worked well. the question is which price better to use? typical or close?

                                                  I found it had better additional reference to decide opening position. In this case, RSI band is used whether on upper band for sell and lower band for buy.

                                                  It is just to increase to succeed the probability thus of course, increasing our confidence. In my exercised showed that one indicator is not enough to anticipate trend reversal.

                                                  Do you have any suggestion to this matter? please let me know. Especially the reference to define uptrend, sideway and downtrend. 


                                                  Cheers,

                                                  Toto S 

                                                  Toto Sarono
                                                  Toto Sarono | 12 Apr 2022 at 22:34
                                                  Toto Sarono #:

                                                  Hi...

                                                  Thanks a lot for your explanation, already corrected and worked well. the question is which price better to use? typical or close?

                                                  I found it had better additional reference to decide opening position. In this case, RSI band is used whether on upper band for sell and lower band for buy.

                                                  It is just to increase to succeed the probability thus of course, increasing our confidence. In my exercised showed that one indicator is not enough to anticipate trend reversal.

                                                  Do you have any suggestion to this matter? please let me know. Especially the reference to define uptrend, sideway and downtrend. 


                                                  Cheers,

                                                  Toto S 

                                                  For your illustration about the trend questioning and additional indicator, please refer to the attached file.

                                                  Thank you.

                                                  John Winsome Munar
                                                  John Winsome Munar | 21 May 2022 at 16:28
                                                  Thanks for sharing
                                                  Mohamed Abdelmaaboud
                                                  Mohamed Abdelmaaboud | 21 May 2022 at 23:46
                                                  John Winsome Munar #:
                                                  Thanks for sharing

                                                  You are welcome and thanks for your comment.

                                                  Data Science and Machine Learning (Part 02): Logistic Regression Data Science and Machine Learning (Part 02): Logistic Regression
                                                  Data Classification is a crucial thing for an algo trader and a programmer. In this article, we are going to focus on one of classification logistic algorithms that can probability help us identify the Yes's or No's, the Ups and Downs, Buys and Sells.
                                                  Mathematics in trading: Sharpe and Sortino ratios Mathematics in trading: Sharpe and Sortino ratios
                                                  Return on investments is the most obvious indicator which investors and novice traders use for the analysis of trading efficiency. Professional traders use more reliable tools to analyze strategies, such as Sharpe and Sortino ratios, among others.
                                                  Multiple indicators on one chart (Part 01): Understanding the concepts Multiple indicators on one chart (Part 01): Understanding the concepts
                                                  Today we will learn how to add multiple indicators running simultaneously on one chart, but without occupying a separate area on it. Many traders feel more confident if they monitor multiple indicators at a time (for example, RSI, STOCASTIC, MACD, ADX and some others), or in some cases even at different assets which an index is made of.
                                                  Graphics in DoEasy library (Part 96): Graphics in form objects and handling mouse events Graphics in DoEasy library (Part 96): Graphics in form objects and handling mouse events
                                                  In this article, I will start creating the functionality for handling mouse events in form objects, as well as add new properties and their tracking to a symbol object. Besides, I will improve the symbol object class since the chart symbols now have new properties to be considered and tracked.