MT5 PROBLEM / BUG. Report to service desk?

 

My custom indicator works as desired sometimes, but other times it doesn't work at all.  When it fails, it is because the CopyBuffer() function fails to access requested rates. (See below).  I've looked through the docs, and I don't think there is any coding I can do to make the indicator work reliably. So, I feel it must be a bug in metatrader 5. Should I report to service desk?

//+------------------------------------------------------------------+
//|                                                myCorrelation.mq5 |
//|                                              Copyright 2013, Joe |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "2.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_applied_price PRICE_CLOSE
#include <Math\Alglib\alglib.mqh>
//---- plot CORRELATION
#property indicator_label1  "CORR"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#property indicator_minimum -1
#property indicator_maximum 1
//--- input parameters
input string  secondSymbol="EURUSD";  // Second symbol
input int     setPeriod=1440; 
//--- indicator buffers and handles
double         CORRBuffer[];
double         TempDataBuffer1[];
int            ExtHandle=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,CORRBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,TempDataBuffer1,INDICATOR_CALCULATIONS);
//--- bar, starting from which the indicator is drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,setPeriod);
   string shortname;
   StringConcatenate(shortname,"CORR(",secondSymbol,",",setPeriod,")");
//--- set a label do display in DataWindow
   PlotIndexSetString(0,PLOT_LABEL,shortname);   
//--- set a name to show in a separate sub-window or a pop-up help
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- set accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- 
   ExtHandle=iMA(secondSymbol,0,1,0,MODE_SMA,PRICE_CLOSE);
   if(ExtHandle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,    // size of the price[] array;
                 const int prev_calculated,// number of available bars;
                 // at the previous call;
                 const int begin,// from what index of the 
                 // price[] array true data start;
                 const double &price[]) // array, at which the indicator will be calculated;
  {
//--- get price array for second currency pair, same length as &price[] array 
   int copy=CopyBuffer(ExtHandle,0,0,rates_total,TempDataBuffer1);
   if(copy!=rates_total)
     {
      Print("failed to copy requested number of elements");
      //usually garbage values from TempDataBuffer1[0]] to TempDataBuffer1[rates_total-copy], if this loop is entered
      return 0;
     }       
//--- calculate correlation
    double TempDataBuffer2[];
    double TempDataBuffer3[];
    int start;
    if(prev_calculated==0) start=setPeriod; // set the starting index for input arrays
    else start=prev_calculated-1;    // set 'start' equal to the last index in the arrays
    for(int i=start;i<rates_total;i++)
      {
       ArrayCopy(TempDataBuffer2,TempDataBuffer1,0,i-setPeriod,setPeriod);
       ArrayCopy(TempDataBuffer3,price,0,i-setPeriod,setPeriod);  
       CORRBuffer[i]=CAlglib::PearsonCorr2(TempDataBuffer2,TempDataBuffer3);
       ArrayFree(TempDataBuffer2);
       ArrayFree(TempDataBuffer3);
      }     
//--- return   
   return(rates_total);

  }
 
oneilljo:

My custom indicator works as desired sometimes, but other times it doesn't work at all.  When it fails, it is because the CopyBuffer() function fails to access requested rates. (See below).  I've looked through the docs, and I don't think there is any coding I can do to make the indicator work reliably. So, I feel it must be a bug in metatrader 5. Should I report to service desk?

Your code assumes that the bar secondSymbol is already available. But rates_total may be different for that symbol. You need to include a check and anyway should avoid requesting the complete data of the ma on each call of OnCalculate which happens every tick.

 
oneilljo:

My custom indicator works as desired sometimes, but other times it doesn't work at all.  When it fails, it is because the CopyBuffer() function fails to access requested rates. (See below).  I've looked through the docs, and I don't think there is any coding I can do to make the indicator work reliably. So, I feel it must be a bug in metatrader 5. Should I report to service desk?

Hi, you have to understand how multi-currency indicator works, and fix your code, as ugo58 suggest you.

It's not a bug in MT5. Feel free to ask more help.