Login Page - Create Account

Support Board


Date/Time: Tue, 10 Jun 2025 22:09:05 +0000



Custom study does not calculate properly during chart reload

View Count: 460

[2022-11-11 01:07:53]
dwfleener - Posts: 8
I created a custom study that was working fine one moment and I didn't change anything and now it won't work properly. Now it seems when the chart is first loaded or recalculated (INSERT key) it doesn't invoke my custom study during recalculation but only fires it after it has been loaded so the custom Xs are mostly skipped and not drawn (only the new real-time candles has the potential for it to draw an X above or below a candle hence only after it does a full recalculation during chart loading). What can cause this? Here is the code for the custom study. It is based on Rob Hoffman's Inventory Retracement Bar (IRB) concept. I added the line "sc.AddMessageToLog("[!]", true);" to see that it isn't firing my custom study during chart reload.

SCSFExport scsf_IRB(SCStudyInterfaceRef sc) {

SCInputRef enabledInput = sc.Input[0];
SCInputRef retracementInput = sc.Input[1];
//SCInputRef enableRegimeInput = sc.Input[2];
SCInputRef regimeStudyInput = sc.Input[3];

SCSubgraphRef irbSubgraph = sc.Subgraph[0];
SCSubgraphRef revIrbSubgraph = sc.Subgraph[1];

if (sc.SetDefaults) {
sc.GraphName = "IRB";
sc.StudyDescription = "...";

sc.AutoLoop = false;

sc.FreeDLL = false;

sc.GraphRegion = 0;

enabledInput.Name = "Enabled";
enabledInput.SetYesNo(YES);

retracementInput.Name = "Retracement [in %]";
retracementInput.SetInt(45);
retracementInput.SetIntLimits(0, 100);

//enableRegimeInput.Name = "Enable Regime";
//enableRegimeInput.SetYesNo(YES);

regimeStudyInput.Name = "Regime Study";
regimeStudyInput.SetChartStudySubgraphValues(1, 1, 0);

irbSubgraph.Name = "IRB+";
irbSubgraph.PrimaryColor = RGB(255, 255, 255);
irbSubgraph.DrawStyle = DRAWSTYLE_X;

revIrbSubgraph.Name = "IRB-";
revIrbSubgraph.PrimaryColor = RGB(255, 255, 255);
revIrbSubgraph.DrawStyle = DRAWSTYLE_X;

return;
}

// at least this point on does not get invoked during chart recalculation

if (enabledInput.GetYesNo() == false)
return;

sc.AddMessageToLog("[!]", true); // this line was added to debug why it isn't firing my custom study during chart reload

auto const currentIndex = sc.Index; // [!] is it safe to have this const?

auto const currentOpen = sc.BaseDataIn[SC_OPEN][currentIndex];
auto const currentHigh = sc.BaseDataIn[SC_HIGH][currentIndex];
auto const currentLow = sc.BaseDataIn[SC_LOW][currentIndex];
auto const currentClose = sc.BaseDataIn[SC_LAST][currentIndex];

auto const currentOpenInTicks = sc.PriceValueToTicks(currentOpen);
auto const currentHighInTicks = sc.PriceValueToTicks(currentHigh);
auto const currentLowInTicks = sc.PriceValueToTicks(currentLow);
auto const currentCloseInTicks = sc.PriceValueToTicks(currentClose);

SCGraphData regimeStudyData;
sc.GetStudyArraysFromChartUsingID(regimeStudyInput.GetChartNumber(), regimeStudyInput.GetStudyID(), regimeStudyData);

SCFloatArrayRef regimeStudySubgraphArray = regimeStudyData[0];

if (regimeStudySubgraphArray.GetArraySize() == 0)
return;

auto refChartIndex = sc.GetNearestMatchForDateTimeIndex(regimeStudyInput.GetChartNumber(), currentIndex);
auto nearestRegimeSubgraphValue = regimeStudySubgraphArray[refChartIndex];

int64_t candleRangeInTicks = abs((int)currentHighInTicks - (int)currentLowInTicks);

auto c = retracementInput.GetInt() / 100.0;

auto irb = min(currentCloseInTicks, currentOpenInTicks) > ((candleRangeInTicks * c) + currentLowInTicks);
auto revIrb = max(currentCloseInTicks, currentOpenInTicks) < currentHighInTicks - (candleRangeInTicks * c);

if (irb && currentCloseInTicks > sc.PriceValueToTicks(nearestRegimeSubgraphValue)) {
irbSubgraph[currentIndex] = sc.TicksToPriceValue(currentLowInTicks);

return;
}

if (revIrb && currentCloseInTicks > sc.PriceValueToTicks(nearestRegimeSubgraphValue)) {
irbSubgraph[currentIndex] = sc.TicksToPriceValue(currentLowInTicks);

return;
}

if (irb && currentCloseInTicks < sc.PriceValueToTicks(nearestRegimeSubgraphValue)) {
revIrbSubgraph[currentIndex] = sc.TicksToPriceValue(currentHighInTicks);

return;
}

if (revIrb && currentCloseInTicks < sc.PriceValueToTicks(nearestRegimeSubgraphValue)) {
revIrbSubgraph[currentIndex] = sc.TicksToPriceValue(currentHighInTicks);

return;
}
}

Any help to resolve this odd behavior will be greatly appreciated.
Date Time Of Last Edit: 2022-11-11 01:16:44
[2022-11-11 15:22:31]
Sierra_Chart Engineering - Posts: 19884
First we want you to refer to:

Working with ACSIL Arrays and Understanding Looping: When the Study Function is Called

When a chart finishes loading data, all of the studies on that chart will be calculated. That will not fail.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2022-11-11 17:03:56]
dwfleener - Posts: 8
I somehow managed to set AutoLoop to false and that was the problem. Thanks.

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

Login

Login Page - Create Account