Filling an indicator buffer inside a for loop gives "array out of range"

 

Hi

This mql5 code produces a run time error "array out of range", could some one please help to fix it?

An array with double data type in "file2.mqh" needs to be ploted with each value reduced by a given number. I have done some reading as this is the first time to code this.

Thank you.

//file1.mq5
#include file2.mqh #property indicator_buffers 1 #property indicator_plots   1 #property indicator_type1   DRAW_LINE #property indicator_color1  clrDodgerBlue double    myBuffer[]; fillMyBuffer(myBuffer);
//file2.mqh
int indHandle = iMA(_Symbol, _Period, 14, 0, MODE_SMA, PRICE_WEIGHTED); double myArr[]; if (CopyBuffer(indHandle, 0, 0, 500, myArr) <= 0) return;     void fillMyBuffer(double &arr[]){       for(int i = 0; i < ArraySize(myArr); i++){         arr[i] = myArr[i] - 158;       }     }
 
    void fillMyBuffer(double &arr[]){
      ArrayResize(arr, ArraySize(myArr));
      for(int i = 0; i < ArraySize(myArr); i++){
        arr[i] = myArr[i] - 158;
      }
    }
 

Thanks Konstantin,

I got that fixed, but after the code is run, I do not see the plotting of the line. Did I miss something else in order to see the line on the main chart window? 

Reason: