CCI Color Levels – indicator MetaTrader 5

The indicator looks like this:

CCI Color Levels

Three types of graphical constructions were used for this visual effect:

  • DRAW_HISTOGRAM2 (“Level UP”);
  • DRAW_LINE (“CCI”);
  • DRAW_HISTOGRAM2 (“Level DOWN”).

CCI Color Levels Draw

Indicator Input

  • Averaging period – indicator averaging period;
  • Level UP – the UP level value;
  • Level DOWN – the DOWN level value.

The UP and DOWN levels will be immediately shown in the indicator sub-window:

CCI Color Levels Inputs

How to Access Indicator Data in an Expert Advisor

The DRAW_HISTOGRAM2 style is based on two indicator buffers, that is why we see two Level UP values and two Level Down values in Data Window:

Test CCI Color Levels.png

These values correspond to indicator buffers from 0 to 4 inclusive.

In the Expert Advisor, we create an indicator handle using iCustom:

//--- input parameters
input int      Inp_CCI_ma_period = 14;    // Averaging period 
input double   Inp_CCI_LevelUP   = 90;    // Level UP
input double   Inp_CCI_LevelDOWN =-90;    // Level DOWN
//---
int            handle_iCustom;            // variable for storing the handle of the iCustom indicator 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iCCI
   handle_iCustom=iCustom(Symbol(),Period(),"CCI Color Levels",Inp_CCI_ma_period,Inp_CCI_LevelUP,Inp_CCI_LevelDOWN);
//--- if the handle is not created 
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iCCI indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }

It is assumed here that the CCI Color Levels indicator is located in [data folder]\MQL5\Indicators\.

Alternative:  Lentz_Volatility - indicator MetaTrader 5

How indicator values are obtained (only buffers 0, 2 and 4 are significant):

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double level_up   = iCustomGet(handle_iCustom,0,0);   // buffer #0 -> BufferUpHigh
   double cci        = iCustomGet(handle_iCustom,2,0);   // buffer #2 -> BufferCCI
   double level_down = iCustomGet(handle_iCustom,4,0);   // buffer #4 -> BufferDownLow
   string text="Lelev UP #0: "+DoubleToString(level_up,2)+"\n"+
               "CCI #0: "+DoubleToString(cci,2)+"\n"+
               "Lelev DOWN #0: "+DoubleToString(level_down,2);
   Comment(text);
  }

In the above screenshot, the mouse points to a bar with index 0, “Data Window” with the indicator data is also shown, and EA’s information about buffers 0, 2 and 4 is displayed on the chart.


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks