Jump to content
Medved Trader Forums
Sign in to follow this  
stock777

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.

Share this post


Link to post
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

}

 

 

 

 

 

Share this post


Link to post
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. 

 

 

 

 

 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×