Questions from Beginners MQL5 MT5 MetaTrader 5 - page 503

 
Vladimir Fionov:
For currency pairs, if you put a limit, everything works, but for timeframe does not work, even if you put it on h1 indicator does not work

https://docs.mql4.com/ru/chart_operations/periodwindow

https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes

Return valuePeriod of the current graph (in minutes).

if(Period() != 60)  return(-1); // для H1

Try it, maybe it will work.

if(Period() != PERIOD_H1)  return(-1);

Or remove inverted commas.

Period - Документация на MQL4
  • docs.mql4.com
Period - Документация на MQL4
 
Vladimir Zubov:

https://docs.mql4.com/ru/chart_operations/periodwindow

https://docs.mql4.com/ru/constants/chartconstants/enum_timeframes

Return valuePeriod of the current graph (in minutes).

Try it and see if it works.

Thank you very much, it worked!!!
 
Another question, when adding a #property strict at the beginning the indicator gives an error array out of range in 'Indicator name' (100,41) how to deal with this

 
Vladimir Fionov:
Another question, when adding in the beginning when #property strict indicator gives error array out of range in 'Indicator name' (100,41) how to deal with it

You need to fix the array out of range. Localization of the problem in your code: line 100, character at position 42.
 
Vladimir Fionov:

What's wrong with it?

  1. Correctly paste the code in the forum
  2. You should fix the error of exceeding the"ema[]" array's limits. You are probably calculating the"limit" variable incorrectly.
 
Karputov Vladimir:
  1. Inserting code correctly in the forum
  2. You should fix the error of exceeding the"ema[]" array's limits. You are probably calculating the"limit" variable incorrectly.
Sorry, I didn't know about the code insertion, but about the code itself, why does this happen when you insert #property strict and everything works without it
 
Vladimir Fionov:
I'm sorry, I didn't know about the code insertion, but as for the code itself, why does it happen when you insert #property strict and everything works without it?

Have you seen the help in MetaEditor?

The work with functions, scope of variables and freeing memory in local arrays has also changed. Since the changes turned out to be quite significant, it was decided to introduce a new property #property strict in order to maximize compatibility with the old approach to writing MQL4 programs. When creating a new MQL4 program using the MQL4 Wizard, this property is always added to the template.

And so on:

Table of differences between compilers:

Old MQL4 compiler

New MQL4 Compiler

New MQL4 compiler with #property strict

Entry points init(), start(), deinit() can have any parameters and any return type

init(), start(), deinit() retained for compatibility,

and the newOnInit(),OnStart(),OnCalculate(),OnTick(),OnTimer(),OnChartEvent(),OnTester(),OnDeinit() must exactly match their signatures

Same

The return result of the init() function is not analyzed in any way by the executing subsystem

The return result of the init() and OnInit() functions is not analyzed in any way by the executing subsystem

When returning a non-zero value from OnInit(), the expert or indicator stops and the program is unloaded

Variable names can be almost any (except for reserved words), including special characters and full stops

Variable names cannot have special characters and full stops.

The listof reserved words is extended, so common words like short, long, const, etc. cannot be named.

Same

The scope of a variable is from the declaration (even in a nested block) to the end of the function.

Same

Visibility range of a variable - from the declaration to the end of the block in which the variable is declared.

Implicit initialization of all variables (both global and local) with zeroes.

The same

Initialization of global variables only. From local variables, only strings are implicitly initialized

Local arrays are not freed on leaving the function

Local arrays are freed on leaving the function

Local arrays are freed on exit {}

Array out of range"error does not lead to a critical error*.

Same. Except for arrays of structures and classes for which this error is critical

"Array out of range" is a critical error and causes the program to stop

No structures and classes

There arestructures and classes. Additional data types appear.

Same

Strings - single-byte.

datetime - 32-bit integer

Predefined variable Volume has type double

Strings - unicode.

datetime - 64-bit integer

Volume is a predefined variable of long type.

Same

ArrayCopyRates() produces virtual copying to array double[][6]

ArrayCopyRates() produces a virtual copying to MqlRates[] array. For compatibility, copying to array double[][6] remains, but this copying is not virtual but real.

Also.

Functions may not return values even if they have a type. For this purpose, the compiler automatically inserts return(0) at the end of the function.

Same.

Functions of any type must always return a value

Number of files opened simultaneously - 32

Number of files being simultaneously opened - 64

Same

Files are always opened in shared mode **

The sharing mode must be explicitly declared with FILE_SHARE_READ and/or FILE_SHARE_WRITE

Same

The scripts in the input window show theextern variable names

The names ofextern andinput variables are shown in the input parameters window for the scripts in show_inputs mode.

For scripts in the show_inputs mode, string comments are shown in the input window instead ofextern andinput variable names

* You should pay special attention to the "Array out of range" error - many old custom indicators will produce this error in the new compiler in strict mode when running on a chart. It is desirable to find the cause and fix it.

** In the new MQL4 and MQL5 the FILE_SHARE_READ and FILE_SHARE_WRITE flags are responsible for the file sharing mode, they didn't exist in the old MQL4.

Препроцессор - Документация на MQL4
  • docs.mql4.com
Препроцессор - Документация на MQL4
 
Vladimir Fionov:
tell me what's wrong?
  int idx;
  int counted = IndicatorCounted();
  if (counted < 0) return (-1);
  if (counted > 0) counted--;
  int limit = Bars - counted;
  if(counted == 0) limit-=1;
Try adding a line like this.
 
Vladimir Fionov:

Sorry if I'm bothering you, but now there's this error

39th position.

Same error, array out of range ?
 
Vladimir Zubov:
Same error, array out of range ?
YES