Features of the mql4 language, subtleties and techniques - page 4

 
Alexey Kozitsyn:
Wow, this is a subtle point. Did they write it in the SD?

The author has written. The capabilities of the language have long been inconsistent with the old documentation, i.e. undocumented things are actually used, which is a strange claim to make accordingly.

Forum on trading, automated trading systems and strategy testing

How to quickly compare double and QNaN ?

fxsaber, 2016.10.11 15:56

Left unnoticed.

double QNaN   =Nan(0x7FF7000000000000);  

The initial value of a global variable can now be declared via a function!

The same goes for the rest of the static variables.

Strange that the developers were silent about this innovation.


Документация по MQL5: Основы языка / Переменные / Статические переменные
Документация по MQL5: Основы языка / Переменные / Статические переменные
  • www.mql5.com
Основы языка / Переменные / Статические переменные - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
fxsaber:
There's a subtle point about static in both languages

Alexey Kozitsyn:
Wow, what a fine point... Did you write it in SD?

Is it all right that the help says that a static variable... read it for yourself.

A static variable can be initialized by a constant or a constant expression appropriate to its type unlike a simple local variable which can be initialized by any expression.


But not a function.

This is how it works

#property strict
#property indicator_chart_window

int TestBrokenStatic()
{
   static int stInt = 101;
   stInt++;
   return stInt;
}

int OnInit()
{
   static int result = 0;
   result = TestBrokenStatic();
   Print("TestStatic Expected result 102   - Actual result=", result);
   result = TestBrokenStatic();
   Print("TestStatic Expected result 103   - Actual result=", result);
   
   return INIT_SUCCEEDED;
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return rates_total;
}
2017.04.29 13:49:51.546 !Test USDCHF,M15: TestStatic Expected result 103   - Actual result=103
2017.04.29 13:49:48.457 !Test USDCHF,M15: TestStatic Expected result 102   - Actual result=102
2017.04.29 13:49:40.089 Custom indicator Test\!Test USDCHF,M15: loaded successfully
Статические переменные - Переменные - Основы языка - Справочник MQL4
Статические переменные - Переменные - Основы языка - Справочник MQL4
  • docs.mql4.com
Статические переменные - Переменные - Основы языка - Справочник MQL4
 
Alexey Viktorov:

Is it all right that the help says that a static variable... read it for yourself.

But not a function.

That's how it works.

Then the compiler must give an error...
 
Alexey Viktorov:

Is it all right that the help says that a static variable... read it for yourself.

Is it ok that I gave a link to the documentation at once and a link to a six-month old code discussion from the developers... Follow your own advice.

Especially with static const.

 
fxsaber:

Is it OK that I gave a link to the documentation at once and a link to a discussion of code from the developers from half a year ago... follow your own advice.

Especially with static const.

I didn't look at the link because I don't know aglitskiy language, and mech. translation is sometimes more incomprehensible than Chinese/Japanese with a dash of korean.

And you don't have to be so sensitive. There's not a hint of reproach in my words that you didn't pay attention to such a trifle.

 
Alexey Viktorov:

I did not look at the link due to my lack of knowledge of the aglitsky language, and the mech. translation is sometimes more incomprehensible than the Chinese/Japanese with a dash of korean.

Oh, and there's no need to be so morbid about it. My words don't contain a hint of reproach that you didn't pay attention to such a trifle.


Forum on trading, automated trading systems and strategy tester

Features of mql4 language, subtleties and tricks

fxsaber, 2017.04.29 11:07

The features of the language have long been inconsistent with the old documentation, i.e. actually undocumented things are used, claims about which are accordingly strange to make.

 
Alexey Kozitsyn:
Then the compiler should give an error...

Maybe it should, but... we have what we have.

 
fxsaber:

Wasn't it like that in the old documentation?


ps. It's much too late for me to grasp the meaning of these references...

But here's a rebuttal to the statement

fxsaber:

Left unnoticed.

The initial value of a global variable can now be declared through a function!

The same is true for the rest of the static variables.

It's strange that the developers are silent about this innovation.

Or is this about something else entirely? Declare or initialize?
 
static const bool IsTester = (::MQLInfoInteger(MQL_TESTER) || ::MQLInfoInteger(MQL_OPTIMIZATION) ||
                              ::MQLInfoInteger(MQL_VISUAL_MODE) || ::MQLInfoInteger(MQL_FRAME_MODE));
 
fxsaber:

I can't check right now, but MQL_TESTER seems to include everything else. But everything else separately does not include each other.

That is, to understand that the program works in the tester (in any of listed modes), you only need to check the very first flag.

Reason: