Wrong values retrieved from indicator buffers

 

I just moved from mql4 to mql5 , and honestly mql4 was much easier then mql5 in most cases ,

anyhow i am trying to read  buffers values from an indicator , but it only shows me 0 instead of the actual buffer value.7


Here is my code :

#property version   "1.00"

int handle1 = 0;

double valu1,valu2,valu3,valu4;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   handle1 = iCustom(NULL, NULL, "LTD by KDMfx");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   IndicatorRelease(handle1);
  }

 


//+------------------------------------------------------------------+
//| Get indicator value                                              |
//+------------------------------------------------------------------+
double GetIndicator(int handle, int buffer_num, int index)
  {
 
   double arr[];
 
   if(CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0)
     {
      Sleep(200);
      for(int i=0; i<100; i++)
        {
         if(BarsCalculated(handle) > 0)
            break;
         Sleep(50);
        }
      int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr);
      if(copied <= 0)
        {
         Print("CopyBuffer failed. Maybe history has not download yet? Error = ", GetLastError());
         return -1;
        }
      else
         return (arr[index]);
     }


   return 0;
  }



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   valu1 = GetIndicator(handle1,0,4);
   valu2 = GetIndicator(handle1,1,4);
   valu3 = GetIndicator(handle1,2,4);
   valu4 = GetIndicator(handle1,3,4);
   
   Comment("b1: ", valu1,
            "\nb2: ", valu2,
               "\nb3: ", valu3,
                  "\nb4: ", valu4 
            
            );
  }

 

what am i doing wrong here ?

 
Arad_1:

I just moved from mql4 to mql5 , and honestly mql4 was much easier then mql5 in most cases ,

It's also easier to drive a car than a plane.

anyhow i am trying to read  buffers values from an indicator , but it only shows me 0 instead of the actual buffer value.7


Here is my code :

what am i doing wrong here ?

double GetIndicator(int handle, int buffer_num, int index)
  {
 
   double arr[];
 
   if(CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0)
     {
      ...this is error processing
     }


   return 0;
  }
Why are you expecting something else than 0 ?
Reason: