CopyRates - BUG - page 2

 
fxsaber #:
I suppose that is one of the reasons.
Which exactly do you mean?
 
Ilyas #:
Hello Doerk,

you can send all details to me, I'll investigate.

Thanks. Appreciate that. 

From our last conversation I know, you gonna have internal restrictions when its about using DLLs?

But lets try to keep it as simple as possible and let me know how I can support your effort. 

 
Doerk Hilger #:


Bug:

The bug is clearly caused by a race condition between EA and indicator, the mutex is the proof. This should never be the case and MQL code should be treated thread-safe.  

If you are deliberately requesting from an indicator the same symbol/timeframe which are actual work environment of the chart, then this is against publicly announced rules. They are described both in the algortrading book and in MQL5 docs.

At the very beginning, we check if the timeseries of the current symbol and the current timeframe is requested from an indicator-type MQL program. Such requests are prohibited, since the "native" timeseries on which the indicator is running is already being built by the terminal or is ready: requesting it again may lead to looping or blocking.

The normal way of accessing current chart's timeseries in an indicator is via OnCalculate parameters.

PS. Here is the relevant docs.

MQL5 Book: Multicurrency and multitimeframe indicators / Creating application programs
MQL5 Book: Multicurrency and multitimeframe indicators / Creating application programs
  • www.mql5.com
Until now, we have considered indicators that work with quotes or ticks of the current chart symbol. However, sometimes it is necessary to analyze...
 
Stanislav Korotky #:

If you are deliberately requesting from an indicator the same symbol/timeframe which are actual work environment of the chart, then this is against publicly announced rules. They are described both in the algortrading book and in MQL5 docs.

The normal way of accessing current chart's timeseries in an indicator is via OnCalculate parameters.

PS. Here is the relevant docs.

I know what you mean and you are right. But I need also the flexibility to user further timeframes within the indicator, also other symbols.

All that can only be done using CopyRates, and it might then also happen, you access same timeframe of same symbol of another chart even. 

 
Doerk Hilger #:

All that can only be done using CopyRates, and it might then also happen, you access same timeframe of same symbol of another chart even. 

In a code of an indicator, if it detects that required symbol/timeframe is the same as of the curren chart, the indicator should not re-request the data, but only check the built-in synchroniation flag for the timeseries, and if it's not in sync - just leave the event handler for postponed attempt to try again later, for example on a next tick or on timer.

This is the current architecture of the terminal, even if it's not convenient for us MQL5 developers.

 
Stanislav Korotky #:
In a code of an indicator, if it detects that required symbol/timeframe is the same as of the curren chart, the indicator should not re-request the data, but only check the built-in synchroniation flag for the timeseries, and if it's not in sync - just leave the event handler for postponed attempt to try again, for example on a next tick or on timer.
Yep. 
Maybe I really should avoid CopyRates when just the actual timeframe of the actual symbol is used. The thing is, I dont access arrays directly, its done by my CBars class, since its way easier to read the code like bar.IsHammer(index), bar.IsCrossing(time, level) etc. and that would force me to modify a class which is there since many years and just does its job super-reliable. And this class is 1:1 the same in EA and indicators, also the same for MT4 and MT5. This change would break that. Always try to avoid to touch working things. 
 
No wait, the arrays of OnCalculate are not accessible outside OnCalculate, Id be force to manage a full copy. 
Unfortunately thats not an option, since I dont operate inside OnCalculate, its all done asynchronously in OnTimer to not block anything. 
 
Its all a little different from normal indicators. These indicators show typical indicating, graphical stuff, yes, but also they have panels and can be used for sending trading signals to the EA using IPC. 
 
You can try QuoteRefresh.mqh from the link above and if it returns true (synced timeseries), only then call CopyRates, otherwise skip processing until next request (because otherwise the code will hang anyway). Though, I'm not sure if this solve the issue.
 
Stanislav Korotky #:

If you are deliberately requesting from an indicator the same symbol/timeframe which are actual work environment of the chart, then this is against publicly announced rules. They are described both in the algortrading book and in MQL5 docs.

The normal way of accessing current chart's timeseries in an indicator is via OnCalculate parameters.

PS. Here is the relevant docs.

So the be clearer, the documentation you pointed says :

The next important check is checking the type of the program, from which the function is called. Note that it is not desirable to send a request to update the timeseries from indicator with the same period. The undesirability of requesting data on the same symbol-period as that of the indicator is conditioned by the fact that update of history data is performed in the same thread where the indicator operates. So the possibility of deadlock occurrence is high.

Did you checked that it can actually lead to deadlock ?

If yes, can you define "the possibility is high" ? And also in which (indicator) context it can happen ?