- Multi parameter return value 'return( "string",double)
- [ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4.
- magic number - letters allowed?
- Please edit your post and place your sample code with the "</>" icon or Alt-S. It makes it easier to read your code. Don't just paste it as plain text.
- Do some research on structures — Documentation on MQL5: Language Basics / Data Types / Structures, Classes and Interfaces
- Study the following code and see if it suites your needs (untested code, just typed):
// Define a structure for a "cycle" struct SCycle { double dbPips, dbResult; int nTrades; }; // Declare a array for the "cycle" structure #define MCycles 3 SCycle oCycle[ MCycles ]; // Do something with the array of "cycle" void SomeFunction( void ) { for( int i = 0; i < MCycles; i++ ) PrintFormat( "Cycle: %d, Pips: %.1f, Trades: %d", i, oCycle[ i ].dbPips, oCycle[ i ].nTrades ); };
Should it be done differently?
No. yes. Create an array of a struct.
struct Cycle{ int cycle, nTrades; double pips, result; }; Cycle saved[3]; saved[0].pips=7
With your indications I have understood how struct works, according to the following example development approaching my objectives.
struct EstructuraCiclo { double CicloPips; string CicloMotivo; int CicloTrades; }; #define Num 3 EstructuraCiclo mVar[Num]; int Contador=0; //+------------------------------------------------------------------+ void OnTick() { if(Contador<Num-1) { mVar[Contador].CicloPips=0.1; mVar[Contador].CicloMotivo="Buy"; mVar[Contador].CicloTrades=Contador+1; Contador+=1; mFuncion(); } } //+------------------------------------------------------------------+ void mFuncion() { Print(TimeCurrent()); for( int i = 0; i <= Contador; i++ ) { Print( "Ciclo: ",i," | Pips: ",mVar[ i ].CicloPips," | Motivo: ",mVar[ i ].CicloMotivo, " | Trades: ", mVar[ i ].CicloTrades ); } }
So far so good.
But now, what can I do to increase the number of struct elements?
Thanks in advance,
Juan
Use a dynamic array of the structure instead of a static array — Documentation on MQL5: Language Basics / Data Types / Dynamic Array Object
A dynamic array can be resized to any any size at any time — Documentation on MQL5: Array Functions / ArrayResize
TThank you very much.
I have successfully implemented a data structure, with which I can continue with my current project.
I have been looking at dynamic arrays, but it is another level: I will read it again to be able to apply it, although I see that it is not a simple subject: The mql5 Manual, when you don't know anything about it, doesn't make things easy with simple examples.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use