Wrong date getting inserted using CustomTicksAdd

 

Hi, 


I'm using websocket in mt5 to read ticks and inserting the same into a custom symbol using CustomTicksAdd function. Although I'm supplying correct datetime but looking at the tick history for all ticks the date being added is 1970.01.01 00:00:00.008. Due to this the chart candle is not getting updated. Looking at the code please suggest if I'm doing anything wrong or anything additional needs to be done.


datetime mqlTime = (datetime) (time+19800);
string symbol_name = getSymbolFromToken(instrument_token);
MqlTick last_tick[1];
last_tick[0].bid = finalLTP;
last_tick[0].ask = finalLTP;
last_tick[0].last = finalLTP;
last_tick[0].volume = 0;
last_tick[0].volume_real = 0;
last_tick[0].time = mqlTime;
int n = CustomTicksAdd(symbol_name+".ZD",last_tick);

where time is the epoch.


Thanks,

Anubhav

 

From CustomTickAdd() documentation :

CustomTicksAdd

The MqlTick structure has two fields with the time value: time (the tick time in seconds) and  time_msc (the tick time in milliseconds), which are counted from January 1, 1970. These fields in the added ticks are processed in the following order:

  1. If ticks[k].time_msc!=0, we use it to fill the ticks[k].time field, i.e. ticks[k].time=ticks[k].time_msc/1000 (integer division) is set for the tick
  2. If ticks[k].time_msc==0 and ticks[k].time!=0, time in milliseconds is obtained by multiplying by 1000, i.e. ticks[k].time_msc=ticks[k].time*1000
  3. If ticks[k].time_msc==0 and ticks[k].time==0, the current trade server time up to a millisecond as of the moment of CustomTicksAdd call is written to these fields.

From Language Basic, about variables initialization :

If a variable is not initialized explicitly, the value stored in this variable can be any. Implicit initialization is not used.