[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 644

 
Myth63:


The matter is that I'm not really good at MQL programming and my EA is based on the BASIC principles =) A variable is assigned to an open order. The terminal says that I have been re-logged and the value of this variable disappears when the order is opened. I think what should be done if the order is re-logged? If this happens, the terminal should check for the open positions and assign those values to the variables that have been assigned by the robot. And the Expert Advisor shows good readings in the test.

Depending on what you want to store (what information), different options can be used:

  • the information about the order can be stored in its comment and then read from the comment;
  • the information you want can be written to a file - a slow process;
  • The most often used variant is to write it in global variables of the terminal.
 
FelixFX:

If you don't mind, here's an example. As far as I understand, the data will not be updated until the loop is executed?
int start()
{
//----
    while (!IsStopped() && IsExpertEnabled())
    {fMineFunction();}
//----
    return (0);
}
 
TarasBY:

Will only the same data be used during this endless cycle? Will the data be updated with the new tick or not?
 
Myth63:


The thing is that I'm not very good at MQL programming and my EA is based on Bacyca principles =) A variable is assigned to an open order. The terminal says that I have been re-logged and the value of this variable disappears when the order is opened. I wonder how to make it check for open positions if there is an overlog and assign those values to the variables that have been assigned by a robot.

Are you talking about magic number? Not enough information to help you... what's the variable and how it's assigned - that's where you need to start from.

But my Expert Advisor is showing good results in the test.

100 trades isn't a reading, it's a good piece of history. A couple of thousand trades over 2-3 years is something you can trust.
 
FelixFX:

Will only the same data be used during this endless cycle? Will the data be updated with a new tick or not?
No. For it to be updated, it has to be this. The question about looping is answered by the site search engine, how many pages it returns. Read it.
 
FelixFX:

Will only the same data be used during this endless cycle? Will the data be updated with the new tick or not?
The loop allows you to run your function in a "loop", without waiting for the next tick to arrive. What data are you asking about?
 
Please advise if there is a built-in function that allows me to run a function that I wrote just at the opening of each bar, not on each tick. It seems to be easy to write by hand, but when part of the code is executed by ticks, and part by bars, the program gets very confusing) Thanks a lot)
 
Qwertee:
Please advise if there is a built-in function, that I can run some function, written by me, just at opening of each bar, not on each tick. It is not so difficult to write by hand, but when some code is executed by ticks and some by bars, the program gets very confusing) Thanks a lot)

so you just determine when a new bar opens and perform your function.

You can determine the appearance of a new bar by memorising the opening time of the bar and then comparing it with the current time of bar 0. If the new time is longer than the previous time, then we have a new bar.

 

sergeev thanks for the advice, it seems to work)

Ok, one more thing.

In my EA I have this branching:

if(period=="M15")
{
//check to open buy
Alert(buysell);

if(buysell=="buy")

Alert(1);

.............

}

Basically, nested if. BUT. condition if(period=="M15") is fulfilled and Alert gives a result, and buy, but condition if(buysell=="buy") is not fulfilled and Alert(1) command is not even started. hell, both conditions are even syntactically the same, but why one is fulfilled and the other is not?

 
sergeev:

so you just determine when a new bar opens and perform your function.

You can determine the appearance of a new bar by memorising the opening time of the bar and then comparing it with the current time of bar 0. If the new time is longer than the previous time, then you have a new bar.

I will describe it here:

int time.marker;

void start() {
   if(time.marker!=Time[0]) {
      time.marker=Time[0];
      // тут то что буде исполнятся только на открытии бара
      }
   // тут то что буде исполнятся на каждом тике
   }
Reason: