My approach. The core is the engine. - page 126

 
Nikolai Semko:
If it is MT4, then yes.
MT5, as I understand it, fully supports multi-core and multi-threading, unlike MT4.

It seems that to take the load off you have to use OpenCL. But MT4 doesn't have it. Or you can just put up with it.

Another variant is to allow the user to adjust the speed of animation redrawing. In this case, it will be able to reduce the load on the processor when it is necessary and increase it back if it wants.

 
Реter Konow:

It looks like you need to use OpenCL to take the load off. But MT4 doesn't have it. Or just put up with it.

Another option is to allow the user to adjust the speed of animation redrawing. In this case, he will be able to reduce the load on the processor when needed, and increase it back if he wants.

I have already switched to MT5.
It is interesting to test the work of two EAs in MT5 that are installed on different windows but work with resources of only one window. After all, each EA has its own thread and, as you know, you cannot put more than one EA in one window.
 
Nikolai Semko:
It's interesting to test in MT5 the work of two EAs that are installed on different windows but work with resources of one window only. Because each EA has its own thread and, as you know, you cannot put more than one Expert Advisor in one window.

In MT4, each EA has its own thread as well. If I'm not mistaken...

The thread is different, but the processor is the same for all...

I think that is the reason of creating a chart.

 

There's another nuance.

If the animation is cyclic (like a gif), you don't need to reinitialise the pixel array all the time. You can go through one cycle of drawing the animation and store each frame in a resource. Next, just toggle the image. Partly, I have implemented this and thanks to this, achieved multiple animation speeds. (In the beginning, the animation speed was terrible, because each time I redrew the original image, and then drew a new image on it).

 
Реter Konow:

In MT4, each EA has its own thread as well. If I'm not mistaken...

The thread is different, but the processor is the same for all...

I think that's why they have created a graphical map.

Just to appreciate the difference between MT4 and MT5, run this code on both platforms (the code works there and there) and you'll see that in MT4 it runs much slower:

#define protected public
#include <Canvas\Canvas.mqh>
#undef protected
#property script_show_inputs 
input uint N=8; // количество центов гравитации
void OnStart()
  {
   ChartSetInteger(0,CHART_FOREGROUND,true);
   CCanvas C;
   int Width=(ushort)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);                               // get Window width
   int Height=(ushort)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);                             // get Window height 
   if(!C.CreateBitmapLabel(0,0,"CanvasExamlple",0,0,Width,Height,COLOR_FORMAT_XRGB_NOALPHA)) // create canvas with the size of the current window
      Print("Error creating canvas: ",GetLastError());
   uint i=0,j=100000;
   int size=Width*Height;
   uchar h[25600];
   ArrayInitialize(h,0);
   uint w;
   for(w=0;w<25600;w++) h[w]=uchar(128+128*sin(double(w)/256)); //create an array to speed up the work
   double SQRT[];
   uint ss=Width*Width+Height*Height;
   Print(ss);
   ArrayResize(SQRT,ss);
   for(w=0;w<ss;w++) SQRT[(int)w]=sqrt(w); //create an array to speed up the work 
   int k[]; ArrayResize(k,N*2);
   for(w=0;w<N*2;w++) k[w]=20+rand()%200;
   double XP[],YP[],D[],D1[];
   ArrayResize(XP,N);
   ArrayResize(YP,N);
   ArrayResize(D,N);
   ArrayInitialize(XP,0);
   ArrayInitialize(YP,0);
   ulong t=0,sum=0, f=0;
   C.FontSet("Verdana",50,FW_MEDIUM);
   while(!IsStopped())
     {
      int pos=int(i%size);
      if(pos==0)
        {
         //Sleep(20); //For those who have a too powerful computer.
         if (i>0) {t=GetMicrosecondCount()-t; sum+=t; f++; 
         C.TextOut(Width/2,Height/2,"Время формирования кадра = "+IntegerToString(sum/f)+" мкс",clrBlueViolet,TA_CENTER|TA_VCENTER);}
         C.Update();
         t=GetMicrosecondCount();
         for(w=0;w<N;w++)
           {
            XP[w]= Width/2-(sin((double)j/k[2*w])*(double)Width/2);
            YP[w]= Height/2-(cos((double)j/k[2*w+1])*(double)Height/2);
           }
         j++;
        }
      int X=pos%Width;
      int Y=int(pos/Width);
      
     // for(int w=0;w<N;w++) D1[w]=SQRT[int((XP[w]-X)*(XP[w]-X)+(YP[w]-Y)*(YP[w]-Y))];
      for(w=0;w<N;w++) D[w]=    sqrt((XP[w]-X)*(XP[w]-X)+(YP[w]-Y)*(YP[w]-Y));
      double S1=0,S2;
      for(w=0;w<N/2;w++) S1+=D[w];
      S2=S1;
      for(w=N/2;w<N;w++) S2+=D[w];
      double d=S1/S2;
      
      //double d= (D[0]+D[1]+D[2]+D[3])/(D[0]+D[1]+D[2]+D[3]+D[4]+D[5]+D[6]+D[7]);
       //d= (D[0]+D[1])/(D[0]+D[1]+D[2]+D[3]);
      C.m_pixels[pos]=XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]);// works a little faster, but requires transferring the array m_pixels from protected to public in Canvas.mqh
      //C.PixelSet(X,Y,XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]));
      i++;
     }
   C.Destroy();
  }
//+------------------------------------------------------------------+
 
Nikolai Semko:

Just to appreciate the difference between MT4 and MT5, run this code on both platforms (the code works there and there) and you'll see that it's an order of magnitude slower in MT4:

Yes, put it there and there. The difference is about a factor of 10. Exactly because in MT5 the arrays are initialised 10 times or more faster. I've checked.

However, even on MT4 everything should be much faster. After all, you're just redrawing the image. It's different if you're processing it repeatedly in an array.

I don't know why it's so slow on MT4.

 

However, perhaps it's because you're reinitialising EVERY pixel in the entire kanvas space the size of the graph.

In my animation, only individual areas are drawn, and the main part of the image is taken entirely from the resource. You don't have the main part, and the image is created entirely. Therefore, it slows down.

It's the size of the drawing.

 
Реter Konow:

However, perhaps it's because you're reinitialising EVERY pixel in the entire canvas space the size of the graph.

In my animation, only individual areas are drawn, and the main part of the image is taken entirely from the resource. You don't have the main part, and the image is created entirely. Therefore, it slows down.

It's the size of the drawing.

What a difference. This is a deliberately extreme example that clearly demonstrates the advantages of mt5 in terms of kanvas speed. And this issue is archival in your brainchild. That's why I've been saying for a long time - go to MQL5.
The fact remains. Image framing on mt5 is 10 times faster than on mt4. And that's a very compelling argument.
 
Nikolai Semko:
What a difference. This is a deliberately extreme example that clearly demonstrates the advantages of mt5 in the speed of the kanvas. And this issue is archival in your brainchild. That's why I've been saying for a long time - go to MQL5.
The fact remains. Imaging on MT5 is 10 times faster than on MT4. And that's a very valid argument.

The downsides of MT4, are what is needed in development. You don't have to run away from them. They force you to think and improve your solutions.

On MT5, you don't have to try very hard either. Everything works fast enough as it is. Therefore, migration to MT5 is planned for the final stage.

 
Реter Konow:

Finally, the dynamic table is done. I have to say that it was not easy. It turns out that there are a lot of nuances.

Also, this table is "conditionally" dynamic. That is, the maximum number of rows is predetermined. It was not possible to make "absolutely" dynamic yet.

This table has 20 possible rows. So, it can display 20 open positions. We could make more, but it's just a demonstration for now.

Click to view.

Here are the connection files (put in the inclusion), the engine(in the indicators folder), and the test.EA (in the experts folder):

Peter, sorry but your work is not accepted as what you have sent is a rare hack job. I'm sorry but it seems that I'm the only one who ran what you sent and besides me no one will examine it.

So, in order, the assignment was as follows:

Forum on trading, automated trading systems and testing trading strategies

My approach. Core - Engine.

Vasiliy Sokolov, 2018.12.26 13:29

Peter, here's the assignment. Make a panel showing current order openings in MT4. No need to make a full copy of the system panel, display the most simple table with basic properties of open orders: opening price, direction, profit. The rest is up to you. The main thing is that when an order is closed, its indication in your table would also disappear. And vice versa, it would appear in this table when a new order is opened.

What I see instead:

Firstly, trades can only be opened in your panel by clicking the buy/sell button. If a position is opened through the standard window, the trade does not appear.

Secondly, some orders are displayed with empty values. They are present in the table, but the rows are empty.

Third, (this is really creepy), if we close an order through the standard dialog, it doesn't disappear in the table. But the saddest thing is that when you reload the panel, the closed orders are again displayed as supposedly open! What is this? Why are you storing irrelevant information somewhere and then trying to load it!?

Fourth, what the hell are 20 orders? I don't have a word about this restriction in my assignment! It was done on purpose, to test your engine to work with dynamic and previously unknown environment. The job was not randomly chosen, you have changed my requirements, so that it would hide all the "sharp corners" of your engine. But the task was given in order to show these angles.

Fifth, you don't need to do it if you set a stop loss or take profit. Leave these fields blank.

And yes, the button to close the position (cross) in your panel doesn't work either.

In short, Peter. I'm sorry, but what you've sent me is a total hack job. Please fix it as per spec.

I will clarify the task once again, so there won't be any questions:

  1. The table is dynamic and shows the same orders as on the Trade tab. If there are no orders on the tab, your table does not show them either.
  2. The number of the displayed orders in your table should be anything. There are no limitations from above.
  3. Opening an order via the standard dialog window should cause the order to appear in your table. The closing of the order by standard means should result in the disappearance of the order in your table.
  4. A non-consistent state is not acceptable! If your table shows one thing and the Trade tab another, this is an error.

So far, a fat no-go. Waiting for your refinements. And no 3D renderings until you figure it out!
Reason: