Support Board
Date/Time: Thu, 13 Feb 2025 16:22:07 +0000
Post From: sc.GetOHLCOfTimePeriod Help
[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
|