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

 
TYRBO:
problem solved by comparing prices
In the tester? In a real market on a floating spread account, the breakeven price will change after one tick
 
Artyom Trishkin:

In this context, my point is this:

  1. We need to get as few cycles per tick as possible.
  2. We need to have one constant array with data of market orders and positions and one array with data of deleted/closed orders and positions
  3. If we have the array locally in a function, calling it repeatedly requires filling it again. I suggest that it is filled only once at a new tick - so the array is global, otherwise we would lose it when exiting the function.
  4. In order to find something in it (in the array), we need a filled array and functions that will return the found data. Within functions, we can declare auxiliary arrays for necessary calculations.

For this reason, it would be better to have global arrays - for closed and open orders and positions. Once on a new tick, we pass the necessary amount of orders/positions once, filling the two arrays with them. And then we get all the necessary data from them on the same tick. Note that not only the last closed/open order/position and all its data are calculated, but also all parent and child ticks of all positions are searched in case of partial closing. Accordingly, at any time I can see which ticket originated from one or another position, if it has been closed partially more than once - all this already works in a class that runs in a timer. I have many other data I need with a small total number of cycles. The necessary depth of history for arrays is set for the tester.

And so on and so forth ...

Sorry. One more addition (not to counterbalance, but as an addition), I'd like to add that local arrays withstatic are not lost. That is, if conditions allow you to do without declaring them globally.

 
P./S.: I am completing this, of course, based on my own "vested" interest))). Because I can apply local static in permissible cases.
 
Vitaly Muzichenko:

I'm now slowly rewriting it for 5. I mean that price may change very quickly and the level may be less than the stop-loss value, which will lead to an error. I mean that the price may change very quickly and the level will be less than the allowable stop level, which will lead to an error.

I understand that this"SymbolInfoTick" thing is needed to get the current price?

So, to get the actual Ask and Bid in mql4, the refresh should have been called anyway. And it turns out that the load is unlikely to change compared to calling SymbolInfoTick().

But here's another addition: I write SymbolInfoTick() in the following loop to get accurate prices

        do
         while(!SymbolInfoTick(_Symbol, mqlTick));

If we get normal prices from the first time, this loop will not increase the execution time. And if there's some failure, it's better to repeat than to get the same price instead of the current one.

 
Alexey Viktorov:

So, to get actual Ask and Bid in mql4, you have to call refresh anyway. And it turns out that the load is unlikely to change compared to calling SymbolInfoTick().

But here's another addition: for error-free getting of actual prices, I put SymbolInfoTick() into this loop

        do
         while(!SymbolInfoTick(_Symbol, mqlTick));

If we get normal prices from the first time, this loop will not increase the execution time. And if there's some failure, it's better to repeat than to get the same price instead of the current one.

I see, where should we put it, inside or before the loop?
 
Vitaly Muzichenko:
I see, but where should I put it, inside the cycle, or before?
Well, it's a separate cycle until we get the current prices. We have already discussed where to put it. If there is an ambush with not actual prices, we should set it in the loop of order evaluation.
 
Alexey Viktorov:

So, to get actual Ask and Bid in mql4, you have to call refresh anyway. And it turns out that the load is unlikely to change compared to calling SymbolInfoTick().

But here's another addition: for error-free getting of actual prices, I put SymbolInfoTick() into this loop

        do
         while(!SymbolInfoTick(_Symbol, mqlTick));

If we get normal prices from the first time, this loop will not increase the execution time. And if there's some failure, it's better to repeat than to get the same price instead of the current one.

And if you don't get them at all? How do you slow down the loop?
 
Artyom Trishkin:
And if it doesn't receive it at all? How do you slow down the cycle?

Yes, logically it could be, for example, the terminal has lost connection - there are plenty of reasons for that, I have had it lose connection 50 times a day.

What's the best way to get up-to-date prices, while being less resource-intensive, mind you - for the grid trawl.

 
Vitaly Muzichenko:

Yes, logically it could be, for example, the terminal has lost connection - there are plenty of reasons for that, I have had it lose connection 50 times a day.

What's the best way to get up-to-date prices, while being less resource-intensive, remember - for the grid trawl.

check back 10 pages, there's a good scheme there
 
trader781:
check back 10 pages, there's a pretty good schematic there.
Couldn't find it, and I don't remember it here.