Login Page - Create Account

Support Board


Date/Time: Fri, 31 Jan 2025 22:57:02 +0000



[Programming Help] - What is Version.SetInt(2)?

View Count: 877

[2019-06-04 09:21:13]
grantx - Posts: 244
What is the purpose of setting this reference? First, you manually set it and then immediately check it. This is from the 'HighLowForTimePeriod' study.

Version = sc.Input[2];


#include "sierrachart.h"
SCDLLName("Custom Study DLL2")
SCSFExport scsf_HighLowForTimePeriod(SCStudyInterfaceRef sc)
{
  SCSubgraphRef HighOfDay = sc.Subgraph[0];
  SCSubgraphRef LowOfDay = sc.Subgraph[1];

  SCFloatArrayRef TimeRangeHigh = sc.Subgraph[0].Arrays[0];
  SCFloatArrayRef TimeRangeLow = sc.Subgraph[0].Arrays[1];

  SCInputRef StartTime = sc.Input[0];
  SCInputRef EndTime = sc.Input[1];
  SCInputRef Version = sc.Input[2];
  SCInputRef InputDataHigh = sc.Input[3];
  SCInputRef InputDataLow = sc.Input[4];
  SCInputRef DisplayHighLowIncrementally = sc.Input[5];
  SCInputRef NumberDaysToCalculate = sc.Input[6];


  if (sc.SetDefaults)
  {
    sc.GraphName = "High/Low for Time Period";
    sc.GraphRegion = 0;
    sc.AutoLoop = 0;

    HighOfDay.Name = "High";
    HighOfDay.DrawStyle = DRAWSTYLE_DASH;
    HighOfDay.PrimaryColor = RGB(0, 255, 0);
    HighOfDay.DrawZeros = false;

    LowOfDay.Name = "Low";
    LowOfDay.DrawStyle = DRAWSTYLE_DASH;
    LowOfDay.PrimaryColor = RGB(255, 0, 255);
    LowOfDay.DrawZeros = false;

    StartTime.Name = "Start Time";
    StartTime.SetTime(0);

    EndTime.Name = "End Time";
    EndTime.SetTime(SECONDS_PER_DAY - 1);

    InputDataHigh.Name = "Input Data High";
    InputDataHigh.SetInputDataIndex(SC_HIGH);

    InputDataLow.Name = "Input Data Low";
    InputDataLow.SetInputDataIndex(SC_LOW);

    DisplayHighLowIncrementally.Name = "Display High Low Incrementally";
    DisplayHighLowIncrementally.SetYesNo(false);

    NumberDaysToCalculate.Name = "Number Of Days To Calculate";
    NumberDaysToCalculate.SetInt(10000);

    Version.SetInt(2);

    return;
  }

  if (Version.GetInt() < 2) //Why are you checking this? What does it mean?
  {
    InputDataHigh.SetInputDataIndex(SC_HIGH);
    InputDataLow.SetInputDataIndex(SC_LOW);
    Version.SetInt(2);
  }

  if (NumberDaysToCalculate.GetInt() <= 0)
    NumberDaysToCalculate.SetInt(10000);

  int InputDataHighIndex = InputDataHigh.GetInputDataIndex();
  int InputDataLowIndex = InputDataLow.GetInputDataIndex();

  SCDateTime InStartTime = StartTime.GetDateTime();
  SCDateTime InEndTime = EndTime.GetDateTime();

  for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++)
  {
    SCDateTime DaysToCalculateStartDateTime = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.ArraySize - 1]) - (NumberDaysToCalculate.GetInt() - 1);

    if (sc.BaseDateTimeIn[Index] < DaysToCalculateStartDateTime)
      continue;

    SCDateTime StartDateTime = 0;
    SCDateTime EndDateTime = 0;


    SCDateTime BarDate = sc.BaseDateTimeIn[Index].GetDate();
    if (InStartTime < InEndTime)
    {
      StartDateTime = BarDate + InStartTime;
      EndDateTime = BarDate + InEndTime;
    }
    //Times are reversed and the current time is greater than or equal to the start time
    else if (sc.BaseDateTimeIn[Index].GetTimeInSeconds() >= InStartTime.GetTimeInSeconds())
    {

      StartDateTime = BarDate + InStartTime;
      EndDateTime = BarDate + 1 + InEndTime;
    }
    //Times are reversed and the current time is less than or equal to the end time
    else if (sc.BaseDateTimeIn[Index].GetTimeInSeconds() <= InEndTime.GetTimeInSeconds())
    {

      StartDateTime = BarDate + InStartTime - 1;
      EndDateTime = BarDate + InEndTime;
    }

    //Initial calculations or start of new time range
    if (Index == 0 || sc.BaseDateTimeIn[Index - 1] < StartDateTime)
    {
      TimeRangeHigh[Index] = -FLT_MAX;
      TimeRangeLow[Index] = FLT_MAX;
    }
    else
    {
      TimeRangeHigh[Index] = TimeRangeHigh[Index - 1];
      TimeRangeLow[Index] = TimeRangeLow[Index - 1];
    }

    //Outside of range
    if (sc.BaseDateTimeIn[Index] > EndDateTime || sc.BaseDateTimeIn[Index] < StartDateTime)
      continue;


    if (sc.BaseData[InputDataHighIndex].GetArraySize() > 0)
    {
      if (TimeRangeHigh[Index] < sc.BaseData[InputDataHighIndex][Index])
        TimeRangeHigh[Index] = sc.BaseData[InputDataHighIndex][Index];
    }
    else
    {

      if (TimeRangeHigh[Index] < sc.BaseData[0][Index])
        TimeRangeHigh[Index] = sc.BaseData[0][Index];
    }

    if (sc.BaseData[InputDataLowIndex].GetArraySize() > 0)
    {
      if (TimeRangeLow[Index] > sc.BaseData[InputDataLowIndex][Index])
        TimeRangeLow[Index] = sc.BaseData[InputDataLowIndex][Index];
    }
    else
    {
      if (TimeRangeLow[Index] < sc.BaseData[0][Index])
        TimeRangeLow[Index] = sc.BaseData[0][Index];
    }

    if (DisplayHighLowIncrementally.GetYesNo())
    {

      HighOfDay[Index] = TimeRangeHigh[Index];
      LowOfDay[Index] = TimeRangeLow[Index];
    }
    else
    {
      int  BackIndex = Index;

      while (true)
      {
        if (BackIndex < 0)
          break;

        SCDateTime IndexDateTime = sc.BaseDateTimeIn[BackIndex];

        if (IndexDateTime < StartDateTime)
          break;

        HighOfDay[BackIndex] = TimeRangeHigh[Index];
        LowOfDay[BackIndex] = TimeRangeLow[Index];


        BackIndex--;

        if (sc.UpdateStartIndex != 0)
          sc.EarliestUpdateSubgraphDataArrayIndex = BackIndex;
      }
    }

  }
}




Date Time Of Last Edit: 2019-06-04 09:21:50

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

Login

Login Page - Create Account