How To Update Custom Indicator On Evey Tick

 
I have a Custom Indicator, but i have a problem, When New Candles Come, It Dosn't Work As Well, Until I click On Compile Button, I want It To Be Update On Every Tick
//+------------------------------------------------------------------+
//|                                                    
//|                   Copyright 2017,Navid Aria
//|                                   
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,Navid Aria"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_label1 "time M1"
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3

#property indicator_color2 clrBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 3
#property indicator_label2 "time M5"


double buffer1[],buffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
 SetIndexBuffer(0,buffer1);  
 SetIndexBuffer(1,buffer2); 
 IndicatorDigits(3);
//---
   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[])
  {
  
datetime time1[];
 
ArrayCopySeries(time1,MODE_TIME,NULL,PERIOD_M5);
  
int i,y;
  
for(i=0,y=0;i<Bars-prev_calculated;i++)
{

if(Time[i]<time1[y])y++;

 buffer1[i]=iMA(NULL,PERIOD_M1,10,0,MODE_EMA,PRICE_CLOSE,i);
 buffer2[i]=iMA(NULL,PERIOD_M5,16,0,MODE_SMMA,PRICE_CLOSE,y);

}   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
sepehrreyes I want It To Be Update On Every Tick
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. It is being called every tick. It is your Bars-prev_calculated that is the problem; it is zero after the initial run, so your loop does nothing.
              How to do your lookbacks correctly #9 - #14 & #19

  3. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20

 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. It is being called every tick. It is your Bars-prev_calculated that is the problem; it is zero after the initial run, so your loop does nothing.
              How to do your lookbacks correctly #9 - #14 & #19

  3. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20

well, Thanks a Lot, I will Do What Ever You Say, Best Wishes
 
Navid Aria: Thanks a Lot, I will Do What Ever You Say, Best Wishes

Don't double post! You already had this thread open.
          General rules and best pratices of the Forum. - General - MQL5 programming forum 2017.07.19

 
Navid Aria:

Do not double Post!!!

You have already been told and yet You duplicate this topic again.

I have deleted your duplicated topic.

 

You are copying the whole M5 history for each and every tick, this is not performant:

ArrayCopySeries(time1,MODE_TIME,NULL,PERIOD_M5);

If your indicator is working on a different timeframe than M5, you need to handle history-not-found errors.

I think it is easier to drop the ArrayCopySeries approach and use iBarShift to get the matching M5 bar index.

Reason: