Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 18:01:23 +0000



Post From: Study: Horizontal Lines At Increment (Round to Tick)

[2024-02-24 02:09:32]
User688525 - Posts: 257
Hello,
Can assistance please be provided to add "Round to Tick" functionality to the "Horizontal Lines At Increment" study?

I have added

SCInputRef Input_RoundToTickSize = sc.Input[3];

and

Input_RoundToTickSize.Name = "Round To Nearest Tick Size";
Input_RoundToTickSize.SetYesNo(0);

to the "Horizontal Lines At Increment" code in "Studies7.cpp":


#include "sierrachart.h"
SCDLLName("Horizontal Lines At Increment v2")

SCSFExport scsf_HorizontalLinesAtIncrementv2(SCStudyInterfaceRef sc)
{
  const int NumberOfLines = SC_SUBGRAPHS_AVAILABLE - 1;

  SCInputRef Input_StartValue = sc.Input[0];
  SCInputRef Input_LineIncrement = sc.Input[1];
  SCInputRef Input_SetAllSubgraphsToBeSameAsFirst = sc.Input[2];
  SCInputRef Input_RoundToTickSize = sc.Input[3];


  if (sc.SetDefaults)
  {
    sc.GraphName = "Horizontal Lines At Increment v2";

    sc.ValueFormat = VALUEFORMAT_INHERITED;
    sc.DisplayStudyInputValues = false;
    sc.ScaleRangeType = SCALE_SAMEASREGION;
    sc.GraphRegion = 0;

    for (int SubgraphIndex = 0; SubgraphIndex < NumberOfLines; SubgraphIndex++)
    {
      sc.Subgraph[SubgraphIndex].Name.Format("Line%d", SubgraphIndex + 1);
      sc.Subgraph[SubgraphIndex].DrawStyle = DRAWSTYLE_LINE;
      sc.Subgraph[SubgraphIndex].PrimaryColor = RGB(0,255,0);
      sc.Subgraph[SubgraphIndex].DrawZeros = false;
      sc.Subgraph[SubgraphIndex].DisplayNameValueInWindowsFlags = false;
        
    }
    
    Input_SetAllSubgraphsToBeSameAsFirst.Name = "Set All Subgraph Display Settings to Be Same as First";
    Input_SetAllSubgraphsToBeSameAsFirst.SetYesNo(false);

    Input_StartValue.Name = "Start Value";
    Input_StartValue.SetFloat(0);

    Input_LineIncrement.Name = "Line Increment";
    Input_LineIncrement.SetFloat(1);

    Input_RoundToTickSize.Name = "Round To Nearest Tick Size";
    Input_RoundToTickSize.SetYesNo(0);

    return;
  }

  for(int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++)
  {
    float CurrentLineValue = Input_StartValue.GetFloat();

    for (int SubgraphIndex = 0; SubgraphIndex < NumberOfLines; SubgraphIndex++)
    {
      if (sc.Subgraph[SubgraphIndex].DrawStyle == DRAWSTYLE_IGNORE)
        continue;

      if (sc.IsFullRecalculation
        && BarIndex == 0
        && Input_SetAllSubgraphsToBeSameAsFirst.GetYesNo()
        && SubgraphIndex > 0)
      {
        sc.Subgraph[SubgraphIndex].DrawStyle = sc.Subgraph[0].DrawStyle;
        sc.Subgraph[SubgraphIndex].PrimaryColor = sc.Subgraph[0].PrimaryColor;
        sc.Subgraph[SubgraphIndex].LineStyle = sc.Subgraph[0].LineStyle;
        sc.Subgraph[SubgraphIndex].LineWidth = sc.Subgraph[0].LineWidth;
        sc.Subgraph[SubgraphIndex].LineLabel = sc.Subgraph[0].LineLabel;
      }

      sc.Subgraph[SubgraphIndex][BarIndex] = CurrentLineValue;

      CurrentLineValue += Input_LineIncrement.GetFloat();
    }

  }

Thank you