Login Page - Create Account

Support Board


Date/Time: Wed, 24 Apr 2024 10:01:38 +0000



[Programming Help] - How to set the time for the past 10 minutes to use sc.GetOHLCOfTimePeriod

View Count: 551

[2019-10-18 11:00:58]
User704508 - Posts: 20
Hi!

I'm trying to use the sc.GetOHLCOfTimePeriod function but am struggling with the dates. I tried using SetDateTimeYMDHMS, BaseDateTimeIn, SetTime but can't figure it out.

My goal: getting the current time and the current time minus 10 minutes to get the highest point and lowest point of the past 10 minutes.

Thank you in advance.

Here is what I got so far:

float& Open = sc.GetPersistentFloat(6);
  float& High = sc.GetPersistentFloat(7);
  float& Low = sc.GetPersistentFloat(8);
  float& Close = sc.GetPersistentFloat(9);
  float& NextOpen = sc.GetPersistentFloat(10);
  
  int Day = sc.BaseDateTimeIn[sc.Index].GetDay();
  int Hour = sc.BaseDateTimeIn[sc.Index].GetHour();
  int Minute = sc.BaseDateTimeIn[sc.Index].GetMinute();
  int MinuteMinus = sc.BaseDateTimeIn[sc.Index-10].GetMinute();
  int Month = sc.BaseDateTimeIn[sc.Index].GetMonth();
  int Year = sc.BaseDateTimeIn[sc.Index].GetYear();
  
  SCDateTime startDateTime;
  SCDateTime endDateTime;
  startDateTime.SetDateTimeYMDHMS(Year, Month, Day, Hour, MinuteMinus, 0);
  endDateTime.SetDateTimeYMDHMS(Year, Month, Day, Hour, Minute, 0);
  startDateTime.SetTime(startDateTime);
  endDateTime.SetTime(endDateTime);
  
  sc.GetOHLCOfTimePeriod(startDateTime, endDateTime, Open, High, Low, Close, NextOpen);

[2019-10-18 12:33:41]
User907968 - Posts: 802
You can simplify quite a lot


enddatetime = sc.BaseDateTimeIn[sc.Index];
startdatetime = enddatetime - (10 * MINUTES);

or if your chart is a time based and the period is a divisor of 10, and you only want the high and low, you could also use these functions -
sc.GetHighest()
sc.GetLowest()
[2019-10-18 12:42:24]
User704508 - Posts: 20
Thank you so much!

I don't know why I tried to complicate it.

And thanks for the tip on the GetHighest function, I didn't know it existed.

Best,
Matt

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

Login

Login Page - Create Account