Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 04:46:56 +0000



[User Discussion] - sc.GetOHLCOfTimePeriod Help

View Count: 657

[2020-12-09 11:54:51]
User820318 - Posts: 40
I am trying to calculate the median price over a time window each day (on intraday chart) are draw that value as a level using a subgraph. I have tried using the
sc.GetOHLCOfTimePeriod()
function to get the High and Low over the interval to then pass to calculation of the median. Below is the code I am using. Unfortunately this simply returns a zero for OpenLevel subgraph. Can anyone point out what I am doing wrong here?
Thanks in advance for any help.

SCDLLName("MedPriceAtTime")

SCSFExport scsf_MedPriceAtTime(SCStudyInterfaceRef sc)
{
// Inputs
  SCInputRef Start = sc.Input[0];
  SCInputRef End = sc.Input[1];

  // Outputs
SCSubgraphRef OpenLevel = sc.Subgraph[0];

if (sc.SetDefaults) {
    
    sc.StudyVersion = 20201209;
sc.GraphName = "Median Price At Time";

sc.AutoLoop = 1; //Automatic looping is enabled.
sc.GraphRegion = 0;

OpenLevel.Name = "MedPrice";
OpenLevel.DrawStyle = DRAWSTYLE_DASH;
OpenLevel.PrimaryColor = RGB(255, 182, 193);
OpenLevel.DrawZeros = 0;
    OpenLevel.LineWidth = 2;
    OpenLevel.LineLabel = LL_DISPLAY_NAME | LL_NAME_ALIGN_CENTER | LL_NAME_ALIGN_FAR_RIGHT;

Start.Name = "Start Time";
Start.SetTime(HMS_TIME(5, 30, 0));
    
    End.Name = "End Time";
End.SetTime(HMS_TIME(7, 30, 0));

return;
}

// Section 2 - Do data processing here
  
  // Declare variables
  float OpenTP;
  float HighTP;
  float LowTP;
  float CloseTP;
  float NextOpenTP;
  
  SCDateTime StartTime = Start.GetTime();
  SCDateTime EndTime = End.GetTime();    

  // Get OHLC values over time period
  sc.GetOHLCOfTimePeriod(StartTime, EndTime, OpenTP, HighTP, LowTP, CloseTP, NextOpenTP) ;
  
  // calculate Median
OpenLevel[sc.Index] = (HighTP + LowTP) / 2;
  
}

Date Time Of Last Edit: 2020-12-09 13:19:10
[2020-12-09 14:57:01]
User907968 - Posts: 802

SCDateTime StartTime = Start.GetTime();
SCDateTime EndTime = End.GetTime();

Your SCDateTime variables have no date part set, only time.

You could try, for example -

SCDateTime StartTime = sc.BaseDateTimeIn[sc.Index];
StartTime.SetTime(Start.GetTime());

[2020-12-09 15:11:33]
User820318 - Posts: 40
Thank you for the suggestion. That worked. really appreciate it.

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

Login

Login Page - Create Account