Questions from Beginners MQL5 MT5 MetaTrader 5 - page 774

 
0Aleksandr0:

What is it? I'm not a good judge of MQL4, if you tell me what I need to get, I will be able to write it in MQL5.
I think it has something to do with history profit/loss calculation.


That's the thing, I don't understand it myself - the code was written to my order, pulled out of a class. I'm also inclined to think that this code is for balance calculation. But, according to the idea, the change of balance with the opening-closing of a new order should be reset in the array, but I don't see it...

 
Aleksey Vyazmikin:

Please help me rewrite code on MT5 - I don't know anything about orders :(

#include <MT4Orders.mqh>
 
fxsaber:

Thank you, the EA with this class compiled - I don't know if it will conflict...


Now getting an error when running the test

2017.08.23 11:22:59.929 Core 3 2016.06.01 00:00:00 DLL loading is not allowed

2017.08.23 11:22:59.929 Core 3 global initialization failed

2017.08.23 11:22:59.929 Core 3 global initialization critical error

2017.08.23 11:22:59.929 Core 3 tester stopped because expert initialization failed


Library call is used - in MT4 everything is correct.

#import "Kernel32.dll"
bool CopyFileW(string lpExistingFileName,string lpNewFileName,bool bFailIfExists);
#import 

What can be the reason?

 
Aleksey Vyazmikin:

Thank you, the EA compiled with this class - but I don't know if it will conflict...

It won't.

Now getting an error when running the test

2017.08.23 11:22:59.929 Core 3 2016.06.01 00:00:00 DLL loading is not allowed

2017.08.23 11:22:59.929 Core 3 global initialization failed

2017.08.23 11:22:59.929 Core 3 global initialization critical error

2017.08.23 11:22:59.929 Core 3 tester stopped because expert initialization failed


Library call is used - in MT4 everything is correct.

What could be the reason?

In Terminal allow the use of DLL.

 
fxsaber:

It will not.

In the Terminal, allow the DLL to be used.


You won't believe it - I did, but it had no effect - apparently the cache is there, which is cleared after some time - it's working now. Thank you.

 

How can agents be taught to write to the same file? Right now everyone creates their own file in their own folder, which is not good.

 
Aleksey Vyazmikin:

How can agents be taught to write to the same file? Right now everyone creates their own file in their own folder, which is not good.

Alexey, open the documentation at least once... It is accurately described there which flag point to the general folder, which opens the general access to the file. Whether it is easier to wait for the answer, than to read documentation?

Документация по MQL5: Файловые операции
Документация по MQL5: Файловые операции
  • www.mql5.com
Файловые операции - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Aleksey Vyazmikin:

How can agents be taught to write to the same file? Right now, everyone creates their own file in their own folder, which is not good.


First (Step 1) you need to overcome:

... in its own folder, ...


This is done with the FILE_COMMON flag - all agents will now write to a common folder (but still each agent will write to its own file).


Example EA:

//+------------------------------------------------------------------+
//|                                           Agents FILE_COMMON.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//---
input int s=0;
//---
string InpFileName="";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initialize the generator of random numbers 
   MathSrand(GetTickCount());
   InpFileName=IntegerToString(MathRand())+".txt";
//--- open the file 
   ResetLastError();
   int file_handle=FileOpen(InpFileName,FILE_WRITE|FILE_TXT|FILE_COMMON);
   if(file_handle!=INVALID_HANDLE)
     {
      //--- the string is formed, write it to the file 
      FileWriteString(file_handle,InpFileName);
      //--- close the file 
      FileClose(file_handle);
      PrintFormat("Data is written, %s file is closed",InpFileName);
      PrintFormat("Common path for all of the terminals installed on a computer: %s",TerminalInfoString(TERMINAL_COMMONDATA_PATH));
     }
   else
     {
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+


To quickly open this common folder, do the following: In the MetaEditor, select "Open Common Data Folder" in the File menu.


Now run this EA for optimization and watch as new files are created in the Common Data Folder as tests are run.

Files:
 
Vladimir Karputov:

First (Step 1) needs to be defeated:


This is done with the FILE_COMMON flag - all agents will now write to a common folder (but still each agent will write to its own file).


Example EA:


To quickly open this shared folder, do the following: in the MetaEditor code editor, select "Open Common Data Folder" from the File menu.


Now run this EA for optimization and watch how new files will be created in the Common Data Folder as the tests are run.


I don't want to put it into Common, as the terminal runs in its own directory, and there will be many files, as you say anyway, which doesn't solve the problem.

 
Aleksey Vyazmikin:

I don't want to go into Common, as the terminal runs in its own directory, and there will still be a lot of files, as you say, which doesn't solve the problem.


It says: " ... Step 1 ..."

On step 2 - now think for yourself, namely, how multiple threads WITHOUT CONFLICT can write to ONE file.