MQL4 to MQL5

 

Hi guys  i am at the beginning of learning mql5 and trying to convert  an indicator. Its not plotting any idea what i

#property copyright "T/oligarch"
#property link      "t/o"
#property version   "1.00"

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers  12  // Number of buffers
#property indicator_plots   4

#property strict
#property indicator_type1   DRAW_LINE
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_LINE
#property indicator_type4   DRAW_LINE
#property indicator_type5   DRAW_LINE
#property indicator_type6   DRAW_LINE

#property indicator_color1 White    // Line color of 0 buffer
#property indicator_color2 DarkOrange//Line color of the 1st buffer
#property indicator_color3 Green    // Line color of the 2nd buffer
#property indicator_color4 Brown    // Line color of the 3rd buffer
#property indicator_color5 Blue     // Line color of the 4th buffer
#property indicator_color6 Red      // Line color of the 5th buffer

//--- input parameters

input int History    =5000;        // Amount of bars in calculation his-tory
input double Period_MA_1=21;          // Period of calculated MA
input double Bars_V     =13;          // Amount of bars for calc. rate
input double Aver_Bars=5   ;           // Amount of bars for smoothing

//--- indicator buffers

double   ExtLine_0[];                        // Indicator array of supp. MA
double  ExtLine_1[]; 
double  ExtLine_2[]; 
double   ExtLine_3[];    // Indicator array of rate lines 
double  ExtLine_4[];                        // Indicator array - sum
double   ExtLine_5[];         
double MA_c_1Buffer[];
double   MA_p_1Buffer[]; 
double   MA_c_2Buffer[]; 
double   MA_p_2Buffer[];
double    MA_cBuffer[];
double  MA_pBuffer[];


               // Indicator array - sum, smoothed
int   ExtSh_1;
int    ExtSh_2;
int    ExtSh_3;                // Amount of bars for rates calc.

int MA_c_1Handle;
int  MA_p_1Handle; 
int   MA_c_2Handle; 
int  MA_p_2Handle;
int   MA_cHandle;
int  MA_pHandle;

//--- global variable


double   ExtPeriod_MA_2;  
double   ExtPeriod_MA_3;       // Calculation periods of MA for other timefr.
double  ExtK2; 
double   ExtK3;                          // Coefficients of timeframe correla-tion

//+------------------------------------------------------------------+
//| Rate of Change initialization function                           |
//+------------------------------------------------------------------+

int init()
  {
    SetIndexBuffer(0,ExtLine_0,INDICATOR_DATA);   //--- indicator buffers mapping
    SetIndexBuffer(1,ExtLine_1,INDICATOR_DATA);
    SetIndexBuffer(2,ExtLine_2,INDICATOR_DATA);
    SetIndexBuffer(3,ExtLine_3,INDICATOR_DATA);
    SetIndexBuffer(4,ExtLine_4,INDICATOR_DATA);
    SetIndexBuffer(5,ExtLine_5,INDICATOR_DATA);
    
    SetIndexBuffer(6, MA_c_1Buffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(7, MA_p_1Buffer,INDICATOR_CALCULATIONS);
    SetIndexBuffer(8, MA_c_2Buffer,INDICATOR_CALCULATIONS);
    SetIndexBuffer(9, MA_p_2Buffer,INDICATOR_CALCULATIONS);
    SetIndexBuffer(10, MA_cBuffer,INDICATOR_CALCULATIONS);
    SetIndexBuffer(11, MA_pBuffer,INDICATOR_CALCULATIONS);
    
    
    IndicatorSetInteger(INDICATOR_DIGITS,2);  //--- set accuracy

   
//--- sets first bar from what index will be drawn
        PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);      
        PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);      
        PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_LINE);      
       
        PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_LINE);      
     
        PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_LINE);
        PlotIndexSetInteger(5,PLOT_DRAW_TYPE,DRAW_LINE);      
        
        PlotIndexSetInteger(0,PLOT_LINE_COLOR,White); 
        PlotIndexSetInteger(1,PLOT_LINE_COLOR,DarkOrange); 
        PlotIndexSetInteger(2,PLOT_LINE_COLOR,Green); 
        PlotIndexSetInteger(3,PLOT_LINE_COLOR,Brown);       
        PlotIndexSetInteger(4,PLOT_LINE_COLOR,Blue); 
        PlotIndexSetInteger(5,PLOT_LINE_COLOR,Red);

  
//--- initialization done
switch (Period())                 // Calculating coefficient for..
     {                              // .. different timeframes
      case     1: ExtK2=5;ExtK3=15; break;// Timeframe M1
      case     5: ExtK2=3;ExtK3= 6; break;// Timeframe M5
      case    15: ExtK2=2;ExtK3= 4; break;// Timeframe M15
      case    30: ExtK2=2;ExtK3= 8; break;// Timeframe M30
      case    16385: ExtK2=4;ExtK3=24; break;// Timeframe H1
      case    16388: ExtK2=6;ExtK3=42; break;// Timeframe H4
      case  16408: ExtK2=7;ExtK3=30; break;// Timeframe D1
      case  32769: ExtK2=4;ExtK3=12; break;// Timeframe W1
      case 49153: ExtK2=3;ExtK3=12; break;// Timeframe MN
     }
//--------------------------------------------------------------- 6 --
   ExtSh_1=Bars_V;                     // Period of rate calcul. (bars)
   ExtSh_2=ExtK2*ExtSh_1;                    // Calc. period for nearest TF
   ExtSh_3=ExtK3*ExtSh_1;                    // Calc. period for next TF
   ExtPeriod_MA_2 =ExtK2*Period_MA_1;     // Calc. period of MA for nearest TF
   ExtPeriod_MA_3 =ExtK3*Period_MA_1;     // Calc. period of MA for next TF
//--------------------------------------------------------------- 7 --
   return(0);                          // Exit the special function init()
  }
  
//+------------------------------------------------------------------+
//| Rate of Change                                                   |
//+------------------------------------------------------------------+
 

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

                    // Special function start()
  {
//--------------------------------------------------------------- 9 --
  
    double MA_c_1;
    double   MA_p_1; 
    double   MA_c_2; 
    double   MA_p_2;
    double    MA_c;
    double  MA_p;
    double   Sum; 
                                // Technical param. for sum accumul.
   int
   i,                               // Bar index
   n,                               // Formal parameter (bar index)
   Counted_bars;                    // Amount of counted bars 
   
//-------------------------------------------------------------- 10 --
  Counted_bars=prev_calculated; // Amount of counted bars 
  i=rates_total-Counted_bars-1;
                                     //Index of the first uncounted
 if (i>History-1)                 // If too many bars ..
  i=History-1;                  // ..calculate specified amount
//-------------------------------------------------------------- 11 --
   while(i>=0)                      // Loop for uncounted bars
     {
      //-------------------------------------------------------- 12 --
      ExtLine_0[i]=0;                  // Horizontal reference line88888888888888888888
      //-------------------------------------------------------- 13 --
      MA_c_1Handle=iMA(NULL,0,Period_MA_1,0,MODE_LWMA,PRICE_TYPICAL);
      CopyBuffer(MA_c_1Handle,0,i,i,MA_c_1Buffer);
      
      MA_p_1Handle=iMA(NULL,0,Period_MA_1,0,MODE_LWMA,PRICE_TYPICAL);
      MA_p_1=CopyBuffer(MA_p_1Handle,0,i+ExtSh_1,0,MA_p_1Buffer);  
      ExtLine_1[i]= MA_c_1Buffer[i]-MA_p_1Buffer[i];         // Value of 1st rate line
      //-------------------------------------------------------- 14 --
      MA_c_2Handle=iMA(NULL,0,ExtPeriod_MA_2,0,MODE_LWMA,PRICE_TYPICAL);
      MA_c_2=CopyBuffer(MA_c_2Handle,0,i,0,MA_c_2Buffer);
      
      MA_p_2Handle=iMA(NULL,0,ExtPeriod_MA_2,0,MODE_LWMA,PRICE_TYPICAL);
      MA_p_2=CopyBuffer(MA_p_2Handle,0,i+ExtSh_2,0,MA_p_2Buffer);
        
      ExtLine_2[i]= MA_c_2-MA_p_2;         // Value of 2nd rate line
      //-------------------------------------------------------- 15 --
     MA_cHandle=iMA(NULL,0,ExtPeriod_MA_3,0,MODE_LWMA,PRICE_TYPICAL);
      MA_c= CopyBuffer(MA_cHandle,2,i,0,MA_cBuffer);
     
      MA_pHandle=iMA(NULL,0,ExtPeriod_MA_3,0,MODE_LWMA,PRICE_TYPICAL);
      MA_pHandle=CopyBuffer(MA_pHandle,2,i+ExtSh_3,0,MA_pBuffer);
      ExtLine_3[i]= MA_c-MA_p;         // Value of 3rd rate line      
     //-------------------------------------------------------- 16 --
     ExtLine_4[i]=((ExtLine_1[i]+ExtLine_2[i]+ExtLine_3[i])/3);// Summary array
 
      i--;                          // Calculating index of the next bar
      //-------------------------------------------------------- 19 --
     }
   return(0);                          // Exit the special function start()
  }











am leaving out?

 
oligarch101:

Hi guys  i am at the beginning of learning mql5 and trying to convert  an indicator. Its not plotting any idea what i

am leaving out?

1. Click "New" in "MetaEditor" to create a template and then start it.


2. "ExtLine_5" is not used.

3. Get handles in "OnInit".

4. Why is the return value used in the calculation instead of the copied value?

ExtLine_2[i]= MA_c_2-MA_p_2;         // Value of 2nd rate line
ExtLine_3[i]= MA_c-MA_p;         // Value of 3rd rate line 

5. ArraySetAsSeries" needs to be set to "true".

 
Check indicator_plots.

Check indicator_type
Check indicator_color

They don't match
 
Same problem
 
Please post your code.