The second code is creating an object directly on the stack of the function. When passing this object to a function, a copy of the object is created on the stack of the called function.
When the called function alters the object, it changes only the local copy.
A pointer points to an object created on the heap memory of the process, therefore it referes to the same object.
To achieve same you can pass the object (from stack) to a function which uses a reference as input.
Overweight:
The code generated by EA generator MT5 includes definitions of object pointer for example :
Why not use this method?
Just place the cursor of the editor on new and press F1 - you'll directly forwarded to the doc. of the MQL functions.

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
The code generated by EA generator MT5 includes definitions of object pointer for example :
CExpertSignal *signal = new CExpertSignal;
Why not use this method?
What is the reason for using the new operator?