Machine learning in trading: theory, models, practice and algo-trading - page 2333

 


....

 

Easy, good article about genetic programming possibilities

https://blog.ephorie.de/symbolic-regression-genetic-programming-or-if-kepler-had-r

 

I found (for me) a cool way to test my mql scripts on python, as well as significantly speed up some functions in it, using dll.

Here is the original function in mql5, which I want to put to python. It simply searches for minima and maxima of price using its smoothed pattern.

void get_loc_extremum(double &x[],double &x2[],double &loc_max[],double &loc_min[],bool real_price)
  {
   int N = ArraySize(x);
   for(int i=1; i<N-1; i++)
     {
      if(x[i-1]<x[i]&& x[i]>x[i+1])
        {
         ArrayResize(loc_max,ArraySize(loc_max)+1);
         if(real_price)
            loc_max[ArraySize(loc_max)-1]=x2[i];
         else
            loc_max[ArraySize(loc_max)-1]=x[i];
        }

      if(x[i-1]>x[i]&& x[i]<x[i+1])
        {

         ArrayResize(loc_min,ArraySize(loc_min)+1);
         if(real_price)
            loc_min[ArraySize(loc_min)-1]=x2[i];
         else
            loc_min[ArraySize(loc_min)-1]=x[i];
        }

     }

It is done in several steps

1. We compile our dll in Visualstudio or in codeblock. It is very simple, in file .cpp we write our function, in file .h we declare it. An example that worked for me in the appendix to this post. In the folder codeblox project file, main .cpp, main . h files, in the folder \bin\Debug file my_lib.dll. In short, here is the header of the function in c++:

void DLL_EXPORT GetLocalMaxMin(double* x_sm[],double* x_rl[], double* loc_max[], double* loc_min[], int N, bool real_price)
{
...
}

2 In python do the following:

from ctypes import *

my_dll = cdll.LoadLibrary("my_dll/my_lib.dll") 					#загружаем  свою DLL
my_dll.GetLocalMaxMin.argtypes = [POINTER(c_double), 
        POINTER(c_double), POINTER(c_double), POINTER(c_double), c_int, c_bool] #определяем  типы входных аргументов функции через атрибуты ctypes
my_dll.GetLocalMaxMin.restype = None                                            #определяем  типы выходных данных 

...
#  y - список цен
#  y_sm - список сглаженных цен
#  len(y)=len(y_sm) - длина списков одинаковая

x_sm = (c_double * len(y))(*y_sm)    				  #создаем  указатель на массив x_sm размером len(y_sm) предаем туда указатель на массив y_sm
x_rl = (c_double * len(y))(*y)       			       	  #создаем  указатель на массив x_rl размером len(y) предаем туда указатель на массив y
loc_max = (c_double * len(y))()      				  #создаем  указатель на массив loc_max размером len(y) заполный 0.0 
loc_min = (c_double * len(y))()     				  #создаем  указатель на массив loc_min размером len(y) заполный 0.0 
my_dll.GetLocalMaxMin(x_sm, x_rl, loc_max, loc_min, len(y), True) #вызываем  функцию и передаем туда все что насоздавали

print(list(loc_max),list(loc_min)) #смотрим  что получилось

This is not the final truth, there are additions, or other options, write.

Files:
my_lib.zip  36 kb
 

I found (for me) a cool way to test my mql scripts on python, as well as significantly speed up some functions in it, using dll.

Here is the original function in mql5, which I want to put to python. It simply searches for minima and maxima of price using its smoothed pattern.

It is done in several steps

1. We compile our dll in Visualstudio or in codeblock. It is very simple, in file .cpp we write our function, in file .h we declare it. An example that worked for me in the appendix to this post. In the folder codeblox project file, main .cpp, main . h files, in the folder \bin\Debug file my_lib.dll. In short, here is the header of the function in c++:

2 In python do the following:

This is not the final truth, any additions, or other options, write.

What do you want to achieve?
If speed, don't use
ArrayResize(loc_max,ArraySize(loc_max)+1);

inside the loop, and once before calling the function, set the size you want, like you did in C++ and python, or reserve it with the 3rd parameter

ArrayResize(loc_max,ArraySize(loc_max)+1, max_size);

Now every call to ArrayResize, creates a new block in memory, copies the old one into it and deletes the old one. This is very, very slow.

И

ArraySize(loc_max)

you can store it in a variable instead of doing it every time.


Try it, maybe you won't need to spread a simple function across 3 different programming languages. Developers say that MQL is comparable to C++ in speed and even faster in some things.

Why do you need Python if you can call DLL directly from MQL?

Or do you have some other goal?
 
elibrarius:
And what do you want to achieve?
If speed, don't use

inside the loop, and set the desired size once before calling the function, as you did in C++ and Python, or reserve it with the 3rd parameter

Now every call to ArrayResize, creates a new block in memory, copies the old one into it and deletes the old one. This is very, very slow.

И

you can store it in a variable instead of doing it every time.


Try it, maybe you won't need to spread a simple function across 3 different programming languages. Developers say that MQL is comparable to C++ in speed and even faster in some things.

Why do you need Python if you can call a DLL directly from MQL?

Or do you have some other goal?

The extremum search function in the message is provided just as an example to show the principle.

And MQL has a good tester that, if you don't cheat yourself, will give you a good estimate of your findings.

I'm comfortable working with Python, but I'm just learning and cannot write any function in mql5 with cycles in Python using the vector calculations libs. And writing code without them is a waste of time because python is very slow. Some functions can be called on every bar and that makes it very difficult to find. I've used algib everywhere I could because they have solutions for both python and mql5. But when it comes to the flight of my fantasy here there are problems.

Code for mql5 can easily convert to C++ and compiled into a dll. As a result I use the same function in the tester and in python scripts.

 

The extremum search function in the message is given merely as an example to show the principle on it.

The purpose is formed by the fact that in Python it is convenient to look for the dependences of features and target and to select models, while MQL has a good tester with which, if you don't cheat yourself, you can get a clear estimate of your findings.


So, you have found dependencies in Python, picked and trained a model and tested it. And how do you test it in a tester? Python is not friendly with the tester or with MKL5.

 
If for the TC the average time to hold a position is 10 minutes. And the current position hangs for 10 hours, then its result is a gambit (completely non-systemic)?
 
fxsaber:
If the average position holding time for the TS is 10 minutes. And the current position hangs for 10 hours, then its result is a random (completely non-systemic)?

It depends on how the logic/rules of the TS are written. The "maybe" is a probabilistic result that is not determined by the logic of TC. If all 10 hours of logic worked definitely, then it is just a rare case.

 
Valeriy Yastremskiy:

If all 10 hours of logic worked definitely, it's just a rare case.

The fact that the logic worked does not make the result systematic.

 
fxsaber:

Just because logic worked does not make the result systematic.

The question does not specify to what to apply the luck and systematicity. If to TC, it all depends on TC, if to external conditions, then rare cases are not systemic inherently. And may be exceptions to the rules. Eurodollar 14 from May to March '15. Not a systemic case.

Reason: