title: MetaTrader 4 / MQL4 Time is off by -5 hours but only when using epoc time
body: <p>I'm working with MetaTrader4 running in WINE in Ubuntu 16.04. I have a simple inline function that saves the time and various other info to a file using this line:</p>
  
  <pre><code>FileWrite(data_filehandle, "sys_time:" + (string)TimeLocal() + "." + StringFormat("%06lu", usec_instance) + ", sym:" + (string)Symbol() + ", tick_time:" + (string)last_tick.time + ", ask:" + (string)last_tick.ask + ", bid:" + (string)last_tick.bid);
  </code></pre>
  
  <p>Using the directive:</p>
  
  <pre><code>#property strict
  </code></pre>
  
  <p>will cause it to output the time in a Date Time format.
  Removing that directive will cause it to output time in epoc format.</p>
  
  <p>When it uses Date Time format ( by using '#property strict' ), the time is correct.</p>
  
  <p>It outputs:</p>
  
  <pre><code>sys_time:2020.01.21 07:38:02.994394, sym:EURUSD, tick_time:2020.01.21 14:38:03, ask:1.1104, bid:1.1103
  </code></pre>
  
  <p>This matches my system time correctly.</p>
  
  <p>Now if I remove '#property strict' to switch to epoc time</p>
  
  <p>It outputs:</p>
  
  <pre><code>sys_time:1579592538.630395, sym:EURUSD, tick_time:1579617738, ask:1.1105, bid:1.11041
  
  </code></pre>
  
  <p>my local time is:</p>
  
  <pre><code>$ date '+%s'
  1579610544
  
  $ date '+%Z %z'
  EST -0500
  </code></pre>
  
  <p>my time: 1579610544 - MT4 LocalTime: 1579592538 = 18006 seconds  (Which is 5 hours and 6 sec behind me)</p>
  
  <p>Any idea on what could be causing this?
  I might be slightly less confused if it were +5 hours because that would be GMT.
  But it's -5 hours which is Hawaii.
  Also... why is the time correct in one format, but not in the other format?</p>
  
  <p><hr><br></p>
  
  <h1>Additional info</h1>
  
  <p>I ran some more tests using additional MQL4 functions. I had them constantly pump out their results to my text file. I then quickly whipped together a BASH script to check out the results. I found the following:</p>
  
  <p>Using this code in MT4</p>
  
  <pre><code>FileWrite(data_filehandle, "TimeDaylightSavings(): " + (string)TimeDaylightSavings());
  FileWrite(data_filehandle,"TimeLocal(): "+(string)TimeLocal());
  FileWrite(data_filehandle,"TimeGMTOffset(): "+(string)TimeGMTOffset());
  FileWrite(data_filehandle,"TimeGMT(): "+(string)TimeGMT()+"\n\n");
  </code></pre>
  
  <p>Gave this output to my text file ( one fresh record about every second ):</p>
  
  <pre><code>TimeDaylightSavings(): 0
  TimeLocal(): 1579601184
  TimeGMTOffset(): 18000
  TimeGMT(): 1579619184
  </code></pre>
  
  <p>I whipped up this BASH script to scan and check the results in real time:</p>
  
  <pre><code>#!/bin/bash
  
  IFS=$'\n'$'\b';
  
  while true
  do
          my_time=$(date);
          my_epoc=$(date '+%s');
          my_record="$( cat EURUSD_price_data.txt| dos2unix | tail -5 )";
  
  
          mt4_time_local=$( echo "$my_record" | grep -w 'TimeLocal' );
          echo "Reading line: $mt4_time_local";
          mt4_time_local=$(echo $mt4_time_local | awk '{print $2}' );
  
          echo "My time: $my_time  -- My epoc: $my_epoc -- MT4_TimeLocal epoc: $mt4_time_local -- Difference: $(( $my_epoc - $mt4_time_local ))";
  
          mt4_time_GMT=$( echo "$my_record" | grep -w 'TimeGMT' );
          echo "Reading line: $mt4_time_GMT";
          mt4_time_GMT=$(echo $mt4_time_GMT | awk '{print $2}' );
          echo "My time: $my_time  -- My epoc: $my_epoc -- MT4_TimeGMT epoc: $mt4_time_GMT -- Difference: $(( $my_epoc - $mt4_time_GMT ))";
  
  
          echo "";
          sleep 1;
  done
  </code></pre>
  
  <p>and got this result:</p>
  
  <pre><code>Reading line: TimeLocal(): 1579601184
  My time: Tue Jan 21 10:06:25 EST 2020  -- My epoc: 1579619185 -- MT4_TimeLocal epoc: 1579601184 -- Difference: 18001
  Reading line: TimeGMT(): 1579619184
  My time: Tue Jan 21 10:06:25 EST 2020  -- My epoc: 1579619185 -- MT4_TimeGMT epoc: 1579619184 -- Difference: 1
  
  </code></pre>
  
  <p>Now if I add '#property strict' to switch back to Date Time format I get:</p>
  
  <pre><code>TimeDaylightSavings(): 0
  TimeLocal(): 2020.01.21 10:23:56
  TimeGMTOffset(): 18000
  TimeGMT(): 2020.01.21 15:23:56
  
  </code></pre>
  
  <p>My system time:</p>
  
  <pre><code>$ date
  Tue Jan 21 10:23:57 EST 2020
  </code></pre>
  
  <p><hr><br></p>
  
  <h1>Conclusion</h1>
  
  <p>For some reason when getting epoc time TimeLocal() gives the wrong time (Hawaiian time for some reason ) , but surprisingly TimeGMT() gives the correct time, even though I am in the EST timezone.</p>
  
  <p>Using the exact same code and set up, when getting the time in Date Time format ( using the '#property strict' directive ) the situation is reversed. TimeLocal() gives the correct time and TimeGMT() gives the wrong time ( but at least it gives correct GMT time )</p>
  
  <p>Is this a bug in MT4, or is there something going on behind the scenes that I haven't fully understood yet?</p>