Here's what you can do with OpenCL directly in MetaTrader 5 without any DLLs - page 11

 
fxsaber:

Apparently, the algotrader's programming objective is what you call something like this- all the trading logic in a few lines.

In that example, in order for the Signal to show a positive trend, the entire algotrading goal is actually contained in just one line

which has nothing to do with the Order-logic, but is decisive for the results of the TS.


"Exactly the same line" is in any competent Expert Advisor. And it is the one that is written by the algotraders.


And what does it show in real trading? You are not in a good mood. Surely the problem (if there is one) lies in some unaccounted for trifle related to the real work (some jumping pings, packet loss, or voltage fluctuations in the network are causing the slave some difficulties. This is my topic too, by the way, I'm building a robot slowly.
 
Alexey Oreshkin:

Why?
I've never done gui for robots at all, I don't see the point in wasting time on it.

I also don't see how you can analyse statarbitrage strategies visually )). All the analysis is calculation data only, but there are enough logs in the debugging phase for that. For example, such data is used in the debugging phase of the strategy, but its visualisation will not tell us anything.

Files:
 
fxsaber:

Apparently, the algotrader's programming objective is what you call something like this- all the trading logic in a few lines.

In that example, in order for the Signal to show a positive trend, the entire algotrading goal is actually contained in just one line

which has nothing to do with the Order-logic, but is decisive for the results of the TS.


"Exactly the same line" is in any competent Expert Advisor. And it is the one that is written by the algotraders.


Ticks are suitable only for scalping. They cannot even be trusted with a short-term strategy of a closed algorithm, because half of the positions will be stuck in the flat, because there is no technical analysis for the correct entry. You enter at random, and the result is corresponding. Ticks are good for strategy tester, as wise people told me, plus they make my work with equities more effective. But what kind of entries by ticks may be - just for scalping, like entry-exit and profit of 5-10 quid. It is pure iteration, without any information. Once again, you know their past state but you will never know their future state. That is the nature of Forex. Instead of this visualized nonsense attach a couple of indicators to your Expert Advisor and they will analyze the chart and identify the vector of further price movement with the probability more than 0,5.)
 
Comments not relevant to this topic have been moved to "The GUI Concept".
 

Once again I come to the topic to find outwhat can be done with OpenCL directly in MetaTrader 5 terminal without any DLL

I have to read bullshit hullabaloo... Please, if you have nothing to write on the subject, don't write at all...

 

Very strange.

It looks like a memory leak exactly in the terminal.

I wrote a script to demonstrate it. I want to make sure I'm not missing anything and it really is a bug.

//+------------------------------------------------------------------+
//|                                            OpenCL_MemoryLeak.mq5 |
//|                                           Copyright 2017, Progid |
//|                             http://www.mql5.com/en/users/progid/ |
//|                                                       18.04.2017 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Progid"
#property link      "http://www.mql5.com/en/users/progid/"
#property version   "1.00"

//+------------------------------------------------------------------+
//| define
//+------------------------------------------------------------------+
#ifndef  _Error_
 #define _Error_(info)  { Print("Error: ",info," line: "+(string)__LINE__+" file: "+__FILE__+" function: "+__FUNCTION__+"; GetLastError: "+(string)GetLastError()); }
#endif

#ifndef  _ErrorDefault_
 #define _ErrorDefault_(info,r) { _Error_(info) r; }
#endif

#define _RAM_Print_ Print("RAM used: Program(",MQLInfoInteger(MQL_MEMORY_USED)," MB) Terminal(",TerminalInfoInteger(TERMINAL_MEMORY_USED)," MB)");

//+------------------------------------------------------------------+
//| resource
//+------------------------------------------------------------------+
//#resource "Gpu_Code_0.cl" as string _CL_GpuCode_0

string _CL_GpuCode_0 = ""
"__kernel void GPU_Test (global int * buf_0,"
"                        global int * buf_1,"
"                        global int * buf_r,"
"                        "
"                        local  int * l_buf_1)"
"{"
"   const int id   = get_global_id(0);"
"   "
"   buf_r[id] = 0;"
"   "
"   l_buf_1[id] = buf_0[id] * buf_1[id];"
"   "
"   buf_r[id] = l_buf_1[id];"
"}";


//+------------------------------------------------------------------+
//| include
//+------------------------------------------------------------------+
#include <OpenCL\OpenCL.mqh>

//+------------------------------------------------------------------+
//| global var
//+------------------------------------------------------------------+
COpenCL _OpenCL;

const int _Size = 5000;

int _Buf_0[];
int _Buf_1[];
int _Buf_r[];
   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
{
   if (ArrayResize(_Buf_0, _Size) != _Size) _ErrorDefault_("", return)
   if (ArrayResize(_Buf_1, _Size) != _Size) _ErrorDefault_("", return)
   if (ArrayResize(_Buf_r, _Size) != _Size) _ErrorDefault_("", return)
   
   for (int i=0; i<_Size; ++i)
   {
      _Buf_0[i] = i;
      _Buf_1[i] = i;
   }
   
   if (!GPU_Init()) _ErrorDefault_("", return)
   
   while(!_StopFlag)
   {
      if (!GPU_Test()) _ErrorDefault_("", break)
   }
      
   _OpenCL.Shutdown();
   
   Print("Completed!");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool GPU_Init()
{
#define _gpu_error_ _OpenCL.Shutdown(); return false
   
//---init
   if (!_OpenCL.Initialize(_CL_GpuCode_0, true)) _ErrorDefault_("", _gpu_error_)
   
   
//---kernels
   if (!_OpenCL.SetKernelsCount(1)) _ErrorDefault_("", _gpu_error_)

   if (!_OpenCL.KernelCreate(0, "GPU_Test")) _ErrorDefault_("", _gpu_error_)


//---buffers
   if (!_OpenCL.SetBuffersCount(3)) _ErrorDefault_("", _gpu_error_)

   //buf_0
   if (!_OpenCL.BufferCreate(0, _Size*sizeof(int), CL_MEM_READ_ONLY)) _ErrorDefault_("", _gpu_error_)
   //buf_1
   if (!_OpenCL.BufferCreate(1, _Size*sizeof(int), CL_MEM_READ_ONLY)) _ErrorDefault_("", _gpu_error_)
   //buf_r
   if (!_OpenCL.BufferCreate(2, _Size*sizeof(int), CL_MEM_WRITE_ONLY)) _ErrorDefault_("", _gpu_error_)
   
   
//---args
   if (!_OpenCL.SetArgumentBuffer(0, 0, 0)) _ErrorDefault_("", _gpu_error_)
   if (!_OpenCL.SetArgumentBuffer(0, 1, 1)) _ErrorDefault_("", _gpu_error_)
   if (!_OpenCL.SetArgumentBuffer(0, 2, 2)) _ErrorDefault_("", _gpu_error_)
   
   if (!_OpenCL.SetArgumentLocalMemory(0, 3, _Size*sizeof(int))) _ErrorDefault_("", _gpu_error_)


//---write to GPU
   if (!_OpenCL.BufferWrite(0, _Buf_0, 0, 0, _Size)) _ErrorDefault_("", return false)
   if (!_OpenCL.BufferWrite(1, _Buf_1, 0, 0, _Size)) _ErrorDefault_("", return false)
   
   
//---
#undef _gpu_error_ 

   return true;   
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+   
bool GPU_Test()
{ 
   for (int c=0; c<100; ++c)
   {   
//---Execute     
      uint GlobalWorkOffset[1] = {0};
      uint GlobalWorkSize[1]   = {0}; GlobalWorkSize[0] = _Size;
      
      if(!_OpenCL.Execute(0, 1, GlobalWorkOffset, GlobalWorkSize)) _ErrorDefault_("", return false)
      if(!_OpenCL.BufferRead(2, _Buf_r, 0, 0, _Size)) _ErrorDefault_("", return false)
   }

//---RAM
   int RAM_Used = TerminalInfoInteger(TERMINAL_MEMORY_USED);
   
   if (RAM_Used > 3024) _ErrorDefault_("RAM used: "+(string)RAM_Used+" > 3024 MB", return false)
   
   static ulong LastMSC = 0;
    
   if (GetMicrosecondCount() - LastMSC >= 3000000)
   { 
      _RAM_Print_
      
      LastMSC = GetMicrosecondCount();
   }
   
//---
   return true;
}


The memory is leaking, quite noticeably. A hundred MB per minute.

The leakage is excluded in the program sinceMQLInfoInteger(MQL_MEMORY_USED) excludes it.

Is this really a bug and should I go to Service Desk?

The script prints in the log the amount of consumed RAM, both by the program itself and by the terminal.

 
Marat Sultanov:

Very strange.

It looks like a memory leak exactly in the terminal.

I wrote a script to demonstrate it. I want to make sure I'm not missing anything and it really is a bug.


The memory is leaking, quite noticeably. A hundred MB per minute.

The leakage is excluded in the program sinceMQLInfoInteger(MQL_MEMORY_USED) excludes it.

Is it really a bug and is it worth going to servicedesk?


Please post the results of studies on this subject here later so that we know where the dog is buried ))
 

Doesn't anyone use OpenCL in practical tasks? :)

Konstantin:

Please post the result of your research on the subject here, so that you know where the dog is buried ))

OK. Sorry, are you like me, are you stuck because of this, or you just want to know for general development?

 
Marat Sultanov:

Doesn't anyone use OpenCL in practical tasks? :)


I do, but I haven't gotten around to your example
 
Igor Volodin:

I do, but I haven't gotten around to your example

Great. The script prints in the log the amount of RAM consumed, both by the program itself and by the terminal. If you run the script, you will immediately see in the log how many MB of RAM the terminal is consuming.

Do you use intensive calculations in your programs?