Bar Time in seconds

 

How can i get current bar's time in seconds

Comment(TimeGMT(),  " " ,   " " , TimeToString(iTime(NULL,0,0),TIME_DATE|TIME_SECONDS));

TimeGMT works fine but i want to get bar time in seconds

output


 

See: https://www.mql5.com/en/code/45287

Beside that:

long tSec = (long)TimeCurent();

gives you the seonds since 1.1.1970.

Dealing with time (2) functions
  • www.mql5.com
Calculate DST for USA, EUR, AUD and RUB and the offset time of the broker automatically from the 70's until 2030 - even in the Strategy Tester of MQ.
 
Carl Schreiber #:

See: https://www.mql5.com/en/code/45287

Beside that:

gives you the seonds since 1.1.1970.

I do not wish to use TimeCurrent() or TimeGMT() or TimeTradeServer()

I want bar time in seconds using iTime()

 
It doesn't matter what 'you want' find a solution of what is available. Even the open time of a bar in seconds is the amount of seconds since 1.1.1970 no matter whether you like and want it or not.
 
Arpit T:

How can i get current bar's time in seconds

TimeGMT works fine but i want to get bar time in seconds

output


the seconds of the day ? or seconds in general ? 

 
Lorentzos Roussos #:

the seconds of the day ? or seconds in general ? 

seconds in general

. same as output given by TimeGMT() as per screenshot i added, but using iTime
 
Arpit T #:

seconds in general

. same as output given by TimeGMT() as per screenshot i added, but using iTime

You can use the 

SymbolInfoInteger(_Symbol,SYMBOL_TIME)

, it returns the time of the last quote which is also part of the last bar.

Or

IntegerToString((long)iTime(_Symbol,_Period,0));

https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_integer

Unless you mean the time of the first tick of each bar , that needs some ninja stuff
If you are facing this in a tick processor then you need to :

  • flatten the time based on seconds based on the duration of each bar of that timeframe in seconds 
  • project a duration in seconds unto that flattened bar time 
  • if a tick matches or crosses that projected time you know a new bar started and you also have the first tick time of that bar (and in ms if the broker has it)
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Wouldn't iTime always give you 0 seconds if bars open directly on the minute/hour?

 
thank you all
 
Lorentzos Roussos #:
SymbolInfoInteger(_Symbol,SYMBOL_TIME)

 not sure why on a custom symbol its returning zero .

 
I think you should explain what your goal is. People could possibly give you a good creative solution if they understand your goal. If you wanted the live seconds since the last bar opened you could subtract iTime from TimeCurrent()