Calling a function from a subwindow indicator to populate fields - page 2

 

I gutted the two indicators, and made a very simple version of the attempt to have one indicator read a buffer from another custom indicator.

Here is the full code of each indicator.


Main Indicator:

//A_indicator_Main_Window.mq5


#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 0


double         TrendData[];

int ThisBarTrade = 0;  

int OnInit()
  {
   SetIndexBuffer(0,TrendData,INDICATOR_DATA);
   return(INIT_SUCCEEDED);
}

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[])                      {
   if(prev_calculated==0){
      for(int j=0;j<14;j++){
         TrendData[j] = 123.123;
         Alert("TrendData[", j, "] = ", TrendData[ThisBarTrade]);
      }
   } else {
   
      if( Bars(_Symbol,_Period) != ThisBarTrade) {
         for(int j=0;j<14;j++){
            TrendData[j] = 123.123;
            Alert("TrendData[", j, "] = ", TrendData[ThisBarTrade]);
         }

       }
   }
   return(rates_total);
}



Second Indicator, which attempts to read a buffer from the first indicator

//B_Indicator_Data_Window.mq5

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 0

double TrendDataBuffer[];

int ThisBarTrade = 0;  
int TrendDataHandle = 0;

int OnInit(){
     ArrayResize(TrendDataBuffer,14);
     ArrayInitialize(TrendDataBuffer,EMPTY_VALUE);
     
     TrendDataHandle = iCustom(NULL,NULL,"A_indicator_Main_Window.ex5",5);
     if(TrendDataHandle == -1){
         Alert("A_Indicator_Main_Window.ex5 could not be accessed. TrendDataHandle = ",TrendDataHandle,"  error = ",GetLastError());
     }
   return(0);
}
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]){
   
   int CopyBufferSize = 0;
   if(prev_calculated==0){
      if( Bars(_Symbol,_Period) != ThisBarTrade) {
    
         ThisBarTrade = Bars(_Symbol,_Period);
         CopyBufferSize =  CopyBuffer(TrendDataHandle,0,0,14,TrendDataBuffer);     
         Alert("CopyBufferSize is ", CopyBufferSize);
         if(CopyBufferSize > 0){  
            for( int i =0 ; i < CopyBufferSize; i++){
                  Alert("TrendDataBuffer[", i, "] = ", TrendDataBuffer[i]);
            }
         }
            
     }
  }
  return(rates_total);
}


On some timeframes, the copied buffer is populated with all zeros. On other timeframes, the copied buffer is full of random data.

I must be overlooking something quite simple here. But, in reviewing good code that I know works, and comparing to this code, I cannot find the differences.