Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1332

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Digging through documentation and forum ...
How to make variables of pointer type global [in the example var], if they are created in OnInit() by string:
and the number of objects and constructor parameters are unknown in advance and are calculated in OnInit() ?
That's easy.
Hello
mt5 has a crosshair button
When you press it on the chart, it shows how many bars, how many pips and percent
Help me how to correctly calculate this value so that i can bind it to my robot
Thank you
Is the new bar class already in place?
And what exactly do the input parameters look like?
The class is borrowed from:https://www.mql5.com/ru/code/768, minor changes made
It is intended to be applied as follows:
Easy.
Thanks for the reply)
At first I did so.
So the object is created twice, first empty, then as it should be by a constructor with parameters.
But ... In this case the compiler prints a warning on the line in OnInit():
declaration of 'var1' hides global variable -> on the line in OnInit()
see previous declaration of 'var1'.
So a local variable hides a global variable ... So what happens?
What variable will then be seen by another function, OnTick(), for instance? The global variable is =NULL, the local one is initialized correctly but cannot be seen by another function ...
The class is borrowed from:https://www.mql5.com/ru/code/768, with minor modifications
It is supposed to be applied as follows:
Extract all substrings from the input parameters and use them to create names of symbols and corresponding timeframes.
Then create new bar objects from these lists and place pointer to each object to be created - "New Bar" - in CArrayObj that is declared globally.
Next, it receives a pointer to the next object in the list in the OnTimer() loop and checks for a new bar. If there is no new object, you must go to the next one, if there is, you must do what you must do when a new bar opens.
The timer should be set according to your needs - millisecond, second, minute - in general, with whatever frequency you consider sufficient to react to a new bar on a non-current symbol.
Thanks for the reply)
At first I did so.
So the object is created twice, first empty, then as it should be by a constructor with parameters.
But ... In this case the compiler prints a warning on the line in OnInit():
declaration of 'var1' hides global variable -> on the line in OnInit()
see previous declaration of 'var1'.
So a local variable hides a global variable ... So what happens?
What variable will then be seen by another function, OnTick(), for instance? The global variable is =NULL and the local one is initialized correctly, but cannot be seen by another function.
Look closely. That is not what you did.
From the input parameters all substrings must be extracted, from which the names of symbols and their corresponding timeframes must be compiled.
Then create new bar objects from these lists and put a pointer to each new object into CArrayObj that is declared on global level.
Next, it receives a pointer to the next object in the list in the OnTimer() loop and checks for a new bar. If there is no new object, you must go to the next one, if there is, you must do what you must do when a new bar opens.
Make a timer according to your needs - millisecond, second, minute - in general, with whatever frequency you think is enough to respond to a new bar on a non-current symbol.
This is what I was doing, but ArrObj.At(0) doesn't call theclass member functions...
Take a closer look. That's not what you were doing.
Already noticed)
So the solution is to declare globally empty objects....
And if you don't know beforehand how many of them there will be ? Just declare "with reserve" ? :)
P.S. I didn't find this way of declaring objects in the built-in help
CObj* var1 = NULL;
Already noticed)
So the solution is to declare globally empty objects....
And if you don't know beforehand how many of them there will be ? Just declare them "with reserve" ? :)
Put inCArrayObj.
TheArrObj.At(0) functionreturns a pointer to a base class that knows nothing about the members of the derived class.
In order to refer to them, just do a type conversion.
CIsNewBar* newBar = (CIsNewBar*)ArrayObj.At(0); newBar.method( parameter );
Put inCArrayObj.
FunctionArrObj.At(0) returns pointer to base class, which knows nothing about derived class members.
Just do a type conversion to refer to them.
Thanks for the reply, you're not evil at all)
Now everything is clear)
UPD
This is the construction that works too
CIsNewBar* newBar = ArrayObj.At(0); newBar.method( parameter )