Features of the mql5 language, subtleties and tricks - page 203

 
 

We are extending the initializing sequences "{ ... }", in the next build any expression will be allowed, not just a constant.

Instead of this change, there will be a restriction on using constants for enumerations (as for a normal expression): if a constant is not part of an enum, an appropriate error will be generated.

Analysis of existing codes has shown that the single zero sequence "{0}" is often used incorrectly.

For example, like this:

MqlTradeRequest request={0};


Such a notation means to set the value of zero for the first field of the structure and zero out the rest of the fields.

For the above code line, according to the new rules, there will be an error since the first field has the type ENUM_TRADE_REQUEST_ACTIONS, an enumeration that lacks the value "0".

cannot convert 0 to enum 'ENUM_TRADE_REQUEST_ACTIONS'


The correct way would be:

MqlTradeRequest request={};
 
Ilyas:

This is correct:

MqlTradeRequest request={};

And then what would request.action be equal to?

 
mktr8591:

And then what would request.action be equal to?

Zero, of course, as if ZeroMemory is called for the object of this structure

 

How do I keep track of time series and indicators based on them?

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Slava, 2021.05.29 18:16

I want to remind you.

1. For each symbol, for which at least one chart is open, a separate thread is working for processing the incoming ticks. Several charts may be open for some symbol, but there will still be only one thread.

2. The symbol thread handles timeseries, not charts. That is, the very same data arrays, which are submitted to the CopyRates request.

3. it is useless to ask your symbol in OnTick or OnCalculate, if it is synchronized. Of course it is!

4. All timeseries are handled in order, from lowest to highest. First we apply the tick, then the calculation of all indicators, created at this time series. If you ask data for the same H1 symbol from the indicator, working on M1, you will never get data with the applied tick. The data will always be one tick back, no matter what tricks you apply. Because one thread per symbol with consecutive timeframe processing.

5. The previous statement does not apply to EAs and scripts, because EAs and scripts each work in their own separate threads.


 
Andrey Khatimlianskii:

How do I keep track of time series and indicators based on them?

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Slava, 2021.06.01 06:34

When you first request, the indicator may not receive data from its symbol but another timeframe only for one reason - the required timeseries has not yet been built or has already been destroyed after some time, when there were no requests.

After an unsuccessful request, just send a command to your chart to update it and terminate OnCalculate immediately. It is guaranteed that OnCalculate will be called and the timeseries will be ready by this time

 

Forum on trading, automated trading systems and trading strategies testing

Features of mql5 language, subtleties and tricks

fxsaber, 2017.11.30 09:48

Memo

Action/type of program Change of TF or symbol Account change
Indicator Run OnDeinit and OnInit, global class object changes (full reset). Nothing happens except that prev_calculated is reset.
EA Run OnDeinit and OnInit, global class object does not change. Run OnDeinit and OnInit, global class object changes (full reload).
The highlighted behaviour of indicators has changed. It is now the same as the EA.
 
fxsaber:
The highlighted indicator behaviour has changed. It now coincides with the EA.

The point is different - could it be an oversight rather than a deliberate change in behaviour? Did you find out?

 
Artyom Trishkin:

The point is different - could it be an oversight rather than a deliberate change in behaviour? Did you recognise it?

I didn't. The feedback is almost non-existent. However, here's a feature I just found out about.

const bool Init = EventSetMillisecondTimer(1);
const long Account = AccountInfoInteger(ACCOUNT_LOGIN);

#define  TOSTRING(A) #A + " = " + (string)(A) + " "

void OnTimer()
{
  if (Account != AccountInfoInteger(ACCOUNT_LOGIN))
    Alert(TOSTRING(Account) + TOSTRING(AccountInfoInteger(ACCOUNT_LOGIN)));
}

This Expert Advisor alerts when switching between accounts. It would seem that it should not do so according to the rule.

Forum on trading, automated trading systems and strategy testing

Features of mql5 language, subtleties and tricks

fxsaber, 2017.11.30 09:48

Memo

Action/type of program Change of TF or symbol Account change
Indicator Run OnDeinit and OnInit, global class object changes (full reset). Nothing happens except that prev_calculated is reset.
EA Run OnDeinit and OnInit, global class object does not change. Run OnDeinit and OnInit, global class object changes (full reload).
However, this is due to the timer.
 
fxsaber:

This advisor alerts when switching between accounts. It would seem that it should not do this, according to the rule

However, this happens because of the timer.

No one has guaranteed that other event handlers will be interrupted (or not run).

After the alert, both deinit and init happen, right?

Reason: