Download MetaTrader 5

I cant understand this error in using structure

To add comments, please log in or register
Stephen Reynolds
3981
Stephen Reynolds  

In the following code i always see error     'MqlDateTime' - struct or class already defined 

I cant see why? 

struct MqlDateTime
{ 
   int year;           // Year 
   int mon;            // Month 
   int day;            // Day 
   int hour;           // Hour 
   int min;            // Minutes 
   int sec;            // Seconds 
   int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) 
   int day_of_year;    // Day number of the year (January 1st is assigned the number value of zero)  
};

void OnInit()   
{ 
MqlDateTime time;

int day = time.day;
int hour = time.hour;
int dayOfWeek =  time.day_of_week;
struct MqlDateTime
peter.MT4Web
157
peter.MT4Web  

What do you think "already defind" means?

Select the Statement and press "F1".

Stephen Reynolds
3981
Stephen Reynolds  
eddie:

What do you think "already defind" means?

Select the Statement and press "F1".


I see that already defined means I have declared MqlDateTime as a struct data type and so I cant declare it again. But, how come for example in the following code i can assign a struct data type as tradeSettings and then define this object as trade which then allows me to access the member variable of the structure

 to create the slippage object. But, in the above code it doesn't let me define a new object as time using the declared MqlDateTime object? I've taken this all from the MQL4 reference and doesn't appear to work for me.

void OnInit()   
{
struct tradeSettings
{   
   ulong slippage;
   double price;
   double stopLoss;
   double takeProfit;
   string comment;
};       

tradeSettings trade;
ulong slippage = trade.slippage = 50;

Print(slippage);  
whroeder1
15331
whroeder1  
renzbub: I have declared MqlDateTime as a struct data type and so I cant declare it again.
Wrong, you have declared it as a struct; that is the second declaration. Compare your code with the example MqlDateTime - MQL4 Documentation
To add comments, please log in or register