Structure type variable OR Object ?

 

Hi everyone,

I'm trying to program cleanly,

what do you recommend for storing trade information and being able to manipulate it until the trade is closed?

I'm hesitating between creating a structure type variable, and creating a class with object manipulation to store all this information.

thank you in advance for your insights 

Best Reguards,
ZeroCafeine 😊

 

A structure or class is basically the same thing, where a structure is simpler than a class.

Forum on trading, automated trading systems and testing trading strategies

How to choose between structure and class?

Vladislav Boyko, 2023.11.18 02:33

In this topic, I propose to either create some list of rules for choosing between a structure and a class, or state that both options are equivalent in terms of performance.


 

Class , you can do pointer stuff . 

 
ZeroCafeine:

Hi everyone,

I'm trying to program cleanly,

what do you recommend for storing trade information and being able to manipulate it until the trade is closed?

I'm hesitating between creating a structure type variable, and creating a class with object manipulation to store all this information.

thank you in advance for your insights 

Best Reguards,
ZeroCafeine 😊

I find embedding structures into classes is a good option - you can create methods within the struct or in the object depending on your need and you do not lose any OOP capabilities.

This also helps when I need to copy a set of fields - if they are grouped together in a structure it is just 1 line of code
 
Thank you all very much for your answers, they mean a lot to me,

can someone give me an explanation or how to use a pointer or a link that is not too complicated so that I can understand this please?
 
ZeroCafeine #:Thank you all very much for your answers, they mean a lot to me, can someone give me an explanation or how to use a pointer or a link that is not too complicated so that I can understand this please?

I suggest you first learn to use structures, then classes without the use of pointers.

Once you know how to use them properly, then it will be easier to understand their pointer use.

Don't try to bite off more than you can chew.

 
Fernando Carreiro #:
Don't try to bite off more than you can chew.

Thanks for the expression 🤣

 
After doing a little research on pointers (thanks Youtube) not only did I understand their use but I realized that I was already using them but I had my own explanations which were of course wrong but which did the job correctly,

If I've understood correctly, you can't pass an array or an object as parameter to a function, hence the use of pointers, 

Here's an example of one of my pointer functions : 



ZeroCafeine #:
give me an explanation or how to use a pointer or a link 
If anyone has an answer please, No suggestion followed by a quote as Mr Fernando Carreiro does, please 😉
MQL5 - Comprendre les adresses
MQL5 - Comprendre les adresses
  • 2020.09.06
  • www.youtube.com
#mql5 #mt5 #metatrader📖 Un livre complet pour bien démarrer en MQL5: https://amzn.to/3d52dXZ📈 Mon broker préféré pour créer des robots de trading: https:...
 
ZeroCafeine #: After doing a little research on pointers (thanks Youtube) not only did I understand their use but I realized that I was already using them but I had my own explanations which were of course wrong but which did the job correctly, If I've understood correctly, you can't pass an array or an object as parameter to a function, hence the use of pointers, Here's an example of one of my pointer functions : If anyone has an answer please, No suggestion followed by a quote as Mr Fernando Carreiro does, please 😉

No! That example code is about passing a parameter by reference. It is not about class object pointers.

I was not being unreasonable in my previous post. There was a reason why I stated that you should first understand structures and classes, before attempting to understanding object pointers.

Documentation on MQL5: Language Basics / Data Types / Object Pointers
Documentation on MQL5: Language Basics / Data Types / Object Pointers
  • www.mql5.com
Object Pointers - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
ZeroCafeine #: If I've understood correctly, you can't pass an array or an object as parameter to a function, hence the use of pointers, 

No - you can pass arrays, structures and objects to functions. They must be prefixed with the ampersand as it is  "call by ref" only and you will get a complier error if you try otherwise.

With 'call by ref' you are indirectly passing a pointer to the variable/struct/object/array, as the function can overwrite the original memory space of the passed argument, with 'call by value' it takes a local copy.

The documentation has more info: Documentation on MQL5: Language Basics / Functions / Passing Parameters

I rarely use object pointers - if you master these basics you will find you can do mostly everything you need.

Documentation on MQL5: Language Basics / Functions / Passing Parameters
Documentation on MQL5: Language Basics / Functions / Passing Parameters
  • www.mql5.com
Passing Parameters - Functions - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
@ Fernando Carreiro 
Thank you for your answer, 

for my own explanation (and for my little brain), I think that using a variable as a reference (& ref) or a pointer (xxx* var) is simply using the memory address instead of the variable itself, correct me if I'm wrong.


Know that I'm here to learn, I always respect someone who teaches me something (It's part of my education), so you can talk to me however you want I'm not going to get angry 😊, but to answer you quickly you were not unreasonable but very unreasonable with your quote 😉,

As Albert Einstein said : "There's no such thing as a stupid question, only a stupid answer.", 

Fernando Carreiro #:
I was not being unreasonable in my previous post. There was a reason why I stated that you should first understand structures and classes, before attempting to understanding object pointers.

I'll take the time to read your links later this week and come back to this post 😉.

Reason: