Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1011

 
Sergey Likho:

What is the best way to write the algorithm?


Task:

One Expert Advisor runs on different charts.

I need to have a separate file with minute by minute information about account, balance, equity, etc.

Now it turns out that all Expert Advisors write all information in one file. As a result, we have a lot of unnecessary entries.

What is the possible original solution, so that only one bot would make records in the file (And, if it was deleted, the other bot would start making records, etc.)

Create a graphical object in OnInit() with the EA's name, or any other object. Perhaps, the EA is already creating an object, you can use it, e.g. "MyEA":ObjectCreate(0,"MyEA",OBJ_...,...))

In OnTick() where writing to the file we need to check the first chart ID with this very label = it means this is the first Expert Advisor installed in the terminal, we are not interested in the rest.

We have to use overshoot:

string ChartGetSymb()
  {
   string symb="";
   long chartID=ChartFirst();
   while(chartID!=-1) 
    {
      if(ObjectGetString(chartID,"MyEA",OBJPROP_NAME)=="MyEA")
       {
        symb=ChartSymbol(chartID);
        break;
       }
      chartID=ChartNext(chartID);
     }
   return(symb);
  }

We get the first chart/symbol with an Expert Advisor installed on it

Then we compare it with the first Expert Advisor before writing it into a file:

if(ChartGetSymb() == Symbol()) {
  записываем в файл, если соответствует символу, иначе не записываем
}


It is not an easy construct, but it is better than writing to the global variable

 
Artyom Trishkin:

Take the standard MA, change the buffer data type, compile and check in the terminal data window (Ctrl+D)

That wouldn't help as it wouldn't show up in the terminal. But I checked it in ZigZag indicator, which has two additional buffers for High and Low, declared as INDICATOR_CALCULATIONS. They are also taken from the program, although they are not displayed in the terminal. Thanks for the tip anyway.
 
Sergey Likho:

ChartID() is written to the terminal's global variables with an error. what is this nonsense?


Try this code:


The result of executing this code

2019.11.29 15:22:07.453 Script 00 EURUSD,H1: removed
2019.11.29 15:22:07.453 00 EURUSD,H1: uninit reason 0
2019.11.29 15:22:07.453 00 EURUSD,H1: GVAR id:131992895281608496 GV_id:131992895281608496
2019.11.29 15:22:07.453 00 EURUSD,H1: initialized
2019.11.29 15:22:07.433 Script Test\00 EURUSD,H1: loaded successfully
 
Vitaly Muzichenko:

Create a graphical object in OnInit() with the name of the EA or any other object, perhaps the EA already creates an object, then you can use it, let's assume "MyEA": ObjectCreate(0,"MyEA",OBJ_...,...))

In OnTick() where writing to the file we need to check the first chart ID with this very label = it means this is the first Expert Advisor installed in the terminal, we are not interested in the rest.

We have to use overshoot:


We get the first chart/symbol with an Expert Advisor installed on it

Then we compare it with the first Expert Advisor before writing it into a file:


It is not an easy construction, but it is better than writing to the global variable

Yes, good idea.

Thank you.


Question, what if EA has been deleted (e.g. due to error), but the object has remained. What to do if the chart is closed completely, we need to somehow re-assign the "main" EA?

 
Sergey Likho:

Yes, that's a good idea.

Thank you.


Question then: What if the EA has been deleted (e.g. due to an error), but the object has remained. What to do if the chart is closed in its entirety, we need to somehow re-assign the "main" Expert Advisor?

There is only one case of an error - if the Expert Advisor was accidentally deleted and the object was left, but in my memory, I do not remember such an error in MT4. In all other cases the chief Expert Advisor will be reassigned.


P.S. Try to check that OnDeInit() will be output on error in Expert Advisor and self-delete from the chart. Probably, you can check it easily by creating a variable and counting ticks and dividing it by 10/0 on the 11th tick.

In OnDeInit() use Print and see the cause of deinitialization, and if it occurs, then by this cause/number delete the object "MyEA" from the chart

t++;
if(t > 10) {
 int e = 10;
 e /= 0;
}

You can write about the result, because I have no time to check it myself

 
Vitaly Muzichenko:

Create a graphical object in OnInit() with the name of the EA or any other object, perhaps the EA already creates an object, then you can use it, let's assume "MyEA": ObjectCreate(0,"MyEA",OBJ_...,...))

In OnTick() where writing to the file we need to check the first chart ID with this very label = it means this is the first Expert Advisor installed in the terminal, we are not interested in the rest.

We have to use overshoot:


We get the first chart/symbol with an Expert Advisor installed on it

Then we compare it with the first Expert Advisor before writing it into a file:


It's not an easy construct, but it's better than writing to a global variable

I think you are mistaken. GVs are not written to disk every time. Otherwise there would be no need to force GV to disk.

void  GlobalVariablesFlush();
And on top of that, going through all the charts in search of EA and object... Vitaly, that's a bummer...
 
Alexey Viktorov:

I think you are mistaken. GVs are not written to disk every time. Otherwise we wouldn't need the function of forced GV writing to disk.

Yes plus to go through all the charts in search of EA and object... Vitaly, that's a bummer...

Yes, they are:GlobalVariableSet("GV",ID);

profiles -> gvariables.dat


 
Vitaly Muzichenko:

Alternatively they are written as:GlobalVariableSet("GV",ID);

profiles -> gvariables.dat


When you create it, maybe, but when you overwrite it before you disable the application that writes there, you have to check. I'm too lazy. Still, purely theoretically, if it were to be written to the disk every time, the above function would be a rattle.

 
Sergey Likho:

You can't do that.

Look for a Windows program that synchronises data in folders. And set it up so that the Expert Advisor is copied to a new terminal automatically.

As I understand it, there are such programs, but they only work with files, but if it is a text document, it does not copy the content and does not replace files, maybe I have not found a normal program. It's too bad the developers didn't consider the option to specify path from where to download Expert Advisor or robot file, I thought I could specify path as it's usually done, but as you pointed out above it's impossible.

 
Seric29:

As I understand it there are such programs, but they only work with files, but if it is a text document, the content is not copied and files are not replaced, maybe I have not found a normal program. I think it is bad that developers did not take into account the possibility to set path from where to get robot or expert file. I thought it would be possible to set path as it is usually done, but as you have already mentioned it is not possible.

Note in this post the words "All terminals have shared folders."

This is not possible. Forum on trading, automated trading systems and testing of trading strategies

What should I do if I want to use a Marketplace product?

Sergey Tabolin, 2019.11.23 08:17

Do you seriously think I don't know how and where to install? )))

All terminals have common folders

I downloaded a free indicator from the market. It binds to the hardware.

Why does it work on one hardware, but not on the other?

Obvious conclusion - it binds, at least not only to the hardware...


Search for information on how this is done and off you go... This is called folder linking.

Reason: