Login Page - Create Account

Support Board


Date/Time: Sat, 11 Jan 2025 23:43:20 +0000



ACSIL Round Numbers

View Count: 1424

[2017-01-03 16:06:15]
Entropy - Posts: 36
I have the following code that seems initially to work as it draws a line at the round number. However it very soon goes haywire and I cannot understand why.

/*==========================================================================
  Displays Round Numbers
==========================================================================*/
SCSFExport scsf_RoundNumbers(SCStudyInterfaceRef sc)
{  
  SCInputRef Increment = sc.Input[0];
  
  const int NumberOfLines = 20;

  if (sc.SetDefaults)
  {
    sc.GraphName = "Round Numbers";
    sc.GraphRegion = 0;
    sc.ValueFormat = 3;
    sc.AutoLoop = 1;
    sc.DisplayStudyInputValues = false;

    for (int i = 0; i < NumberOfLines; i++)  {
      sc.Subgraph[i].Name.Format("Line%d", i + 1);
      sc.Subgraph[i].DrawStyle = DRAWSTYLE_IGNORE;
      sc.Subgraph[i].PrimaryColor = RGB(105,105,105);
      sc.Subgraph[i].DrawZeros = true;
      sc.Subgraph[i].LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_CENTER | LL_VALUE_ALIGN_VALUES_SCALE;
    }
    
    // Set the increment and default it to 500
    Increment.Name = "Incremental Distance";
    Increment.SetInt(500);
    Increment.SetIntLimits(10,10000);
    Increment.SetDescription("Distance in increments between round numbers");

    sc.FreeDLL = 1;

    return;
  }
  
  float High, Low;
  int HighPrice, LowPrice;
  sc.GetMainGraphVisibleHighAndLow(High,Low);
  HighPrice = High / sc.TickSize;
  LowPrice = Low / sc.TickSize;
  int trueNumLines = (HighPrice - LowPrice) / Increment.GetInt();
  std::vector<double> RNums(NumberOfLines);
  
  int x = 0;
  for (int idx = LowPrice; idx <= HighPrice; idx++) {
    if (fmod(idx, Increment.GetInt()) == 0) RNums[x] = idx * sc.TickSize, x++;
    if (x == NumberOfLines) break;
  }
  
  for (int SubgraphIndex = 0; SubgraphIndex < trueNumLines; SubgraphIndex++) {
    sc.Subgraph[SubgraphIndex][sc.Index] = RNums[SubgraphIndex];
    sc.Subgraph[SubgraphIndex].DrawStyle = DRAWSTYLE_LINE;
  }
}

Could anyone have a look at this code and tell me what I am doing wrong. I just want to draw horizontal lines at round number levels.

Cheers,
Fred
[2017-01-04 18:52:17]
Entropy - Posts: 36
OK, I figured it out. One question however: When using sc.GetMainGraphVisibleHighAndLow() the function doesn't recalculate the round numbers when zooming in or out, why is that? Shouldn't it?
[2017-01-04 19:01:53]
Sierra Chart Engineering - Posts: 104368
Zooming in or out does not cause studies to be calculated and the study functions to be called.

This is the reason for why you see what you do.

Refer to:
http://www.sierrachart.com/index.php?page=doc/ACS_ArraysAndLooping.html#WhenFunctionCalled
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-01-04 19:03:02
[2017-01-05 08:50:48]
Entropy - Posts: 36
OK, that make sense. I have recoded the function so it now takes zooming in and out into regard

Cheers,
Fred

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

Login

Login Page - Create Account