Почему я постоянно получаю ошибку в OpenCL версии Bollinger Bands

 
#property copyright   "MetaQuotes Ltd."
#property link        "www.mql5.com"
#property description "Bollinger Bands (OpenCL version)"
#include <OpenCL/OpenCL.mqh>

// Встраиваем файл кернела в ресурсы
#resource "Files\\bb_kernel.txt" as string bbKernelSource

//--- индикатор будет рисоваться в окне графика
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   3

//--- настройки линий
#property indicator_type1   DRAW_LINE
#property indicator_color1  LightSeaGreen
#property indicator_type2   DRAW_LINE
#property indicator_color2  LightSeaGreen
#property indicator_type3   DRAW_LINE
#property indicator_color3  LightSeaGreen

#property indicator_label1  "Bands middle"
#property indicator_label2  "Bands upper"
#property indicator_label3  "Bands lower"

//--- входные параметры
input int     InpBandsPeriod     = 20;       // Period
input int     InpBandsShift      = 0;        // Shift
input double  InpBandsDeviations = 2.0;      // Deviation

//--- глобальные переменные для параметров
int    ExtBandsPeriod, ExtBandsShift;
double ExtBandsDeviations;
int    ExtPlotBegin = 0;

//--- индикаторные буферы
double ExtMLBuffer[];
double ExtTLBuffer[];
double ExtBLBuffer[];
double ExtStdDevBuffer[];

//--- экземпляр OpenCL
COpenCL openCL;

//--- Максимальное окно обработки (один день = 1440 баров на M1)
#define MAX_WINDOW 6000

//--- Размер буфера (в байтах)
int g_bufferSize = MAX_WINDOW * sizeof(float);

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
   // Проверка входных параметров
   if(InpBandsPeriod < 2)
     {
      ExtBandsPeriod = 20;
      PrintFormat("Incorrect InpBandsPeriod=%d. Using %d.", InpBandsPeriod, ExtBandsPeriod);
     }
   else
      ExtBandsPeriod = InpBandsPeriod;
      
   if(InpBandsShift < 0)
     {
      ExtBandsShift = 0;
      PrintFormat("Incorrect InpBandsShift=%d. Using %d.", InpBandsShift, ExtBandsShift);
     }
   else
      ExtBandsShift = InpBandsShift;
      
   if(InpBandsDeviations == 0.0)
     {
      ExtBandsDeviations = 2.0;
      PrintFormat("Incorrect InpBandsDeviations=%f. Using %f.", InpBandsDeviations, ExtBandsDeviations);
     }
   else
      ExtBandsDeviations = InpBandsDeviations;
      
   // Назначаем индикаторные буферы
   SetIndexBuffer(0, ExtMLBuffer);
   SetIndexBuffer(1, ExtTLBuffer);
   SetIndexBuffer(2, ExtBLBuffer);
   SetIndexBuffer(3, ExtStdDevBuffer, INDICATOR_CALCULATIONS);
   
   PlotIndexSetString(0, PLOT_LABEL, "Bands(" + string(ExtBandsPeriod) + ") Middle");
   PlotIndexSetString(1, PLOT_LABEL, "Bands(" + string(ExtBandsPeriod) + ") Upper");
   PlotIndexSetString(2, PLOT_LABEL, "Bands(" + string(ExtBandsPeriod) + ") Lower");
   
   IndicatorSetString(INDICATOR_SHORTNAME, "Bollinger Bands");
   
   ExtPlotBegin = ExtBandsPeriod - 1;
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ExtBandsPeriod);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ExtBandsPeriod);
   PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, ExtBandsPeriod);
   
   PlotIndexSetInteger(0, PLOT_SHIFT, ExtBandsShift);
   PlotIndexSetInteger(1, PLOT_SHIFT, ExtBandsShift);
   PlotIndexSetInteger(2, PLOT_SHIFT, ExtBandsShift);
   
   IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1);
   
   // Инициализация OpenCL
   if(!openCL.Initialize(bbKernelSource))
   {
      Print("OpenCL initialization failed");
      return;
   }
   
   if(!openCL.SetKernelsCount(1))
   {
      Print("Failed to set kernels count");
      return;
   }
   if(!openCL.KernelCreate(0, "bollinger"))
   {
      Print("Failed to create kernel 'bollinger'");
      return;
   }

   // Создаем входной и выходные буферы один раз в OnInit
   if(!openCL.BufferCreate(0, g_bufferSize, CL_MEM_READ_WRITE))
   {
      Print("Error creating input buffer (price) in OnInit");
      return;
   }
   if(!openCL.BufferCreate(1, g_bufferSize, CL_MEM_WRITE_ONLY))
   {
      Print("Error creating output buffer for MA in OnInit");
      return;
   }
   if(!openCL.BufferCreate(2, g_bufferSize, CL_MEM_WRITE_ONLY))
   {
      Print("Error creating output buffer for Upper in OnInit");
      return;
   }
   if(!openCL.BufferCreate(3, g_bufferSize, CL_MEM_WRITE_ONLY))
   {
      Print("Error creating output buffer for Lower in OnInit");
      return;
   }
   if(!openCL.BufferCreate(4, g_bufferSize, CL_MEM_WRITE_ONLY))
   {
      Print("Error creating output buffer for StdDev in OnInit");
      return;
   }
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   openCL.Shutdown();
  }
  
//+------------------------------------------------------------------+
//| Bollinger Bands calculation function                             |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   if(rates_total < ExtPlotBegin)
      return(0);
      
   if(ExtPlotBegin != ExtBandsPeriod + begin)
   {
      ExtPlotBegin = ExtBandsPeriod + begin;
      PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ExtPlotBegin);
      PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ExtPlotBegin);
      PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, ExtPlotBegin);
   }
     
   // Обрабатываем данные за один день (MAX_WINDOW = 1440)
   int N = (rates_total < MAX_WINDOW) ? rates_total : MAX_WINDOW;
   int start_index = rates_total - N;
   
    
   // Размер буфера фиксирован: g_bufferSize = MAX_WINDOW * sizeof(float)
   int data_size = g_bufferSize;
   //Print("Processing N=", N, ", data_size=", data_size);
   
   float fprice[];
   ArrayResize(fprice, N);
   for(int i = 0; i < N; i++)
   fprice[i] = (float)price[start_index + i];
   
   if(!openCL.BufferWrite(0, fprice, 0, 0, (uint)ArraySize(fprice)))
   {
      Print("Error writing to input buffer (price)");
      return(prev_calculated);
   }
   uint work_offset[1] = {0};
   uint work_size[1]   = {(uint)N};
   
   bool ok = true;
   ok = ok && openCL.SetArgumentBuffer(0, 0, 0);  // Arg0: price buffer
   ok = ok && openCL.SetArgumentBuffer(0, 1, 1);  // Arg1: MA buffer
   ok = ok && openCL.SetArgumentBuffer(0, 2, 2);  // Arg2: Upper buffer
   ok = ok && openCL.SetArgumentBuffer(0, 3, 3);  // Arg3: Lower buffer
   ok = ok && openCL.SetArgumentBuffer(0, 4, 4);  // Arg4: StdDev buffer
   ok = ok && openCL.SetArgument(0, 5, N);          // Arg5: количество элементов для расчёта
   ok = ok && openCL.SetArgument(0, 6, ExtBandsPeriod); // Arg6: period
   ok = ok && openCL.SetArgument(0, 7, (float)ExtBandsDeviations); // Arg7: deviations
   if(!ok)
   {
      Print("Error setting kernel arguments");
      return(prev_calculated);
   }
   
   if(!openCL.Execute(0, 1, work_offset, work_size))
   {
      Print("Error executing kernel");
      return(prev_calculated);
   }
   
   vector<float> fma;
   vector<float> fupper;
   vector<float> flower;
   vector<float> fstddev;
   
   if(!openCL.BufferToVector(1, fma, (ulong)N))
   {
      Print("Error reading MA buffer");
      return(prev_calculated);
   }
   if(!openCL.BufferToVector(2, fupper, (ulong)N))
   {
      Print("Error reading Upper buffer");
      return(prev_calculated);
   }
   if(!openCL.BufferToVector(3, flower, (ulong)N))
   {
      Print("Error reading Lower buffer");
      return(prev_calculated);
   }
   if(!openCL.BufferToVector(4, fstddev, (ulong)N))
   {
      Print("Error reading StdDev buffer");
      return(prev_calculated);
   }
   
   // Записываем результаты в индикаторные буферы, начиная с start_index
   for(int i = 0; i < N && !IsStopped(); i++)
   {
      int idx = start_index + i;
      ExtMLBuffer[idx]     = (double)fma[i];
      ExtTLBuffer[idx]     = (double)fupper[i];
      ExtBLBuffer[idx]     = (double)flower[i];
      ExtStdDevBuffer[idx] = (double)fstddev[i];
   }
     
   return(rates_total);
}
// bb_kernel.cl
__kernel void bollinger(__global const float* price,
                        __global float* ma,
                        __global float* upper,
                        __global float* lower,
                        __global float* stddev,
                        const int rates_total,
                        const int period,
                        const float deviations)
{
    int i = get_global_id(0);
    if(i < period - 1 || i >= rates_total) {
        if(i < rates_total) {
            ma[i] = 0.0f;
            upper[i] = 0.0f;
            lower[i] = 0.0f;
            stddev[i] = 0.0f;
        }
        return;
    }
    float sum = 0.0f;
    for(int j = 0; j < period; j++){
        sum += price[i - j];
    }
    float avg = sum / period;
    float sum_sq = 0.0f;
    for(int j = 0; j < period; j++){
        float diff = price[i - j] - avg;
        sum_sq += diff * diff;
    }
    float sigma = sqrt(sum_sq / period);
    ma[i]     = avg;
    stddev[i] = sigma;
    upper[i]  = avg + deviations * sigma;
    lower[i]  = avg - deviations * sigma;
}
 
вот эту ошибку 
Print("Error writing to input buffer (price)");