Выпуск Opencl в индикаторе.

 

Я пробовал индикатор SMA с OpenCL.

Но я не получаю значения в буфере вывода.

Вот мой код:

//+------------------------------------------------------------------+
//|                                                 TestMAOPENCL.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
//--- input parameters
input int            InpMAPeriod=13;         // Period
input int            InpMAShift=0;           // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA;  // Method
//--- indicator buffers
double               ExtLineBuffer[];

#resource "ma.cl" as string clSrc
#include <OpenCL/OpenCL.mqh>
COpenCL opencl;

void OnDeinit(const int r)
  {
   opencl.Shutdown();
   return;
  }
int OnInit()
  {

   if(!opencl.Initialize(clSrc))
     {
      return INVALID_HANDLE;
     }
   else
     {
      opencl.SetKernelsCount(4);
      opencl.KernelCreate(0,"CalculateSimpleMA");
      opencl.SetBuffersCount(2);
     
     }
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);
//---- line shifts when drawing
   PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
//--- name for DataWindow
   string short_name="unknown ma";
   switch(InpMAMethod)
     {
      case MODE_EMA :
         short_name="EMA";
         break;
      case MODE_LWMA :
         short_name="LWMA";
         break;
      case MODE_SMA :
         short_name="SMA";
         break;
      case MODE_SMMA :
         short_name="SMMA";
         break;
     }
   IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")");
//---- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//---- initialization done
   return INIT_SUCCEEDED;
  }
//+------------------------------------------------------------------+
//|  Moving Average                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//--- check for bars count
   if(rates_total<InpMAPeriod-1+begin)
      return(0);// not enough bars for calculation
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
      ArrayInitialize(ExtLineBuffer,0);
//--- sets first bar from what index will be draw
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1+begin);
   int limit =0;
   uint offset[1]= {0};
//--- array sets limits up to which the calculation will be performed
   uint work[1];
   
   if(prev_calculated==0)
     {
      limit=InpMAPeriod+begin;
     }
   else
      limit = prev_calculated -1;
   work[0] = limit;
   double arr[];
   ArraySetAsSeries(arr,true);
   ArrayResize(arr,rates_total);
   switch(InpMAMethod)
     {

      case MODE_SMA:
         Print("SMA");
         Print(opencl.SetArgument(0,0,InpMAPeriod));
         Print(opencl.SetArgument(0,1,rates_total),"  ",GetLastError());
         Print(opencl.SetArgument(0,2,prev_calculated),"  ",GetLastError());
         Print(opencl.SetArgument(0,3,begin),"  ",GetLastError());
         //Print(opencl.BufferCreate(0,(rates_total-1)*sizeof(float),CL_MEM_READ_WRITE),"  ",GetLastError());
         Print(opencl.BufferFromArray(0,price,0,rates_total,CL_MEM_READ_WRITE),"  ",GetLastError());
         //Print(opencl.BufferFromArray(0,ExtLineBuffer,0,rates_total,CL_MEM_READ_WRITE));
         Print(opencl.SetArgumentBuffer(0,4,0),"  ",GetLastError());
         Print(opencl.BufferCreate(1,(rates_total)*sizeof(double),CL_MEM_READ_WRITE),"  ",GetLastError());
         Print(opencl.SetArgumentBuffer(0,5,1),"  ",GetLastError());
         Print(opencl.Execute(0,1,offset,work),"  ",GetLastError());
         
         Print(opencl.BufferRead(1,arr,0,0,rates_total),"  ",GetLastError());
         Print(arr[rates_total-1], "  ",arr[0], "  ",GetLastError());
         break;
     }
//--- calculation
//switch(InpMAMethod)
//  {
//   case MODE_EMA:  CalculateEMA(rates_total,prev_calculated,begin,price);        break;
//   case MODE_LWMA: CalculateLWMA(rates_total,prev_calculated,begin,price);       break;
//   case MODE_SMMA: CalculateSmoothedMA(rates_total,prev_calculated,begin,price); break;
//   case MODE_SMA:  CalculateSimpleMA(rates_total,prev_calculated,begin,price);   break;
//  }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Вот журнал ответов:

TestMAOPENCL (EURUSD,M1)        OpenCL: CPU device 'Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz' selected
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0
TestMAOPENCL (EURUSD,M1)        SMA
TestMAOPENCL (EURUSD,M1)        true
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        true  0
TestMAOPENCL (EURUSD,M1)        0.0  0.0  0

Дайте мне знать, что я могу сделать.

Файлы:
ma.zip  1 kb