Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 13:08:33 +0000



[Programming Help] - How to restart / recalc only one specific study on a chart - or do I simulate a restart?

View Count: 123

[2025-02-26 18:23:37]
JohnR - User831573 - Posts: 330
I have a study, that draws subgraphs on a chart drawing on bars are initiated by finding a specific drawn object type on a bar and it continues to draw until a condition is met. Basically it is a stop loss level. I add the drawn object to the desired bar and currently I press recalc. There are other reason I do not want all studies to recalc.

Can I capture a menu item and then set some sc.'variable' or execute some sc.'function' to accomplish what I am after?

If I need to simulate a recalc for this study based on menu item I create, How do I reset/initiate my 2 subgraphs for all bars, or what value do I place in each bar as I loop through them until last / current bar (sc.Index) ?

If I change an input on Study-A and press OK, it will recalc all studies on the chart.

I've been digging around the online docs

Below are areas I read/reread
sc.FlagFullRecalculate - to cause a full recalculation of all studies on a chart
sc.FlagToReloadChartData

All help, guidance and pointers to info is appreciated.

JohnR
[2025-02-26 18:41:20]
User431178 - Posts: 651
If you switch to manual looping, then something like below would work.
You are substituting 0 for sc.UpdateStartIndex only when you have triggered the recalculation.


auto& sg_1 = sc.Subgraph[0];
auto& sg_2 = sc.Subgraph[0];

// Set the recalc state via menu item or button
// configuredMenuItem would be set when first configuring / initializing the study
const auto recalc = sc.MenuEventID == configuredMenuItem && configuredMenuItem != 0;
const auto updateStartIndex = recalc ? 0 : sc.UpdateStartIndex;

for (auto i = updateStartIndex; i < sc.ArraySize; ++i)
{
  if (recalc)
  {
    sg_1[i] = 0;
    sg_2[i] = 0;
  }
  
  // Various other study code etc
}

[2025-02-26 19:32:57]
JohnR - User831573 - Posts: 330
Thanks much. I'll try it later tonight. I'm self taught C++ and ACSIL and not full time. Sooo I do fall in holes now and then.

Thanks again.

JohnR

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

Login

Login Page - Create Account