Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 12:09:46 +0000



[Programming Help] - Slow loading Study that retrieves an external subgraph array

View Count: 183

[2024-06-04 19:33:03]
ycomp - Posts: 317
this is not my full code, but it is the important part that shows what I'm trying to do.

On autoloop it works fine (but very slow loading)

with Autoloop off, it only paints bars going forward


// Section 1 - Set the configuration variables and defaults
  if (sc.SetDefaults)
  {
    sc.AutoLoop = 0; //Automatic looping is disabled.

Subgraph_External.Name = "External Subgraph";
    Subgraph_External.LineWidth = 1;
    Subgraph_External.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_External.PrimaryColor = COLOR_DODGERBLUE;
    Subgraph_External.SecondaryColorUsed = false;
    Subgraph_External.DisplayNameValueInWindowsFlags = 1;

// External Study Subgraph
Input_UseExternalStudy.Name = "Use External Study Subgraph for the comparison value? (no=use Moving Average)";
Input_UseExternalStudy.SetYesNo(true);

Input_SubgraphRef.Name = "External Study Subgraph Reference";
    Input_SubgraphRef.SetStudySubgraphValues(0, 0);

    return;
  }
  
/*** Actual Processing ***/

const int BarIndex = sc.AutoLoop ? sc.Index : sc.ArraySize - 1;

double value;
if (Input_UseExternalStudy.GetYesNo()) {
// Retrieve the external study subgraph array
sc.GetStudyArrayUsingID(Input_SubgraphRef.GetStudyID(), Input_SubgraphRef.GetSubgraphIndex(), Subgraph_External.Data);
value = Subgraph_External[BarIndex];
}
else {
value = // alternate calculation without subgraph
}

if I try to add a for loop with autoloop off like from the docs


for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) {
int BarIndex = Index;
// double value and rest of code below it is in the loop now

then it will hang while drawing the chart.

1) How can I write this code with autoloop off so that it paints all bars?
2) How can I optimize the code so that it is not really slow loading? is there a better way than to retrieve the subgraph array every time?
[2024-06-06 21:17:29]
ycomp - Posts: 317
ok i figured it out.. the problem was that I was drawing text.. sc.AddAndManageSingleTextDrawingForStudy

this is ok with autoloop on

but autoloop 0 with a for loop, it hangs sierra at least for me.

so I do this in the for loop and it is fast now

if (BarIndex < sc.ArraySize-1) continue;

// text drawing stuff below

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

Login

Login Page - Create Account