Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

CCI Color Levels - indicator for MetaTrader 5

Views:
10126
Rating:
(23)
Published:
2018.03.01 11:21
\MQL5\Experts\ \MQL5\Indicators\
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The indicator looks like this:

CCI Color Levels

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

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\.

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.

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/19704

EasyAndFastGUI library for creating graphical interfaces EasyAndFastGUI library for creating graphical interfaces

The EasyAndFastGUI library allows creating graphical interfaces for custom MQL programs.

VR Orders History MT5 Lite VR Orders History MT5 Lite

VR Orders History MT5 Lite - a script for downloading trading history in the CSV format.

ZigZagEvgeTrofi ver. 1 ZigZagEvgeTrofi ver. 1

A trading system based on the ZigZag indicator.

SAR index based on MA SAR index based on MA

The SAR indicator calculated based on the iMA (Moving Average, MA) indicator values.