Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 23:37:01 +0000



[Programming Help] - How to compare sc.BaseDateTimeIn[sc.Index].GetTime() with s_ChartSessionTimes.StartTime

View Count: 252

[2023-06-20 20:18:42]
emmanuel - Posts: 58
I'm having difficulty comparing the "bar time" with the chart session times in order to have my trading system only trade within the session time:


n_ACSIL::s_ChartSessionTimes SessionTimes;
sc.GetSessionTimesFromChart(sc.ChartNumber, SessionTimes);
int BarTime = sc.BaseDateTimeIn[sc.Index].GetTime();

SCString FormattedMessage;
sc.AddMessageToLog(FormattedMessage.Format("BarTime %i, StartTime %i, EndTime %i", BarTime, SessionTimes.StartTime, SessionTimes.EndTime), 0);

if(BarTime < SessionTimes.StartTime || BarTime >= SessionTimes.EndTime) return;

In the message log I see entries such as...

Chart: ESM23-CME[M] 1 Min #1 | Study: ***: BarTime 30540, StartTime 1156760, EndTime 1156848 | 2023-06-20 19:46:53.560

So it looks like the time representation between
sc.BaseDateTimeIn[sc.Index].GetTime()
and
s_ChartSessionTimes.StartTime
is different, though they are the same data type. How can I compare these values?
[2023-06-21 12:23:38]
emmanuel - Posts: 58
I figured it out:

n_ACSIL::s_ChartSessionTimes SessionTimes;
sc.GetSessionTimesFromChart(sc.ChartNumber, SessionTimes);
int BarTime = sc.BaseDateTimeIn[sc.Index].GetTime();
int StartTime = SessionTimes.StartTime.GetTime();
int EndTime = SessionTimes.EndTime.GetTime();

if(BarTime < StartTime || BarTime >= EndTime) return;

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account