What is the difference?

 

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

 
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.

 

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? 

 

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

 

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

Next time try to read the docs.



 
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?

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

No good ? Well, there are always workarounds.

 
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
 
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?

 
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.

 
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.

Reason: