Русский 中文 Español Deutsch 日本語 Português 한국어 Français Italiano Türkçe
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors

MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors

MetaTrader 5Indicators | 18 March 2010, 10:56
42 885 5
Sergey Pavlov
Sergey Pavlov

Introduction

An Expert Advisor or indicator that doesn't use standard technical indicators in its code is rare. They are popular both for the beginners and advanced developers of trading strategies. It isn't difficult to understand the details of indicator creation; the aim of this article is to help with it. We will consider the use of the functions for working with built-in standard technical indicators.

Fundamentals of Using Functions of Standard Technical Indicators

When being called, each function of a technical indicator creates a handle of the object created (indicator's instance) with specified input parameters. The purpose of the handle is to assign it with this object. It's quite sufficient to get the data from the indicator buffer and use it in your own calculations. Consider an example:

double      MA[];                // array for the indicator iMA
int         MA_handle;           // handle of the indicator iMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- creation of the indicator iMA
   MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   //--- filling an array MA[] with current values of iMA
   //--- Copying 100 elements
   CopyBuffer(MA_handle,0,0,100,MA);
   //--- set indexing of elements as series, as in MQL4
   ArraySetAsSeries(MA,true);  
   //--- here you can use the data of MA[] as you wish, for example: 
   if(MA[0]>MA[1])
      {
      //--- some operations
      }
   }

As we see, everything is quite simple. This example shows how to use the indicator iMA - the most popular among the traders.

The handle of the indicator should be created inside the function OnInit()

  1. "Set indexing of elements as series, as in MQL4"- what does it mean? In our example we have used the elements indexing as timeseries. In other words, the current bar (that hasn't formed yet) is always has index [0], the previous (already formed) has index [1], etc.
  2. Why do we set indexing? We have used it for the convenience and optimal implementation of the algorithm. The MQL5 language allows using the convenient indexing for the programmer.
  3. Why is it better to create an indicator inside the function OnInit()? Of course, it can be created anywhere in the program, because there isn't any explicit prohibition. However, there is a strong argument in favor of the proposed way: the function OnInit() is called once at startup of an Expert Advisor, and it's quite sufficient to perform the initialization of indicators, that doesn't change its parameters during the execution. For the case if they change their input parameters, it's possible to initialize them again inside another function, for example, in function OnTick().

Programming lessons

Almost every Expert Advisor is designed for performing trade operations not just on the demo, but also on a real account. If you want to sleep quietly when it trades, you should foresee all possible results of its trade. Even highly qualified developers of automated trading systems often make annoying mistakes. And the price of such mistake can be very high!

For example, here is a story that happened at Automated Trading Championship 2008. An Expert Advisor of one of the participants should increase his deposit to a certain level and sleep. It has been done. The author and all who were watching the work of the Expert Advisor were surprised, when it woke up and started to trade again, losing the earned money.

Of course, you don't want to make the similar mistakes when the robot gets out of control. So, let's consider the "reefs" that can be caught while using of the standard technical indicators:

  1. The object pointer is created in the initialization block. And what if it was unsuccessful? In this case, we will get an empty reference. Therefore, let's use the possibility to check its validity, that has been provided by MQL5 developers. If the pointer hasn't been created, the value of handle, returned by the function will be equal to standard constant INVALID_HANDLE = -1.
  2. When we get data from the indicator, we are copying its values to the indicator's buffer and use them in our calculations. What if it failed? If copying has failed, a trading system may generate wrong trade signals. For such cases, MQL5 developers have provided the possibility to check immediately the number of copied elements. The number of copied elements in case of an error will be equal to -1.

Now let's consider how it can be coded:

//---- arrays for indicators
double      MA[];                // array for the indicator iMA
//---- handles for indicators
int         MA_handle;           // handle of the indicator iMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- creation of the indicator iMA
   MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
  //--- report if there was an error in object creation
   if(MA_handle<0)
      {
      Print("The creation of iMA has failed: MA_handle=",INVALID_HANDLE);
      Print("Runtime error = ",GetLastError());
      //--- forced program termination
      return(-1);
      }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    //--- filling an array MA[] with current values of iMA
    //--- 100 elements should be written to the array
    //--- if there was an error, we terminate the execution of program
   if(CopyBuffer(MA_handle,0,0,100,MA)<=0) return;
   //--- set indexation of array MA[] as timeseries
   ArraySetAsSeries(MA,true);
   //--- here you can use the data of MA[] as you wish
   if(MA[0]>MA[1])
      {
      //--- some operations
      }
  }

Note that just a little change in the code has increased its safety and reliability. However, that's not all. Now the procedure of copying of the indicator's values to the array may be improved, it's necessary to use the function that has been written:

//+------------------------------------------------------------------------------+
//| The function copies the values of the indicator,the elements                 |
//| will be indexed depending on the value of the input parameter asSeries       |
//+------------------------------------------------------------------------------+
bool CopyBufferAsSeries(
                        int handle,      // indicator's handle
                        int bufer,       // buffer index
                        int start,       // start index
                        int number,      // number of elements to copy
                        bool asSeries,   // if it's true, the elements will be indexed as series
                        double &M[]      // target array
                        )
  {
//--- filling the array M with current values of the indicator
   if(CopyBuffer(handle,bufer,start,number,M)<=0) return(false);
//--- the elements will be indexed as follows:
//--- if asSeries=true, it will be indexed as timeseries
//--- if asSeries=false, it will be indexed as default
   ArraySetAsSeries(M,asSeries);
//---
   return(true);
  }

The function CopyBufferAsSeries is located in the file GetIndicatorBuffers.mqh, that is attached to the article. For its use, we have to add the directive include in our code. It's necessary to copy it into the folder ..\ MQL5\Include\. The final code that calls the indicator iMA and copies the data from the indicator's buffer to the corresponding array looks as follows:

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      MA[];                // array for the indicator iMA
//---- handles for indicators
int         MA_handle;           // handle for the indicator iMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iMA
   MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(MA_handle<0)
     {
      Print("The creation of iMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array MA[] with current values of iMA
//--- set indexation of array MA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(MA_handle,0,0,100,true,MA)) return;
//--- here you can use the data of MA[] as you wish, for example: 
   if(MA[0]>MA[1])
     {
      //--- some operations
     }
  }


Features of Multi-Buffer Indicators

As example, let's consider the indicator iAlligator, that has 3 indicator buffers:

  • 0 buffer - GATORJAW_LINE
  • 1st buffer - GATORTEETH_LINE
  • 2nd buffer - GATORLIPS_LINE

To perform the data receiving from these indicators' buffers using one call, we will use the following function, that can be found in the file, included to the article:

//+------------------------------------------------------------------------------+
//| The function copies the values of the indicator Alligator to three arrays:   |
//| Jaws[], Teeth[], Lips[] (with elements indexed as timeaseries).              |
//+------------------------------------------------------------------------------+
bool GetAlligatorBuffers(int Alligator_handle,
                         int start,
                         int number,
                         double &Jaws[],
                         double &Teeth[],
                         double &Lips[],
                         bool asSeries=true  // (elements indexed as timeaseries)
                         )
  {
//--- filling an array Jaws with current values of GATORJAW_LINE
   if(!CopyBufferAsSeries(Alligator_handle,0,start,number,asSeries,Jaws)) return(false);
//--- filling an array Teeth with current values of GATORTEETH_LINE
   if(!CopyBufferAsSeries(Alligator_handle,1,start,number,asSeries,Teeth)) return(false);
//--- filling an array Lisp with current values of GATORLIPS_LINE
   if(!CopyBufferAsSeries(Alligator_handle,2,start,number,asSeries,Lips)) return(false);
//---
   return(true);
  }

that can be used as follows:

#include <GetIndicatorBuffers.mqh>
//---- indicator buffers
double      Jaws[];   // array for GATORJAW_LINE of iAlligator
double      Teeth[];  // array for GATORTEETH_LINE of iAlligator
double      Lips[];   // array for GATORLIPS_LINE of iAlligator
//---- handles for indicators
int         Alligator_handle;           // handle of the indicator iAlligator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAlligator
   Alligator_handle=iAlligator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN);
//--- report if there was an error in object creation
   if(Alligator_handle<0)
     {
      Print("The creation of iAlligator has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- fill arrays with current values of Alligator
//--- return if there was an error
   if(!GetAlligatorBuffers(Alligator_handle,0,100,Jaws,Teeth,Lips,true)) return;
  }

So, we have outlined the key points, now we are ready to consider the examples for all standard indicators.

Examples of Use of Standard Indicators

iAC

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      AC[];                // array for the indicator iAC
//---- handles for indicators
int         AC_handle;           // handle of the indicator iAC
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAC
   AC_handle=iAC(NULL,0);
//--- report if there was an error in object creation
   if(AC_handle<0)
     {
      Print("The creation of iAC has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array AC[] with current values of iAC
//--- set indexation of array AC[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(AC_handle,0,0,100,true,AC)) return;
  }


iAD

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      AD[];                // array for the indicator iAD
//---- handles for indicators
int         AD_handle;           // handle for the indicator iAD
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAD
   AD_handle=iAD(NULL,0,VOLUME_TICK);
//--- report if there was an error in object creation
   if(AD_handle<0)
     {
      Print("The creation of iAD has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array AD[] with current values of iAD
//--- set indexation of array AD[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(AD_handle,0,0,100,true,AD)) return;
  }


iADX

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Main[];    // array for MAIN_LINE of iADX
double      PlusDI[];  // array for PLUSDI_LINE of iADX
double      MinusDI[]; // array for MINUSDI_LINE of iADX
//---- handles for indicators
int         ADX_handle;           // handle of the indicator iADX
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iADX
   ADX_handle=iADX(NULL,0,14);
//--- report if there was an error in object creation
   if(ADX_handle<0)
     {
      Print("The creation of iADX has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error 
   if(!GetADXBuffers(ADX_handle,0,100,Main,PlusDI,MinusDI,true)) return;
  }


iADXWilder

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Main[];    // array for MAIN_LINE of iADXWilder
double      PlusDI[];  // array for PLUSDI_LINE of iADXWilder
double      MinusDI[]; // array for MINUSDI_LINE of iADXWilder
//---- handles for indicators
int         ADXWilder_handle;           // handle of the indicator iADXWilder
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iADXWilder
   ADXWilder_handle=iADXWilder(NULL,0,14);
//--- report if there was an error in object creation
   if(ADXWilder_handle<0)
     {
      Print("The creation of iADXWilder has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetADXWilderBuffers(ADXWilder_handle,0,100,Main,PlusDI,MinusDI,true)) return;
  }


iAlligator

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Jaws[];   // array for GATORJAW_LINE of iAlligator
double      Teeth[];  // array for GATORTEETH_LINE of iAlligator
double      Lips[];   // array for GATORLIPS_LINE of iAlligator
//---- handles for indicators
int         Alligator_handle;           // handle of the indicator iAlligator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAlligator
   Alligator_handle=iAlligator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN);
//--- report if there was an error in object creation
   if(Alligator_handle<0)
     {
      Print("The creation of iAlligator has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetAlligatorBuffers(Alligator_handle,0,100,Jaws,Teeth,Lips,true)) return;
  }


iAMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      AMA[];                // array for the indicator iAMA
//---- handles for indicators
int         AMA_handle;           // handle for the indicator iAMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAMA
   AMA_handle=iAMA(NULL,0,21,5,8,0,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(AMA_handle<0)
     {
      Print("The creation of iAMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array AMA[] with current values of iAMA
//--- set indexation of array AMA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(AMA_handle,0,0,100,true,AMA)) return;
  }


iAO

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      AO[];                // array for the indicator iAO
//---- handles for indicators
int         AO_handle;           // handle of the indicator iAO
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iAO
   AO_handle=iAO(NULL,0);
//--- report if there was an error in object creation
   if(AO_handle<0)
     {
      Print("The creation of iAO has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array AO[] with current values of iAO
//--- set indexation of array AO[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(AO_handle,0,0,100,true,AO)) return;
  }


iATR

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      ATR[];                // array for the indicator iATR
//---- handles for indicators
int         ATR_handle;           // handle of the indicator iATR
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iATR
   ATR_handle=iATR(NULL,0,14);
//--- report if there was an error in object creation
   if(ATR_handle<0)
     {
      Print("The creation of iATR has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array ATR[] with current values of iATR
//--- set indexation of array ATR[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(ATR_handle,0,0,100,true,ATR)) return;
  }


iBearsPower

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      BearsPower[];                // array for the indicator iBearsPower
//---- handles for indicators
int         BearsPower_handle;           // handle for the indicator iBearsPower
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iBearsPower
   BearsPower_handle=iBearsPower(NULL,0,14);
//--- report if there was an error in object creation
   if(BearsPower_handle<0)
     {
      Print("The creation of iBearsPower has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array BearsPower[] with current values of iBearsPower
//--- set indexation of array BearsPower[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(BearsPower_handle,0,0,100,true,BearsPower)) return;
  }


iBands

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Base[];     // array for BASE_LINE of iBands
double      Upper[];    // array for UPPER_BAND of iBands
double      Lower[];    // array for LOWER_BAND of iBands
//---- handles for indicators
int         Bands_handle;           // handle of the indicator iBands
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iBands
   Bands_handle=iBands(NULL,0,144,0,2,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(Bands_handle<0)
     {
      Print("The creation of iBands has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetBandsBuffers(Bands_handle,0,100,Base,Upper,Lower,true)) return;
  }


iBullsPower

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      BullsPower[];                // array for the indicator iBullsPower
//---- handles for indicators
int         BullsPower_handle;           // handle for the indicatoriBullsPower
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iBullsPower
   BullsPower_handle=iBullsPower(NULL,0,14);
//--- report if there was an error in object creation
   if(BullsPower_handle<0)
     {
      Print("The creation of iBullsPower has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array BullsPower[] with current values of iBullsPower
//--- set indexation of array BullsPower[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(BullsPower_handle,0,0,100,true,BullsPower)) return;
  }


iCCI

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      CCI[];                // array for the indicator iCCI
//---- handles for indicators
int         CCI_handle;           // handle for the indicator iCCI
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iCCI
   CCI_handle=iCCI(NULL,0,14,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(CCI_handle<0)
     {
      Print("The creation of iCCI has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array CCI[] with current values of iCCI
//--- set indexation of array CCI[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(CCI_handle,0,0,100,true,CCI)) return;
  }


iChaikin

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Chaikin[];                // array for the indicator iChaikin
//---- handles for indicators
int         Chaikin_handle;           // handle for the indicator iChaikin
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iChaikin
   Chaikin_handle=iChaikin(NULL,0,8,14,MODE_EMA,VOLUME_TICK);
//--- report if there was an error in object creation
   if(Chaikin_handle<0)
     {
      Print("The creation of iChaikin has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array Chaikin[] with current values of iChaikin
//--- set indexation of array AC[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(Chaikin_handle,0,0,100,true,Chaikin)) return;
  }


iDEMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      DEMA[];                // array for the indicator iDEMA
//---- handles for indicators
int         DEMA_handle;           // handle for the indicator iDEMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iDEMA
   DEMA_handle=iDEMA(NULL,0,8,0,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(DEMA_handle<0)
     {
      Print("The creation of iDEMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array DEMA[] with current values of iDEMA
//--- set indexation of array DEMA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(DEMA_handle,0,0,100,true,DEMA)) return;
  }

iDeMarker

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      DeMarker[];                // array for the indicator iDeMarker
//---- handles for indicators
int         DeMarker_handle;           // handle for the indicator iDeMarker
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iDeMarker
   DeMarker_handle=iDeMarker(NULL,0,21);
//--- report if there was an error in object creation
   if(DeMarker_handle<0)
     {
      Print("The creation of iDeMarker has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array DeMarker[] with current values of iDeMarker
//--- set indexation of array DeMarker[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(DeMarker_handle,0,0,100,true,DeMarker)) return;
  }


iEnvelopes

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Upper[];    // array for UPPER_LINE of iEnvelopes
double      Lower[];    // array for LOWER_LINE of iEnvelopes
//---- handles for indicators
int         Envelopes_handle;           // handle of the indicator iEnvelopes
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iEnvelopes
   Envelopes_handle=iEnvelopes(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,0.1);
//--- report if there was an error in object creation
   if(Envelopes_handle<0)
     {
      Print("The creation of iEnvelopes has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation for arrays as timeseries
//--- return if there was an error
//--- filling the arrays with current values of iEnvelopes
   if(!GetEnvelopesBuffers(Envelopes_handle,0,100,Upper,Lower,true)) return;
  }

iForce

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Force[];                // array for the indicator iForce
//---- handles for indicators
int         Force_handle;           // handle for the indicator iForce
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iForce
   Force_handle=iForce(NULL,0,21,MODE_SMA,VOLUME_TICK);
//--- report if there was an error in object creation
   if(Force_handle<0)
     {
      Print("The creation of iForce has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array Force[] with current values of iForce
//--- set indexation of array Force[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(Force_handle,0,0,100,true,Force)) return;
  }


iFractals

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Upper[];    // array for UPPER_LINE of iFractals
double      Lower[];    // array for LOWER_LINE of iFractals
//---- handles for indicators
int         Fractals_handle;           // handle of the indicator iFractals
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iFractals
   Fractals_handle=iFractals(NULL,0);
//--- report if there was an error in object creation
   if(Fractals_handle<0)
     {
      Print("The creation of iFractals has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetFractalsBuffers(Fractals_handle,0,100,Upper,Lower,true)) return;
  }


iFrAMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      FrAMA[];                // array for the indicator iFrAMA
//---- handles for indicators
int         FrAMA_handle;           // handle for the indicator iFrAMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iFrAMA
   FrAMA_handle=iFrAMA(NULL,0,21,0,MODE_SMA);
//--- report if there was an error in object creation
   if(FrAMA_handle<0)
     {
      Print("The creation of iFrAMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array FrAMA[] with current values of iFrAMA
//--- set indexation of array FrAMA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(FrAMA_handle,0,0,100,true,FrAMA)) return;
  }


iGator

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Upper[];    // array for UPPER_LINE of iGator
double      Lower[];    // array for LOWER_LINE of iGator
//---- handles for indicators
int         Gator_handle;           // handle of the indicator iGator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iGator
   Gator_handle=iGator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN);
//--- report if there was an error in object creation
   if(Gator_handle<0)
     {
      Print("The creation of iGator has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetGatorBuffers(Gator_handle,0,100,Upper,Lower,true)) return;
  }


iIchimoku

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double   Tenkansen[];   // array for TENKANSEN_LINE of iIchimoku
double   Kijunsen[];    // array for KIJUNSEN_LINE of iIchimoku
double   SenkouspanA[]; // array for SENKOUSPANA_LINE of iIchimoku
double   SenkouspanB[]; // array for SENKOUSPANB_LINE of iIchimoku
double   Chinkouspan[]; // array for CHINKOUSPAN_LINE of iIchimoku
//---- handles for indicators
int      Ichimoku_handle;            // handle of the indicator iIchimoku
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iIchimoku
   Ichimoku_handle=iIchimoku(NULL,0,9,26,52);
//--- report if there was an error in object creation
   if(Ichimoku_handle<0)
     {
      Print("The creation of iIchimoku has failed: Runtime error =",GetLastError());
      //--- forced program terminatio
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetIchimokuBuffers(Ichimoku_handle,0,100,
      Tenkansen,
      Kijunsen,
      SenkouspanA,
      SenkouspanB,
      Chinkouspan,
      true)) return;
  }


iBWMFI

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      BWMFI[];                // array for the indicator iBWMFI
//---- handles for indicators
int         BWMFI_handle;           // handle of the indicato iBWMFI
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iBWMFI
   BWMFI_handle=iBWMFI(NULL,0,VOLUME_TICK);
//--- report if there was an error in object creation
   if(BWMFI_handle<0)
     {
      Print("The creation of iBWMFI has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array BWMFI[] with current values of iBWMFI
//--- set indexation of array BWMFI[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(BWMFI_handle,0,0,100,true,BWMFI)) return;
  }


iMomentum

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Momentum[];                // array for the indicator iMomentum
//---- handles for indicators
int         Momentum_handle;           // handle for the indicator iMomentum
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iMomentum
   Momentum_handle=iMomentum(NULL,0,14,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(Momentum_handle<0)
     {
      Print("The creation of iMomentum has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array Momentum[] with current values of iMomentum
//--- set indexation of array Momentum[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(Momentum_handle,0,0,100,true,Momentum)) return;
  }

iMFI

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      MFI[];                // array for the indicator iMFI
//---- handles for indicators
int         MFI_handle;           // handle of the indicator iMFI
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iMFI
   MFI_handle=iMFI(NULL,0,14,VOLUME_TICK);
//--- report if there was an error in object creation
   if(MFI_handle<0)
     {
      Print("The creation of iMFI has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array MFI[] with current values of iMFI
//--- set indexation of array MFI[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(MFI_handle,0,0,100,true,MFI)) return;
  }


iMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      MA[];                // array for the indicator iMA
//---- handles for indicators
int         MA_handle;           // handle of the indicator iMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iMA
   MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(MA_handle<0)
     {
      Print("The creation of iMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array MA[] with current values of iMA
//--- set indexation of array MA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(MA_handle,0,0,100,true,MA)) return;
  }

iOsMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      OsMA[];                // array for the indicator iOsMA
//---- handles for indicators
int         OsMA_handle;           // handle of the indicator iOsMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iOsMA
   OsMA_handle=iOsMA(NULL,0,8,21,14,PRICE_MEDIAN);
//--- report if there was an error in object creation
   if(OsMA_handle<0)
     {
      Print("The creation of iOsMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array OsMA[] with current values of iOsMA
//--- set indexation of array OsMA[] timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(OsMA_handle,0,0,100,true,OsMA)) return;
  }


iMACD

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Main[];    // array for MAIN_LINE of iMACD
double      Signal[];  // array for SIGNAL_LINE of iMACD
//---- handles for indicators
int         MACD_handle;           // handle of the indicator iMACD
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iMACD
   MACD_handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(MACD_handle<0)
     {
      Print("The creation of iMACD has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetMACDBuffers(MACD_handle,0,100,Main,Signal,true)) return;
  }

iOBV

#include <GetIndicatorBuffers.mqh>
//---- indicator buffers
double      OBV[];                // array for the indicator iOBV
//---- handles for indicators
int         OBV_handle;           // handle for the indicator iOBV
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iOBV
   OBV_handle=iOBV(NULL,0,VOLUME_TICK);
//--- report if there was an error in object creation
   if(OBV_handle<0)
     {
      Print("The creation of iOBV has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array OBV[] with current values of iOBV
//--- set indexation of array AC[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(OBV_handle,0,0,100,true,OBV)) return;
  }

iSAR

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      SAR[];                // array for the indicator iSAR
//---- handles for indicators
int         SAR_handle;           // handle of the indicator iSAR
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iSAR
   SAR_handle=iSAR(NULL,0,0.02,0.2);
//--- report if there was an error in object creation
   if(SAR_handle<0)
     {
      Print("The creation of iSAR has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array SAR[] with current values of iSAR
//--- set indexation of array SAR[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(SAR_handle,0,0,100,true,SAR)) return;
  }

iRSI

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      RSI[];                // array for the indicator iRSI
//---- handles for indicators
int         RSI_handle;           // handle of the indicator iRSI
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iRSI
   RSI_handle=iRSI(NULL,0,21,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(RSI_handle<0)
     {
      Print("The creation of iRSI has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array RSI[] with current values of iRSI
//--- set indexation of array RSI[] as timeserie
//--- return if there was an error
   if(!CopyBufferAsSeries(RSI_handle,0,0,100,true,RSI)) return;
  }

iRVI

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Main[];    // array for MAIN_LINE of iRVI
double      Signal[];  // array for SIGNAL_LINE of iRVI
//---- handles for indicators
int         RVI_handle;           // handle of the indicator iRVI
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iRVI
   RVI_handle=iRVI(NULL,0,14);
//--- report if there was an error in object creation
   if(RVI_handle<0)
     {
      Print("The creation of iRVI has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetRVIBuffers(RVI_handle,0,100,Main,Signal,true)) return;
  }

iStdDev

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      StdDev[];                // array for the indicator iStdDev
//---- handles for indicators
int         StdDev_handle;           // handle for the indicator iStdDev
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iStdDev
   StdDev_handle=iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(StdDev_handle<0)
     {
      Print("The creation of iStdDev has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array StdDev[] with current values of iStdDev
//--- set indexation of array StdDev[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(StdDev_handle,0,0,100,true,StdDev)) return;
  }


iStochastic

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Main[];    // array for MAIN_LINE of iStochastic
double      Signal[];  // array for SIGNAL_LINE of iStochastic
//---- handles for indicators
int         Stochastic_handle;           // handle of the indicator iStochastic
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iStochastic
   Stochastic_handle=iStochastic(NULL,0,5,3,3,MODE_SMA,STO_LOWHIGH);
//--- report if there was an error in object creation
   if(Stochastic_handle<0)
     {
      Print("The creation of iStochastic has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- set indexation of arrays as timeseries
//--- filling the arrays with current values of all indicator's buffers
//--- return if there was an error
   if(!GetStochasticBuffers(Stochastic_handle,0,100,Main,Signal,true)) return;
  }


iTEMA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      TEMA[];                // array for the indicator iTEMA
//---- handles for indicators
int         TEMA_handle;           // handle of the indicator iTEMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iTEMA
   TEMA_handle=iTEMA(NULL,0,20,0,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(TEMA_handle<0)
     {
      Print("The creation of iTEMA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array TEMA[] with current values of iTEMA
//--- set indexation of array TEMA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(TEMA_handle,0,0,100,true,TEMA)) return;
  }


iTriX

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      TriX[];                // array for the indicator iTriX
//---- handles for indicators
int         TriX_handle;           // handle of the indicator iTriX
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iTriX
   TriX_handle=iTriX(NULL,0,20,PRICE_CLOSE);
//--- report if there was an error in object creation
   if(TriX_handle<0)
     {
      Print("The creation of iTriX has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array TriX[] with current values of iTriX
//--- set indexation of array TriX[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(TriX_handle,0,0,100,true,TriX)) return;
  }


iWPR

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      WPR[];                // array for the indicator iWPR
//---- handles for indicators
int         WPR_handle;           // handle of the indicator iWPR
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iWPR
   WPR_handle=iWPR(NULL,0,14);
//--- report if there was an error in object creation
   if(WPR_handle<0)
     {
      Print("The creation of iWPR has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array WPR[] with current values of iWPR
//--- set indexation of array WPR[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(WPR_handle,0,0,100,true,WPR)) return;
  }


iVIDyA

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      VIDyA[];                // array for the indicator iVIDyA
//---- handles for indicators
int         VIDyA_handle;           // handle of the indicator iVIDyA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iVIDyA
   VIDyA_handle=iVIDyA(NULL,0,14,21,0,PRICE_MEDIAN);
//--- report if there was an error in object creation
   if(VIDyA_handle<0)
     {
      Print("The creation of iVIDyA has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array VIDyA[] with current values of iVIDyA
//--- set indexation of array VIDyA[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(VIDyA_handle,0,0,100,true,VIDyA)) return;
  }


iVolumes

#include <GetIndicatorBuffers.mqh>
//---- arrays for indicators
double      Volumes[];                // array for the indicator iVolumes
//---- handles for indicators
int         Volumes_handle;           // handle of the indicator iVolumes
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creation of the indicator iVolumes
   Volumes_handle=iVolumes(NULL,0,VOLUME_TICK);
//--- report if there was an error in object creation
   if(Volumes_handle<0)
     {
      Print("The creation of iVolumes has failed: Runtime error =",GetLastError());
      //--- forced program termination
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- filling an array Volumes[] with current values of iVolumes
//--- set indexation of array Volumes[] as timeseries
//--- return if there was an error
   if(!CopyBufferAsSeries(Volumes_handle,0,0,100,true,Volumes)) return;
  }

Conclusion

  1. The use of standard technical indicators in Expert Advisors in MQL5 is as easy, as it is in the previous version.
  2. Use only safe programming methods in your Expert Advisors - analyze and exclude all possible errors. The price of mistakes is too high, it's your deposit!

Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/31

Attached files |
Last comments | Go to discussion (5)
ts_
ts_ | 19 Mar 2010 at 03:07
useful article. :) waiting for trade operation's example.
Sergey Golubev
Sergey Golubev | 27 Feb 2014 at 16:46

Introduction to Technical Indicators (based on dailyfx aticle)

Trend Following

Trend following indicators were created to help traders trade currency pairs that are trending up or trending down. We have all heard the phrase “the trend is your friend.” These indicators can help point out the direction of the trend and can tell us if a trend actually exists.

Moving Averages

A Moving Average (MA for short) is a technical tool that averages a currency pair’s price over a period of time. The smoothing effect this has on the chart helps give a clearer indication on what direction the pair is moving… either up, down, or sideways. There are a variety of moving averages to choose from. Simple Moving Averages and Exponential Moving Averages are by far the most popular.

Ichimoku

Ichimoku is a complicated looking trend assistant that turns out to be much simpler than it initially appears. This Japanese indicator was created to be a standalone indicator that shows current trends, displays support/resistance levels, and indicates when a trend has likely reversed. Ichimoku roughly translates to “one glance” since it is meant to be a quick way to see how price is behaving on a chart.

ADX

The Average Direction Index takes a different method when it comes to analyzing trends. It won’t tell you whether price is trending up or down, but it will tell you if price is trending or is ranging. This makes it the perfect filter for either a range or trend strategy by making sure you are trading based on current market conditions.

Oscillators

Oscillators give traders an idea of how momentum is developing on a specific currency pair. When price treks higher, oscillators will move higher. When price drops lower, oscillators will move lower. Whenever oscillators reach an extreme level, it might be time to look for price to turn back around to the mean. However, just because an oscillator reaches “Overbought” or “Oversold” levels doesn’t mean we should try to call a top or a bottom. Oscillators can stay at extreme levels for a long time, so we need to wait for a valid sign before trading.

RSI

The Relative Strength Index is arguably the most popular oscillator out there. A big component of its formula is the ratio between the average gain and average loss over the last 14 periods. The RSI is bound between 0 – 100 and is considered overbought above 70 and oversold when below 30. Traders generally look to sell when 70 is crossed from above and look to buy when 30 is crossed from below.

Stochastics

Stochastics offer traders a different approach to calculate price oscillations by tracking how far the current price is from the lowest low of the last X number of periods. This distance is then divided by the difference between the high and low price during the same number of periods. The line created, %K, is then used to create a moving average, %D, that is placed directly on top of the %K. The result is two lines moving between 0-100 with overbought and oversold levels at 80 and 20. Traders can wait for the two lines to crosses while in overbought or oversold territories or they can look for divergence between the stochastic and the actual price before placing a trade.

CCI

The Commodity Channel Index is different than many oscillators in that there is no limit to how high or how low it can go. It uses 0 as a centerline with overbought and oversold levels starting at +100 and -100. Traders look to sell breaks below +100 and buy breaks above -100. To see some real examples of the CCI in action,

MACD

The Moving Average Convergence/Divergence tracks the difference between two EMA lines, the 12 EMA and 26 EMA. The difference between the two EMAs is then drawn on a sub-chart (called the MACD line) with a 9 EMA drawn directly on top of it (called the Signal line). Traders then look to buy when the MACD line crosses above the signal line and look to sell when the MACD line crosses below the signal line. There are also opportunities to trade divergence between the MACD and price.

Volatility

Volatility measures how large the upswings and downswings are for a particular currency pair. When a currency’s price fluctuates wildly up and down it is said to have high volatility. Whereas a currency pair that does not fluctuate as much is said to have low volatility. It’s important to note how volatile a currency pair is before opening a trade, so we can take that into consideration with picking our trade size and stop and limit levels.

Bollinger Bands®

Bollinger Bands print 3 lines directly on top of the price chart. The middle ‘band’ is a 20-period simple moving average with an upper and low ‘band’ that are drawn 2 standard deviations above and below the 20 MA. This means the more volatile the pair is, the wider the outer bands will become, giving the Bollinger Bands the ability to be used universally across currency pairs no matter how they behave. The wider the bands, the more volatile the pair. Most common uses for Bollinger Bands are trying to trade double tops/bottoms that hit an upper or lower band or looking to trade bounces off an outer band in the direction of the overall trend.
Bollinger Bands® is a registered trademark of John Bollinger.

ATR

The Average True Range tells us the average distance between the high and low price over the last X number of bars (typically 14). This indicator is presented in pips where the higher the ATR gets, the more volatile the pair, and vice versa. This makes it a perfect tool to measure volatility and also can be a huge help when selecting where we should set our stop losses.

Support/Resistance

Pivot Points

Being one of the older technical indicators, Pivot Points are one of the most widely used in all markets including equities, commodities, and Forex. They are created using a formula composed of high, low and close prices for the previous period. There is a central pivot line and subsequent support lines and resistance lines surrounding it. Traders use these lines as potential support and resistance levels, levels that price might have a difficult time breaking through.

Donchian Channels

Price channels or Donchian Channels are lines above and below recent price action that show the high and low prices over an extended period of time These lines can then act as support or resistance if price comes into contact with them again. A common use for Donchian channels is trading a break of a line in the direction of the overall trend. This strategy was made famous by Richard Dennis’ Turtle Traders where Dennis took everyday people and was able to successfully teach them how to trade futures based on price channels.

Michael Behr
Michael Behr | 5 Nov 2016 at 12:10

Hello Sergey,


I'm used to MT4 and starting to get involved with MT5.


Your article on https://www.mql5.com/en/articles/31      is one of the few with a clear structure and highly appreciated.


I copied your code partially and want to see/check custom indicator values in an EA.


This variation on built in indicators works fine:


OnInit part: MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);


OnTick Part: CopyBuffer(MA_handle,0,0,100,MA); ArraySetAsSeries(MA,true); Comment(MA[0]); the Comment shows the current MA value


---


now when using / replacing the iMA by MA_handle=iCustom(NULL,0,"ParabolicSAR", 0.04, 0.5 );


or my own indicator I get "-1" so even the built in Parabolic isn't adressed correctly ?!


I'd be very thankful for hints how to solve this.


---


Btw: my CustomIndicator I'd like to check in the next step has 5 inputs (A-E) and 3 buffers

OnInit part should probably be: MA_handle=iCustom(NULL, 0, "Indic. Name",A,B,C,D,E);

Hassan Raza Syed
Hassan Raza Syed | 9 Sep 2017 at 00:24

Excellent reference article. Helped me a lot! :)

Tobias Johannes Zimmer
Tobias Johannes Zimmer | 17 Jun 2021 at 21:53
I am irritated by the ArraySetAsSeries() inside the Ontick(). It should suffice to set it once, no?
Practical Implementation of Digital Filters in MQL5 for Beginners Practical Implementation of Digital Filters in MQL5 for Beginners
The idea of digital signal filtering has been widely discussed on forum topics about building trading systems. And it would be imprudent not to create a standard code of digital filters in MQL5. In this article the author describes the transformation of simple SMA indicator's code from his article "Custom Indicators in MQL5 for Newbies" into code of more complicated and universal digital filter. This article is a logical sequel to the previous article. It also tells how to replace text in code and how to correct programming errors.
Event handling in MQL5: Changing MA period on-the-fly Event handling in MQL5: Changing MA period on-the-fly
Suppose that simple MA (Moving Average) indicator with period 13 is applied to a chart. And we want to change the period to 20, but we do not want to go to indicator properties dialog box and edit the number 13 to 20: simply tired of these tedious actions with mouse and keyboard. And especially we don't want to open indicator code and modify it. We want to do all this with a single press of a button - "up arrows" next to the numeric keypad. In this article I'll describe how to do it.
The Drawing Styles in MQL5 The Drawing Styles in MQL5
There are 6 drawing styles in MQL4 and 18 drawing styles in MQL5. Therefore, it may be worth writing an article to introduce MQL5's drawing styles. In this article, we will consider the details of drawing styles in MQL5. In addition, we will create an indicator to demonstrate how to use these drawing styles, and refine the plotting.
How to call indicators in MQL5 How to call indicators in MQL5
With new version of MQL programming language available not only the approach of dealing with indicators have changed, but there are also new ways of how to create indicators. Furthermore, you have additional flexibility working with indicator's buffers - now you can specify the desired direction of indexing and get exactly as many indicator's values as you want. This article explains the basic methods of calling indicators and retrieving data from the indicator's buffers.