Jump to content
Medved Trader Forums

Trying to access Time of bar

Recommended Posts

  I see you  don't expose bar time in the simple  editor ( as far as I can tell)  , so I'm trying to get the  TIMESTAMP variable to work , but not being a C programmer, and there being few examples here, I'm running into brick walls.


 I know this is simple.  Need to compare bar time to  a fixed time or range of times.  Don't need date.

Link to comment
Share on other sites

It would have to be done in Advanced mode. The variable is Timestamp, and it is a UTC DateTime of the beginning of the current candle.

There are also session variables that are also DateTime. You do a GetTradingSessionInfo call, which would return a TradingSessionInfo structure.


So - this is how you would check if you're half an hour or more into current session:


var SessionInfo = GetTradingSessionInfo(Timestamp);

if (Timestamp>SessionInfo.SessionStart.AddMinutes(30) && Timestamp<SessionInfo.SessionEnd)


   // do something







Link to comment
Share on other sites

  Right, I knew I needed advanced.

  I'm confused as to the format of how to compare timestamp to a specific time of day.

 IF (timestamp  > 9:00 )

  do something


I tried something that and was getting errors but not enough info to know what was wrong. 







Link to comment
Share on other sites

As I said, the Timestamp is a UTC time. Which means that with daylight savings time, it floats, sometimes one hour up, sometimes one hour down.


The easiest thing is to compare it to the session parameters as I showed.


You can compare to absolute, would have to be something like


    if (Timestamp.TimeOfDay > new TimeSpan(9-5, 0, 0))  // since 5 hours is the current difference between UTC and CST. Adjust it as you like for other time zones
        ; // do something

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...