Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1264
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
In the structure
STRUCT_POSITION
structure contains method
GetCurrentPositionProperty(void)
which calculates and assigns values to the elements of the structure. Define the body of the method outside the structure. To do this, use the context resolution operation (::).
In OnTick() we call the function:
void OnTick() { //--- STRUCT_POSITION.GetCurrentPositionProperty(); }
And here we get an error:
'.' - name expected eSower_and_Gather_5.mq5 69 19
I don't know where it went wrong, please help.
'.' - name expected eSower_and_Gather_5.mq5 69 19
What is line 69 19? Please publish the code line 69 and specify where the 19 position is. It will immediately become clear where the error is.
What is line 69 19? Post code line 69 and specify where the 19th position is. It will immediately become clear where the error is.
STRUCT_POSITION.GetCurrentPositionProperty();
It is highlighted in red in the post above. Thank you for your prompt reply.
What is line 69 19? Post code line 69 and specify where the 19th position is. It will immediately become clear where the error is.
This is a point that must give access to a function which in turn uses the structure context. But I cannot understand why it doesn't work.
it is highlighted in red in the post above. Thank you for your prompt reply.
'STRUCT_POSITION' is a DATA TYPE. You need to create a variable with this type and then call VARIABLE.GetCurrentPositionProperty();
This is the point that should give access to the function, which in turn uses the context of the structure.This is what I understood from the textbooks. But why it doesn't work I can't understand.
Code: (just calling a function - EA function, not a structure method - that makes more sense)
STRUCT_POSITION' is a DATA TYPE. You need to create an object with this type and then call OBJECT.GetCurrentPositionProperty();
Tried it. Such an object is created, declared right after declaration of the
StrPositionArray[].
If you put it into OnTick
we get an error:
']' - expression expected eSower_and_Gather_5.mq5 69 21
Code: (just calling a function - EA function, not a structure method - that makes more sense)
So using :: was a futile idea?
Then why did you write the function
inside the structure? It would fill the structure without any filling inside it, wouldn't it? Please clarify, I'm confused, maybe this is an obsolete feature, I should forget about it ?
So using :: was a waste of time?
Then why would you write a function
inside the structure??? I mean, it will fill the structure perfectly even without it. Please clarify, I'm confused, maybe this is an obsolete idea that should be forgotten.
Copypaste. There's a line left after copypaste.
It should be like this (there are no methods inside the structure)
Copypaste. There is a line left after the copypaste.
It should be like this (there are no methods inside the structure)
Well, I have spent so much time on the lesson. Although it was for MT4, it was presented there as a trick, so here is an extract from the text:
The structure has a Refresh() method which calculates and assigns values to the elements of the structure. Let's define the body of the method outside the structure. To do this, we use the context resolution operation (::). The context is a descriptor (name) of the structure:
Note that in the body of the method we refer to elements of the structure without using a dot, since we used the context resolution operation. Numeric fields are zeroed by ZeroMemory() with the this keyword before updating them at the beginning of the method body, so the structure passes a reference to itself.
The main EA code inside the OnTick() handler will now look like this