Use classes instead of structures.
Thanks for feedback , am i to assume most people using mt5 just ignore the structs and use classes .
Sounds like the way am going too.
but later down the line in my project , when i come to the real high performance code talking to indicators, structs and thier light weight performance can be be very useful, that is why i am still sticking around on structs.
Anyway we have had your vote, thanks for sharing
I just sometimes need to use some of these features.
union StructToCharArray CharArrayToStruct FileLoad FileSave FileWriteStruct FileReadStruct FileWriteArray FileReadArray
struct MqlTick2 : MqlTick { uchar BrokerName[64]; }; void OnStart() { MqlTick2 Tick2; SymbolInfoTick(_Symbol, Tick2); }
thanks for the contributions guys, my conclusion so far is that MQL5 could really do with allowing pointers for structs.
Else structs could be risky, if you initially need only refence, then later on you find you need pointer , then you have to go back change it to class.
Cause you cant always know ahead if you gona need a pointer for a type which so far refence was enough, until .......
For now ill just take the pain around high performance code by using structs there, cause currently My computer is struggling to handle all the EA instances running on my PC.
So could do with efficiency of struct. but no pointer to struct, or reference to struct variable other than in function parameter is a pain. Makes the struct a sort of design trap.
the number of times i have had to go back to change struct to class in mql5 is demoralising, and makes me wish mql5 could be binned and replaced with c++2022.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In c++ you can declare a refence variable as member of struct
struct SomeStruct{}
struct MyStruct
{
int x;
string s;
SomeStruct& rSomeStruct;
}
the above does not compile in mql5, cause of the reference variable
In mql5 the only place i know that i can declare a reference variable is as function parameter SomeFunction( SomeStruct & in_ rSomeStruct )
My question is, how do i declare reference variable in mql5, other than as function parameter, example as struct or class member.
For performance reasons i have been trying to use structs for light weight types in my projects, but in mql5 due to no pointer to struct, struct become non flexible to move around.
So if there is no way to declare refence to struct as a member of class or struct, then maybe i might just use classes only in mql5, cause they are more flexible to move around due to pointers, you can pass class pointer as parameter or declare it as class or struct member.
thanks much for contribution in advance.
cheers