Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
jt27
36
jt27 2016.07.13 16:44 

I am trying to create an array of structs, everything I find online indicates there shouldn't be a problem with that, but I can't seem to get my code to compile when I try to do this.  Here is what I am trying to do:

// Heiken Ashi Candle Struct
int ha = 20;   // Make this number at least 5 more than the number of candles you plan on analyzing
struct heikenAshi {
   double haClose;
   double haOpen;
   double haHigh;
   double haLow;
}; 

struct heikenAshi haCandles[ha];  // Array of 'ha' Heiken Ashi candles with corresponding properties

 

 Any suggestions as to what I'm doing wrong?

Ovo Cz
2950
Ovo Cz 2016.07.13 17:56  

I would modify it like that:

 // Heiken Ashi Candle Struct

#define ha 20   // Make this number at least 5 more than the number of candles you plan on analyzing
struct heikenAshi {
   double haClose;
   double haOpen;
   double haHigh;
   double haLow;
   heikenAshi() {
	haClose = 0.0;haOpen = 0.0;haHigh = 0.0;haLow = 0.0;
   }
}; 

heikenAshi haCandles[ha];  // Array of 'ha' Heiken Ashi candles with corresponding properties
jt27
36
jt27 2016.07.14 00:24  
Ovo:

I would modify it like that:

 // Heiken Ashi Candle Struct

 

 

 

 

Thank you for your help!  If you don't mind, could you explain the purpose of putting the heikenAshi()... member in the struct?  I'm a hardware engineer and know just enough programming to get myself in trouble!
Ovo Cz
2950
Ovo Cz 2016.07.14 08:20  
jt27:
Thank you for your help!  If you don't mind, could you explain the purpose of putting the heikenAshi()... member in the struct?  I'm a hardware engineer and know just enough programming to get myself in trouble!
It is a constructor (a method which is triggered after the structure allocation), and in this case it sets default values to the struct members. Otherwise the values would be undefined (not initialised).
/
To add comments, please log in or register