Download MetaTrader 5

What is the difference?

To add comments, please log in or register
Gordon Gekko
623
Gordon Gekko  

Hi friends,


What is the difference between these two codes?

The first one doesn't work, the second one works fine. Is there any difference the two kind of TP_Day?

Wrong:

if(GlobalVariableCheck(Glob_Var_Name)) TP_Day=(int) GlobalVariableGet(Glob_Var_Name);
else if(!GlobalVariableCheck(Glob_Var_Name)) TP_Day=(int) GlobalVariableSet(Glob_Var_Name,0);

// some code here

TP_Day=(int) GlobalVariableSet(Glob_Var_Name,TimeDayOfYear(TimeCurrent()));

Good:

if(GlobalVariableCheck(Glob_Var_Name)) TP_Day=(int) GlobalVariableGet(Glob_Var_Name);
else if(!GlobalVariableCheck(Glob_Var_Name)) TP_Day=(int) GlobalVariableSet(Glob_Var_Name,0);

// some code here

GlobalVariableSet(Glob_Var_Name,TimeDayOfYear(TimeCurrent()));
TP_Day=TimeDayOfYear(TimeCurrent());

Thx

Simon Gniadkowski
Moderator
18024
Simon Gniadkowski  
ggekko:

Hi friends,


What is the difference between these two codes?

The first one doesn't work, the second one works fine. Is there any difference the two kind of TP_Day? 

If the . . .

GlobalVariableSet(Glob_Var_Name, TimeDayOfYear(TimeCurrent()))

 fails it returns 0 and TP_Day will be 0  What is actually wrong   "doesn't work,"  with the first code ?  you didn't actually say.

Keith Watford
Moderator
10570
Keith Watford  

in your first code you are giving TP_Day the datetime value for when the GV was modified and then converting it to an integer.

in your second code you are assigning the day of the year to TP_Day. Also it has no relationship to the GV at all.

 

What are you trying to do? 

Gordon Gekko
623
Gordon Gekko  

Thank you guys. In fact, I wasn't exact.

My problem is this:

TP_Day=(int) GlobalVariableSet(Glob_Var_Name,TimeDayOfYear(TimeCurrent()));

In this case TP_Day gets a datetime value (for example: 1411245785). Why not (say) 134?

This

TimeDayOfYear(TimeCurrent())

gives a number between 1..365. The GV gets this 1..365 number, but TP_Day gets 1411245785.

Why do I get a datetime instead of an int?

What does "(int)" actually do?

So, can you show me the right code that gives TP_Day a value between 1..365?

Thx

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  

https://docs.mql4.com/dateandtime/dayofyear

Next time try to read the docs.



Gordon Gekko
623
Gordon Gekko  
deysmacro:

https://docs.mql4.com/dateandtime/dayofyear

Next time try to read the docs.



I did it before. Thank you deysmacro, sit down, please.

(TimeDayOfYear and DayOfYear give an int value between 1..365.)

Anybody else?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
TP_Day0=TimeDayOfYear(TimeCurrent());
TP_Day=(int) GlobalVariableSet(Glob_Var_Name,TP_Day0);

No good ? Well, there are always workarounds.

Keith Watford
Moderator
10570
Keith Watford  
ggekko:

Thank you guys. In fact, I wasn't exact.

My problem is this:

In this case TP_Day gets a datetime value (for example: 1411245785). Why not (say) 134?

This

gives a number between 1..365. The GV gets this 1..365 number, but TP_Day gets 1411245785.

Why do I get a datetime instead of an int?

What does "(int)" actually do?

So, can you show me the right code that gives TP_Day a value between 1..365?

Thx



I already answered your question in the post before yours
Gordon Gekko
623
Gordon Gekko  
GumRai:
I already answered your question in the post before yours

No. Why datetime? Why not integer?

In this formule:

TP_Day=(int) GlobalVariableSet(Glob_Var_Name,TimeDayOfYear(TimeCurrent()));

what does (int) do? Why do I get a datetime instead of an integer for TP_Day?

Keith Watford
Moderator
10570
Keith Watford  
ggekko:

No. Why datetime? Why not integer?

In this formule:

what does (int) do? Why do I get a datetime instead of an integer for TP_Day?

As I said - Already answered
GumRai:

in your first code you are giving TP_Day the datetime value for when the GV was modified and then converting it to an integer.

in your second code you are assigning the day of the year to TP_Day. Also it has no relationship to the GV at all.

Gordon Gekko
623
Gordon Gekko  
GumRai:
As I said - Already answered

No.

"in your first code you are giving TP_Day the datetime value" WHY???

TimeDayOfYear(TimeCurrent())

Is this datetime?! I think this is integer.

123
To add comments, please log in or register