Support Board
Date/Time: Mon, 16 Jun 2025 09:13:08 +0000
Post From: How to plot only the current hourly open as dash on a 5min chart
[2025-05-15 00:18:37] |
cmet - Posts: 706 |
Here's a study that does what you want. You have to have the 60 minute (or any higher time frame) chart open. Has the option to use open from all bars or just the current one. #include "sierrachart.h"
SCDLLName("Plot HTF Open") SCSFExport scsf_PlotHTFOpen(SCStudyInterfaceRef sc) { SCSubgraphRef HTFOpenLine = sc.Subgraph[0]; SCInputRef Input_HTFChartNumber = sc.Input[0]; SCInputRef Input_PlotCurrentOnly = sc.Input[1]; if (sc.SetDefaults) { sc.GraphName = "Plot HTF Open"; sc.StudyDescription = "Plot HTF Open onto LTF chart"; sc.GraphRegion = 0; sc.ValueFormat = VALUEFORMAT_INHERITED; sc.AutoLoop = 0; HTFOpenLine.Name = "HTF Open"; HTFOpenLine.DrawStyle = DRAWSTYLE_DASH; HTFOpenLine.LineWidth = 2; HTFOpenLine.PrimaryColor = RGB(255, 255, 0); HTFOpenLine.DrawZeros = false; Input_HTFChartNumber.Name = "HTF Chart Number"; Input_HTFChartNumber.SetChartNumber(2); Input_PlotCurrentOnly.Name = "Plot Only Current Bar"; Input_PlotCurrentOnly.SetYesNo(1); return; } int HTFChartNum = Input_HTFChartNumber.GetChartNumber(); bool PlotCurrentOnly = Input_PlotCurrentOnly.GetYesNo(); SCDateTimeArray HTFTime; SCFloatArray HTFOpen; sc.GetChartDateTimeArray(HTFChartNum, HTFTime); sc.GetChartArray(HTFChartNum, SC_OPEN, HTFOpen); if (HTFTime.GetArraySize() == 0 || HTFOpen.GetArraySize() == 0) return; SCDateTime LTFNow = sc.BaseDateTimeIn[sc.ArraySize - 1]; int ActiveHTFIndex = -1; for (int j = HTFTime.GetArraySize() - 1; j >= 0; --j) { if (HTFTime[j] <= LTFNow) { ActiveHTFIndex = j; break; } } if (ActiveHTFIndex < 0 || ActiveHTFIndex >= HTFOpen.GetArraySize()) return; SCDateTime HTFStartTime = HTFTime[ActiveHTFIndex]; float HTFOpenValue = HTFOpen[ActiveHTFIndex]; for (int i = 0; i < sc.ArraySize; ++i) { SCDateTime LTFTime = sc.BaseDateTimeIn[i]; if (PlotCurrentOnly) { //current HTF open if (LTFTime >= HTFStartTime) HTFOpenLine[i] = HTFOpenValue; else HTFOpenLine[i] = 0; } else { //HTF open for each bar for (int j = HTFTime.GetArraySize() - 1; j >= 0; --j) { if (HTFTime[j] <= LTFTime) { HTFOpenLine[i] = HTFOpen[j]; break; } } } } } Date Time Of Last Edit: 2025-05-15 18:10:44
|
![]() |