Date error in MT4?

 

Hi,

I run this code:

Print("Year: ",Year());


and got 1900 instead of 2016.

???

What did I wrong?

 

How did you run that? Show us some of surrounding code flow so that we can understand the context in which you ran the code!

Also, was it run against a live Chart or was it in the Strategy Tester?

 
FMIC:

How did you run that? Show us some of surrounding code flow so that we can understand the context in which you ran the code!

Also, was it run against a live Chart or was it in the Strategy Tester?

Live chart. Year() is the current year in all circumstances, isn't it?

How can it be other than 2016 (now)?

 

If you want us to help, you need to give us more details. It may seem unnecessary but sometimes, in those details we can pickup clues in order to identify the problem.

  • What version/build of MT4 is it?
  • What chart Symbol did you use?
  • What chart time-frame did you use?
  • A screen shot of the Chart (or the entire screen) maybe useful too!
  • Is it a Script, EA or Indicator?
  • Can you supply some more code so that we can look at the bigger picture?
  • Can you supply us with the entire journal log, from beginning to end of the execution?
  • Any other details that can help use understand would be great too.

I know, that plenty of this is superfluous, but since we cannot read your mind nor see what you are doing, we need extra details in order to recreate the conditions that are leading to the problem in order to find a solution.


As an example, I ran this Script code against a EURUSD H1 Chart on MT4 Build 950:

#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   Print("Year: ",Year());
}
//+------------------------------------------------------------------+


The Experts log results were the following:

2016.04.10 15:27:56.403 Script YearTest EURUSD,H1: removed
2016.04.10 15:27:56.403 YearTest EURUSD,H1: uninit reason 0
2016.04.10 15:27:56.403 YearTest EURUSD,H1: Year: 2016
2016.04.10 15:27:56.403 YearTest EURUSD,H1: initialized
2016.04.10 15:27:56.403 Script YearTest EURUSD,H1: loaded successfully
 
FMIC:

If you want us to help, you need to give us more details. It may seem unnecessary but sometimes, in those details we can pickup clues in order to identify the problem.

  • What version/build of MT4 is it?
  • What chart Symbol did you use?
  • What chart time-frame did you use?
  • A screen shot of the Chart (or the entire screen) maybe useful too!
  • Is it a Script, EA or Indicator?
  • Can you supply some more code so that we can look at the bigger picture?
  • Can you supply us with the entire journal log, from beginning to end of the execution?
  • Any other details that can help use understand would be great too.

I know, that plenty of this is superfluous, but since we cannot read your mind nor see what you are doing, we need extra details in order to recreate the conditions that are leading to the problem in order to find a solution.

I really, really appreciate your help intention, but I think it would be faster, if you answer for this:

is there any possibility, when a simple Year() can give other value than 2016? I don't think so.

(My code is long and complicated.)

 
Yes, there is one possibility I can think of, and that is if you are not connected to the Broker's server, which is so obvious I hope is not your case (i.e. You did not do an Account login).
 
FMIC:
Yes, there is one possibility I can think of, and that is if you are not connected to the Broker's server, which is so obvious I hope is not your case (i.e. You did not do an Account login).

 Connection is OK, of course.

 

1. Send us a copy of the log for that section of the code execution (with the date and time of the log entry) like in my example above.

2. Send as Screenshot of the Chart used with it scrolled to the very end (latest data).

3. What is the time displayed in the Market watch? Send a screenshot like this:

Market Watch

 

Why are you not willing even to answer some of the more innocuous of questions such as:

  • What version/build of MT4 is it?
  • What chart Symbol did you use?
  • What chart time-frame did you use?
  • Is it a Script, EA or Indicator?
 
FMIC:

Why are you not willing even to answer some of the more innocuous of questions such as:

  • What version/build of MT4 is it?
  • What chart Symbol did you use?
  • What chart time-frame did you use?
  • Is it a Script, EA or Indicator?

Dear FMIC, I'm not a beginner, please consider this.

These questions are not relevant for my case. Look:

Build 950

EURUSD

M15

Indicator

 

Since you are obviously afraid of showing your code, use my code example (see the script above) as the test code and then give use the results of that code.

Save it as "YearTest.mq4" and place it in the "Scripts" folder and run it against a EUR/USD H1 chart just as I have. It will then serve as the comparison between our two respective systems.