Download MetaTrader 5

CreateObject To Display The Value of an enum?

To add comments, please log in or register
Do you know that MQL5 has event handling?
thili55
113
thili55 2014.05.02 01:41 

Title pretty much says it all. How do I display on chart which day is selected with create object? Just throwing the variable name in there like so shows as '0' on chart.

CreateObject("2",day,15,55+inc);
enum day
  {
   Sunday,
   Monday,
   Tuesday,
   Wednesday,
   Thursday,
   Friday,
   Saturday
  };
Keith Watford
Moderator
9614
Keith Watford 2014.05.02 03:12  

enum day doesn't have a value does it? Unless value is re-assigned, Sunday will be value 0,Monday 1 etc

enum day
  {
   Sunday,
   Monday,
   Tuesday,
   Wednesday,
   Thursday,
   Friday,
   Saturday
  };

Change them around

enum day
  {
   Saturday,
   Friday,
   Thursday,
   Wednesday,
   Tuesday,
   Monday,
   Sunday
  };

and then Saturday will be 0, Friday 1 etc

Ian Venner
2584
Ian Venner 2014.05.02 04:43  

I think he wants to display a chosen day like a string there is probably a way, but the documentation on using enums is true to form ...

I would like to know what is the point of gouping them in a named set.

honest_knave
Moderator
2192
honest_knave 2014.05.02 05:48  
Ian Venner
2584
Ian Venner 2014.05.02 06:03  

OK after hacking at that with a script I think I got it now. Probably this description is technically wrong but for all intents it seems to be, creating the enum days set is kinda like defining a new data type, so you can declare a new variable of the days type .... then you could use it in EnumToString() ... You might be able to pass day directly to the create function I'm not sure about all that though.

enum days
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};

days day = 4;

Print(EnumToString(day));  //prints Thursday




Keith Watford
Moderator
9614
Keith Watford 2014.05.02 06:26  
honest_knave:
EnumToString

SDC:

OK after hacking at that with a script I think I got it now. Probably this description is technically wrong but for all intents it seems to be, creating the enum days set is kinda like defining a new data type, so you can declare a new variable of the days type .... then you could use it in EnumToString() ... You might be able to pass day directly to the create function I'm not sure about all that though.


Thanks,

I've learnt something new there :)

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.02 06:28  
Yeah. Got one undocumented tricks. XD
Alain Verleyen
Moderator
30722
Alain Verleyen 2014.05.02 09:00  
GumRai:


Thanks,

I've learnt something new there :)

A new one probably : there is no need to create a new enum for days, it's already existing.

ENUM_DAY_OF_WEEK mylearningday=FRIDAY;
Print("My learning day is ",EnumToString(mylearningday));

Ian Venner
2584
Ian Venner 2014.05.02 14:26  
angevoyageur:

A new one probably : there is no need to create a new enum for days, it's already existing.

I what I did correct or is that an undocumented thing that might not work in the future ?
whroeder1
14480
whroeder1 2014.05.02 15:04  
SDC: I what I did correct or is that an undocumented thing that might not work in the future ?
Why create a new one that is identical to an existing one? You can't use yours with TimeDayOfWeek unless you write conversion routines between your days and enum_day_of_week. Etc.
Alain Verleyen
Moderator
30722
Alain Verleyen 2014.05.02 19:45  
SDC:
I what I did correct or is that an undocumented thing that might not work in the future ?
What you did is perfectly correct, but as WHRoeder said, not needed for working with days. By the way i don't think you are using something undocumented.
123
To add comments, please log in or register