how to convert this code

 

hi there i wanted to know how to convert 

   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0)
      return(-1);
   if(counted_bars>0)
      counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);

this from mql 4 to mql 5 code

 
Falcon23:

hi there i wanted to know how to convert 

this from mql 4 to mql 5 code

MQL5:

//--- main loop
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
      {
       ***
      }
 
Vladimir Karputov #:

MQL5:

hi there thanks for the reply where should i fill the  prev_calculated var and where?
 
Falcon23 # :
hi there thanks for the reply where should i fill the  prev_calculated var and where?

What do you mean where ??? It is always there!

//+------------------------------------------------------------------+
//| 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[])
  {
 
Vladimir Karputov #:

What do you mean where ??? It is always there!

im a newBee sir actually i can not find any equivalents for 
IndicatorCounted

function if u could give me a detailed reply on how to convert the code above which is from mql4 to mql5 i would be thankfull.

 
Falcon23 # :
im a newBee sir actually i can not find any equivalents for 

function if u could give me a detailed reply on how to convert the code above which is from mql4 to mql5 i would be thankfull.

There are none 'IndicatorCounted'. Please read the help: OnCalculate

A simple indicator:

//+------------------------------------------------------------------+
//|                                             Simple Indicator.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot High
#property indicator_label1  "High"
#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         HighBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer,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++)
     {
      HighBuffer[i]=high[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Result:

Documentation on MQL5: Event Handling / OnCalculate
Documentation on MQL5: Event Handling / OnCalculate
  • www.mql5.com
OnCalculate - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Reason: