Login Page - Create Account

Support Board


Date/Time: Mon, 16 Jun 2025 08:41:41 +0000



How to plot only the current hourly open as dash on a 5min chart

View Count: 333

[2025-05-14 17:30:12]
User214239 - Posts: 35
I'm using the Period OHLC-Variable Period study to plot a Dash on a 5min chart, using Time Period Type Minutes, and Time Period Length 60, so that it plots a dash for the open of every 60 minute period. I don't want to see the dashes for the previous 60 minute periods though. I'd just like to see the dash for the current period. When I choose any of the Dash or Line Draw Styles for Open (SG1) it plots all of them, going all the way back on the chart. Is there a way either with this study, or with a different study, to have it only plot the current 60 minute period open on the chart and not all of the previous ones also? I tried using Line at Last Bar to Edge, which does get rid of all the other dashes, but the problem there is that I'd like to be able to see the dash plotted on the chart back to the beginning of the time period so I can track the price action above/below the line as it develops. I appreciate the help.
[2025-05-14 17:51:23]
John - SC Support - Posts: 40422
Use the following formula in a "Spreadsheet Formula" study to display the Open from the OHLC Variable Period for just the current hour. You can hide the OHLC Variable Period study once you have this setup.
=IF(INT(BARTIME * 24) = INT(FRACTIME(NOW()) * 24), ID1.SG1, 0)

Where ID1 is the ID of the OHLC Variable Period study and SG1 is the Open subgraph of that study.

Make sure you set the Input for "Draw Zeros" in the Spreadsheet Formula to "No".

Refer to the following:
Spreadsheet Formula
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-05-14 18:31:23]
User214239 - Posts: 35
Oh my god you're my hero. I've been trying for so long to figure this out before bugging you guys. Thank you so much. I have one follow up question if you don't mind. I'm trying to do the same thing, but with another line for the 240 minute period open (4 hour). I set up a second Period OHLC-Variable Period study set to 240 minutes, and I assumed that I'd change the 24 in the formula to 6 to divide the day into 4 hour periods, and that does seem to work I think since the period just changed as I'm writing this and it looks correct, but for some reason it's giving me a second line on the chart also that is the open of the previous 4 hour candle. I think it has to do with the Number of Bars to Calculate setting in the Spreadsheet formula. For the 60 min version from my first question I had set that number to 60 with the idea that if I went down to a 1min timeframe on this chart it would be covering the time period. With that idea I then set the number of bars to calculate for the 240 minute version to 240, but when I do that the second line appears. If I move it back down to 60 its fine for now, but I'm not sure if that's the correct way to do it, or if it's going to give me a problem after the next hour for example. Am I doing that correct with the way I changed the 24 to a 6 in the formula, or is there something I'm missing/doing wrong? Sorry if its a stupid question and I really appreciate the help.
Date Time Of Last Edit: 2025-05-14 18:47:42
[2025-05-14 19:18:48]
User214239 - Posts: 35
Just a quick follow up since we just changed over to a new hour. The original one for the 60 minute time period is working fine regardless of what timeframe I test the chart on (1m, 5m, 15m, 30m). It also doesn't seem to matter what I have the Number of Bars to Calculate setting set at (currently 60), it only is drawing a dash for the current 60 min period open Like I wanted. That's working perfect as far as I can tell.

So the issue is my experiment to have a second line for the 240 min period. We just had a new hour (3:00 ET) and the dash is plotting the 4 hour candle open that happened at 2:00ET, but the dash on the chart is only going back to the current hour start at 3:00. It's not going back to the actual 240 min period open at 2:00, so I'm assuming I did something wrong with the formula. Also, that second line is now gone. Oh and it doesn't matter what I'm putting the Number of Bars to Calculate setting at (tried both 60 and 240).

I know help writing formulas are probably a bit outside of your scope of support so I sincerely appreciate any help you can give me. I tried to ChatGPT it first before bugging you again, but that failed miserably. Thank you so much.
Date Time Of Last Edit: 2025-05-14 19:21:54
[2025-05-14 20:51:48]
John - SC Support - Posts: 40422
The idea of changing the 24 to 6 is a good thought, but not what you need to do.

Keep in mind how Sierra Chart (and most computers) keep track of time. A quick overview of how Sierra Chart in particular does it, is available here:
Spreadsheet Functions: Serial DateTime Values

Therefore, the formula we gave you is looking at the current hour and if the bar time matches that hour, then it displays the value, otherwise it does not. Therefore, you need to find a way to show the data for the previous 4 hours. The general idea would be to see if the current bar has an hour that is greater than or equal to the hour 4 hours ago.

We leave you with that to ruminate on and see if you can come up with the solution. The main part of this is relatively straightforward (well, for a programmer type), but what would be difficult is what to do when it is 1 or 2 in the morning, so you are dealing with resetting the time from 24 to 01 or 02. But you may not need to deal with that if you are never looking at data at that time.

If you work on this and can not come up with the solution, let us know. We will help you get to it. We just believe in the idea of "Give a person a fish and he eats for a day; teach a person to fish and they eat for a lifetime."
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[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
imagePlot Open ES.jpg / V - Attached On 2025-05-15 18:10:43 UTC - Size: 266.36 KB - 85 views

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

Login

Login Page - Create Account