Login Page - Create Account

Support Board


Date/Time: Tue, 22 Apr 2025 18:08:44 +0000



[User Discussion] - Ignore current day OHLC but show all previous days

View Count: 903

[2019-10-06 10:20:52]
grantx - Posts: 244
Daily OHLC study.
Is there an option to ignore todays developing OHLC levels and only show previous days? I have extension lines on the chart where I anticipate price might go to but seeing a line for the still-developing high and low can be very distracting.

In the uploaded screenshot you can see prior h/l levels. How do I disable the current day?
http://www.sierrachart.com/image.php?Image=1570357057544.png
[2025-01-04 10:50:38]
User676363 - Posts: 82
Copilot is now free and can be used to help with modifications of code.
Google's Gemini Code Assist is also helpful.

I will have to come back to this later to test it, but when I asked Copilot about the OHLC study code, "Can this study be used to show the prior 3 days of highs and lows, extended forward in time while ignoring the current day and days prior to the three days before today?"

It responds:

The current implementation of the scsf_StudyOverlayOHLC function does not directly support showing the prior 3 days of highs and lows extended forward in time while ignoring the current day and days prior to the three days before today. However, you can modify the function to achieve this behavior.

Here is a modified version of the function to show the prior 3 days of highs and lows, extended forward in time while ignoring the current day and days prior to the three days before today:

/*==========================================================================*/
SCSFExport scsf_StudyOverlayOHLC(SCStudyInterfaceRef sc)
{
SCSubgraphRef Subgraph_Open = sc.Subgraph[0];
SCSubgraphRef Subgraph_High = sc.Subgraph[1];
SCSubgraphRef Subgraph_Low = sc.Subgraph[2];
SCSubgraphRef Subgraph_Last = sc.Subgraph[3];
SCSubgraphRef Subgraph_OHLCAvg = sc.Subgraph[6];
SCSubgraphRef Subgraph_HLCAvg = sc.Subgraph[7];
SCSubgraphRef Subgraph_HLAvg = sc.Subgraph[8];

SCInputRef Input_UseZeroValuesFromSource = sc.Input[0];
SCInputRef Input_Multiplier = sc.Input[3];
SCInputRef Input_ChartStudySubgraphReference = sc.Input[4];
SCInputRef Input_Version = sc.Input[5];
SCInputRef Input_DrawZeros = sc.Input[6];
SCInputRef Input_UseStandardOHLCSubgraphsFromSourceStudy = sc.Input[7];

if (sc.SetDefaults)
{
sc.GraphName = "Study Overlay - OHLC";

sc.ValueFormat = 3;
sc.GraphRegion = 1;
sc.GraphDrawType = GDT_OHLCBAR;

sc.AutoLoop = 0;

Subgraph_Open.Name = "Open";
Subgraph_Open.DrawStyle = DRAWSTYLE_LINE;
Subgraph_Open.PrimaryColor = RGB(0,255,0);
Subgraph_Open.SecondaryColor = RGB(0,255,0);
Subgraph_Open.SecondaryColorUsed = 1;
Subgraph_Open.DrawZeros = false;
Subgraph_Open.LineWidth = 1;

Subgraph_High.Name = "High";
Subgraph_High.DrawStyle = DRAWSTYLE_LINE;
Subgraph_High.PrimaryColor = RGB(128,255,128);
Subgraph_High.DrawZeros = false;
Subgraph_High.LineWidth = 1;

Subgraph_Low.Name = "Low";
Subgraph_Low.DrawStyle = DRAWSTYLE_LINE;
Subgraph_Low.PrimaryColor = RGB(255,0,0);
Subgraph_Low.SecondaryColor = RGB(255,0,0);
Subgraph_Low.SecondaryColorUsed = 1;
Subgraph_Low.DrawZeros = false;
Subgraph_Low.LineWidth = 1;

Subgraph_Last.Name = "Last";
Subgraph_Last.DrawStyle = DRAWSTYLE_LINE;
Subgraph_Last.PrimaryColor = RGB(255,128,128);
Subgraph_Last.DrawZeros = false;
Subgraph_Last.LineWidth = 1;

Subgraph_OHLCAvg.Name = "OHLC Avg";
Subgraph_OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_OHLCAvg.PrimaryColor = RGB(127,0,255);
Subgraph_OHLCAvg.DrawZeros = false;

Subgraph_HLCAvg.Name = "HLC Avg";
Subgraph_HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_HLCAvg.PrimaryColor = RGB(0,255,255);
Subgraph_HLCAvg.DrawZeros = false;

Subgraph_HLAvg.Name = "HL Avg";
Subgraph_HLAvg.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_HLAvg.PrimaryColor = RGB(0,127,255);
Subgraph_HLAvg.DrawZeros = false;

Input_UseZeroValuesFromSource.Name = "Use Zero Values from Source Study";
Input_UseZeroValuesFromSource.SetYesNo(false);

Input_Multiplier.Name = "Multiplier";
Input_Multiplier.SetFloat(1.0f);

Input_ChartStudySubgraphReference.Name = "Chart, Study, Subgraph Reference";
Input_ChartStudySubgraphReference.SetChartStudySubgraphValues(1,1,0);

Input_Version.SetInt(1);

Input_DrawZeros.Name = "Draw Zero Values";
Input_DrawZeros.SetYesNo(false);

Input_UseStandardOHLCSubgraphsFromSourceStudy.Name = "Use Standard OHLC Subgraphs from Source Study";
Input_UseStandardOHLCSubgraphsFromSourceStudy.SetYesNo(false);

return;
}

if (Input_DrawZeros.GetYesNo())
{
Subgraph_Open.DrawZeros = true;
Subgraph_High.DrawZeros = true;
Subgraph_Low.DrawZeros = true;
Subgraph_Last.DrawZeros = true;
Subgraph_OHLCAvg.DrawZeros = true;
Subgraph_HLCAvg.DrawZeros = true;
Subgraph_HLAvg.DrawZeros = true;
}
else
{
Subgraph_Open.DrawZeros = false;
Subgraph_High.DrawZeros = false;
Subgraph_Low.DrawZeros = false;
Subgraph_Last.DrawZeros = false;
Subgraph_OHLCAvg.DrawZeros = false;
Subgraph_HLCAvg.DrawZeros = false;
Subgraph_HLAvg.DrawZeros = false;
}

int ChartNumber = Input_ChartStudySubgraphReference.GetChartNumber();
int StudyID = Input_ChartStudySubgraphReference.GetStudyID();
int StudySubgraphNumber = Input_ChartStudySubgraphReference.GetSubgraphIndex();

float MultiplierVal = Input_Multiplier.GetFloat();
if (MultiplierVal == 0.0f)
MultiplierVal = 1.0f;

SCDateTimeArray ReferenceChartDateTimeArray;
sc.GetChartDateTimeArray(ChartNumber, ReferenceChartDateTimeArray);
if (ReferenceChartDateTimeArray.GetArraySize() == 0)
return;

SCGraphData ReferenceArrays;
sc.GetStudyArraysFromChartUsingID(ChartNumber, StudyID, ReferenceArrays);

c_ArrayWrapper<float>* p_ReferenceOpen = NULL;
c_ArrayWrapper<float>* p_ReferenceHigh = NULL;
c_ArrayWrapper<float>* p_ReferenceLow = NULL;
c_ArrayWrapper<float>* p_ReferenceClose = NULL;

if (Input_UseStandardOHLCSubgraphsFromSourceStudy.GetYesNo())
{
p_ReferenceOpen = &ReferenceArrays[SC_OPEN];
p_ReferenceHigh = &ReferenceArrays[SC_HIGH];
p_ReferenceLow = &ReferenceArrays[SC_LOW];
p_ReferenceClose = &ReferenceArrays[SC_LAST];
}
else
{
p_ReferenceOpen = &ReferenceArrays[StudySubgraphNumber];
p_ReferenceHigh = &ReferenceArrays[StudySubgraphNumber];
p_ReferenceLow = &ReferenceArrays[StudySubgraphNumber];
p_ReferenceClose = &ReferenceArrays[StudySubgraphNumber];
}

SCFloatArrayRef ReferenceSubgraphArray = ReferenceArrays[StudySubgraphNumber];

if (Input_UseStandardOHLCSubgraphsFromSourceStudy.GetYesNo())
{
if (ReferenceArrays[SC_OPEN].GetArraySize() == 0
|| ReferenceArrays[SC_HIGH].GetArraySize() == 0
|| ReferenceArrays[SC_LOW].GetArraySize() == 0
|| ReferenceArrays[SC_LAST].GetArraySize() == 0
)
{
sc.AddMessageToLog("Study references a Study Subgraph that does not exist.", 1);
return;
}
}
else if (ReferenceSubgraphArray.GetArraySize() == 0)
{
sc.AddMessageToLog("Study references a Study Subgraph that does not exist.", 1);
return;
}

if (sc.UpdateStartIndex == 0)
{
SCString StudyName = sc.GetStudyNameFromChart(ChartNumber, StudyID);
if (ChartNumber == sc.ChartNumber && StudyID == sc.StudyGraphInstanceID)
StudyName = "Self";

sc.GraphName.Format("Overlay OHLC of %s", StudyName.GetChars());

//Zero all output values at all chart bars
for (int Index = 0; Index < sc.ArraySize; Index++)
{
Subgraph_Open[Index] = 0.0f;
Subgraph_High[Index] = 0.0f;
Subgraph_Low[Index] = 0.0f;
Subgraph_Last[Index] = 0.0f;
sc.CalculateOHLCAverages(Index);
}
}

int RefDataStartIndex = sc.GetStudyDataStartIndexFromChartUsingID(ChartNumber, StudyID);

sc.DataStartIndex =
sc.GetContainingIndexForSCDateTime(sc.ChartNumber, ReferenceChartDateTimeArray[RefDataStartIndex].GetAsDouble());

int ArraySize = sc.BaseDateTimeIn.GetArraySize();
int RefArraySize = ReferenceChartDateTimeArray.GetArraySize();

int RefIndex = 0;
int StudyStartIndex = max(sc.DataStartIndex, sc.UpdateStartIndex - 1);

// Find the appropriate reference index
RefIndex = sc.GetContainingIndexForSCDateTime(ChartNumber, sc.BaseDateTimeIn[StudyStartIndex].GetAsDouble());

// If no exact match is found, IndexForDateTime returns index right before the specified date and time
if (sc.BaseDateTimeIn[StudyStartIndex] > ReferenceChartDateTimeArray[RefIndex])
{
RefIndex++;
}

if (RefIndex >= RefArraySize || StudyStartIndex >= ArraySize)
return;

int StartingPoint = StudyStartIndex; // for CalculateAverages afterwards

float OpenVal = (*p_ReferenceOpen)[RefIndex];
float HighVal = (*p_ReferenceHigh)[RefIndex];
float LowVal = (*p_ReferenceLow)[RefIndex];
float CloseVal = (*p_ReferenceClose)[RefIndex];

// Calculate the date range for the prior 3 days
SCDateTime CurrentDate = sc.BaseDateTimeIn[ArraySize - 1].GetDate();
SCDateTime StartDate = CurrentDate - SCDateTime::DAYS(3);
SCDateTime EndDate = CurrentDate - SCDateTime::DAYS(1);

for (int OutputArrayIndex = StudyStartIndex; OutputArrayIndex < ArraySize; OutputArrayIndex++)
{
SCDateTime CurrentBarDate = sc.BaseDateTimeIn[OutputArrayIndex].GetDate();

// Skip bars that are not within the prior 3 days
if (CurrentBarDate < StartDate || CurrentBarDate >= CurrentDate)
{
Subgraph_Open[OutputArrayIndex] = 0;
Subgraph_Last[OutputArrayIndex] = 0;
Subgraph_High[OutputArrayIndex] = 0;
Subgraph_Low[OutputArrayIndex] = 0;
continue;
}

// If DateTime is not contained, then skip. Most likely because referenced graph has a larger duration time period
if (OutputArrayIndex + 1 < ArraySize && sc.BaseDateTimeIn[OutputArrayIndex + 1] <= ReferenceChartDateTimeArray[RefIndex])
{
Subgraph_Open[OutputArrayIndex] = 0;
Subgraph_Last[OutputArrayIndex] = 0;
Subgraph_High[OutputArrayIndex] = 0;
Subgraph_Low[OutputArrayIndex] = 0;
continue;
}

SCDateTime NextIndexDateTime = SCDateTime::GetMaximumDate();

if(OutputArrayIndex + 1 < ArraySize)
{
NextIndexDateTime = sc.BaseDateTimeIn[OutputArrayIndex + 1];
}

// Increment RefIndex while Next BaseTime is greater than RefTime
while (NextIndexDateTime > ReferenceChartDateTimeArray[RefIndex])
{
if ((Input_UseZeroValuesFromSource.GetYesNo() || (*p_ReferenceHigh)[RefIndex] != 0.0f)
&& HighVal < (*p_ReferenceHigh)[RefIndex]
)
{
HighVal = (*p_ReferenceHigh)[RefIndex];
}
else if ((Input_UseZeroValuesFromSource.GetYesNo() || (*p_ReferenceLow)[RefIndex] != 0.0f)
&& LowVal > (*p_ReferenceLow)[RefIndex]
)
{
LowVal = (*p_ReferenceLow)[RefIndex];
}

if (Input_UseZeroValuesFromSource.GetYesNo() || (*p_ReferenceClose)[RefIndex] != 0.0f)
CloseVal = (*p_ReferenceClose)[RefIndex];

RefIndex++;

if (RefIndex >= RefArraySize)
break;
}

Subgraph_Open[OutputArrayIndex] = OpenVal * MultiplierVal;
Subgraph_Last[OutputArrayIndex] = CloseVal * MultiplierVal;
Subgraph_High[OutputArrayIndex] = HighVal * MultiplierVal;
Subgraph_Low[OutputArrayIndex] = LowVal * MultiplierVal;

sc.CalculateOHLCAverages(OutputArrayIndex);

if (RefIndex >= RefArraySize)
break;

OpenVal = (*p_ReferenceOpen)[RefIndex];
HighVal = (*p_ReferenceHigh)[RefIndex];
LowVal = (*p_ReferenceLow)[RefIndex];
CloseVal = (*p_ReferenceClose)[RefIndex];
}
}

This modified version of the function calculates the date range for the prior 3 days and skips bars that are not within this range. It then processes the data as usual, overlaying the OHLC values from the reference study onto the current chart. This should achieve the desired behavior of showing the prior 3 days of highs and lows extended forward in time while ignoring the current day and days prior to the three days before today.

Similar code found with 1 license type - View matches

# Code Citations

## License: unknown
https://github.com/ACSIL/ACS_Source/tree/96d5826b9c2dacb85b120e4fd598855ab900d198/defaults/Studies8.cpp

```
*==========================================================================*/
SCSFExport scsf_StudyOverlayOHLC(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_Open = sc.Subgraph[0];
  SCSubgraphRef Subgraph_High = sc.Subgraph[1];
  SCSubgraphRef Subgraph_Low = sc.Subgraph[2];
  SCSubgraphRef Subgraph_Last = sc.Subgraph[3];
  SCSubgraphRef Subgraph_OHLCAvg = sc
```


## License: unknown
https://github.com/ACSIL/ACS_Source/tree/96d5826b9c2dacb85b120e4fd598855ab900d198/defaults/Studies6.cpp

```
.Name = "OHLC Avg";
    Subgraph_OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_OHLCAvg.PrimaryColor = RGB(127,0,255);
    Subgraph_OHLCAvg.DrawZeros = false;

    Subgraph_HLCAvg.Name = "HLC Avg";
    Subgraph_HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_HLCAvg.PrimaryColor = RGB(0
```


## License: unknown
https://github.com/ACSIL/ACS_Source/tree/96d5826b9c2dacb85b120e4fd598855ab900d198/defaults/Studies3.cpp

```
;
    Subgraph_OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_OHLCAvg.PrimaryColor = RGB(127,0,255);
    Subgraph_OHLCAvg.DrawZeros = false;

    Subgraph_HLCAvg.Name = "HLC Avg";
    Subgraph_HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_HLCAvg.PrimaryColor = RGB(0,255,255);
    Subgraph_HLCAvg
```


## License: unknown
https://github.com/rcorral/sierra-chart-boilerplate/tree/7d16fef08dfe3864b76426e36fb251b8e591c5f0/ACS_Source/Studies8.cpp

```
.0f;

  SCDateTimeArray ReferenceChartDateTimeArray;
  sc.GetChartDateTimeArray(ChartNumber, ReferenceChartDateTimeArray);
  if (ReferenceChartDateTimeArray.GetArraySize() == 0)
    return;

  SCGraphData ReferenceArrays;
  sc.GetStudyArraysFromChartUsingID(ChartNumber, StudyID, ReferenceArrays);

  c_ArrayWrapper<float>* p_ReferenceOpen = NULL;
  c_ArrayWrapper<float>
```


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

Login

Login Page - Create Account