Login Page - Create Account

Support Board


Date/Time: Sun, 12 Jan 2025 00:00:14 +0000



Post From: ACSIL Round Numbers

[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