Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 03:29:41 +0000



Post From: Labels display on right hand side of chart

[2023-12-03 14:05:46]
user08187 - Posts: 15
Hi,

Thanks for the "Horizontal Lines" study suggestion. As per your suggestion, I've coded a custom study similar to Horizontal lines study, but I have a few questions regarding that.


SCInputRef fileName = sc.Input[0];
  if (sc.SetDefaults)
  {
    sc.GraphName = "NamesAndValues";
    sc.StudyDescription = "Names And Values";

    sc.GraphRegion = 0;

    fileName.Name = "File Name";
    fileName.SetString("InFile.txt");
    sc.AutoLoop = 1;
    return;
  }


  // Section 2 - Do data processing here

  if (!sc.IsFullRecalculation)
    return;

  SCString fileNameString = fileName.GetString();
  if (fileNameString.IsEmpty())
  {
    return;
  }

  auto index = 0;
  const std::string delimiter = ",";
  std::ifstream input(fileNameString);
  for (std::string line; getline(input, line); ) {
    auto pos = line.find(delimiter);
    auto symbol = line.substr(0, pos);
    
    auto scSymbol = sc.Symbol.GetChars();
    if (strcmp(scSymbol,symbol.c_str()) == 0)
    {
      line = line.substr(pos+1);
      pos = line.find(delimiter);
      auto label = line.substr(0, pos);
      auto value = line.substr(pos + 1);
      sc.Subgraph[index].Name = label.c_str();
      sc.Subgraph[index][sc.Index] = stof(value);

      sc.Subgraph[index].DisplayNameValueInDataLine = 0;
      sc.Subgraph[index].DisplayNameValueInWindowsFlags = 0;
      sc.Subgraph[index].IncludeInStudySummary = 0;
      sc.Subgraph[index].DrawStyle = DRAWSTYLE_TRANSPARENT_TEXT;
      sc.Subgraph[index].LineLabel = LL_DISPLAY_NAME | LL_NAME_ALIGN_CENTER | LL_NAME_ALIGN_LEFT_EDGE;
      sc.Subgraph[index].UseLabelsColor = 1;
      sc.Subgraph[index].LabelsColor = RGB(255, 0, 0);
      index++;
    }
  }
  input.close();

my input file has lines like below
ESZ3.CME,Name1,4610
ESZ3.CME,Name2,4560

Questions(in the decreasing order of importance):
1. the custom study doesn't display Value on the price axis, like how "Horizontal Lines" display Value on the price axis(see the attached image). What needs to be added/changed in the code?
2. while the chart is loading, I wanted the study to be executed only once and not for each bars on the chart. But, if I put "sc.AutoLoop = 0", it's not displaying any Name Value pairs. What needs to be added/changed in the code?
3. In addition to being executed only once while loading, I wanted the study to be executed only when I wanted to recalculate. Is the code("if (!sc.IsFullRecalculation) return;") correct for that?
4. what needs to be added in the code, so that I don't want to display Custom Study Name, Subgraph Name and Value, Input Values, etc. in the Chart Values for tools, Top of Chart(i.e., after SYMBOL BARPERIOD ... ), etc.?

Thanks
imageSierraChart_CustomStudy_doubts.jpg / V - Attached On 2023-12-03 13:49:31 UTC - Size: 197.14 KB - 87 views