MT5 Easy Indicator Issue

 

I am programming in mql4 for 3 years and this week i tried to create my first indicator on mql5.

I am trying to create and indicator that draws a line that connects the Open Prices of the candles.

The line that i see on charts is very weird(check the photo). At some timeframes i do not see anything at all. Could you tell me please what is wrong with my code?


//+------------------------------------------------------------------+
//|                                                     openLine.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red



double ExtLineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
void OnInit()
  {
   SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
  
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
  {
     
    for(int bar=1;bar<rates_total-1;bar++)
     {
     
    double   open1=iOpen(Symbol(),PERIOD_CURRENT,bar);

      ExtLineBuffer[bar]=NormalizeDouble( open1, _Digits );
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
 
Loko15:

The line that i see on charts is very weird(check the photo). At some timeframes i do not see anything at all. Could you tell me please what is wrong with my code?

The values returned by "iOpen" will be in the reverse order. (That is, the same as MQL4)

Add the following one line.

ArraySetAsSeries(ExtLineBuffer, true);
 

When I create an indicator, I always create a template using the 'MQL Wizard':


Several necessary steps:

Yu

After that, a blank is received:

//+------------------------------------------------------------------+
//|                                                    Open Line.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Open
#property indicator_label1  "Open"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellowGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         OpenBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


It remains to add a few lines and the indicator is ready:

//+------------------------------------------------------------------+
//|                                                    Open Line.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Open
#property indicator_label1  "Open"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellowGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         OpenBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit;i<rates_total;i++)
     {
      OpenBuffer[i]=open[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Files:
Open_Line.mq5  5 kb
Reason: