Login Page - Create Account

Support Board


Date/Time: Wed, 08 May 2024 21:27:03 +0000



[Programming Help] - ACSIL - WilliamsR

View Count: 880

[2018-02-28 20:58:34]
VaclavS - Posts: 21
Hello,
Can you pls show to me ACSIL code for WilliamsR
[2018-02-28 22:51:54]
JoseyWales - Posts: 67
Here is the code for Williams %R, found in file ACS_Source\studies5.cpp

SCSFExport scsf_WilliamsR(SCStudyInterfaceRef sc)
{
  SCSubgraphRef PercentR = sc.Subgraph[0];

  SCInputRef Length = sc.Input[3];
  SCInputRef Invert = sc.Input[4];
  SCInputRef InputDataHigh = sc.Input[5];
  SCInputRef InputDataLow = sc.Input[6];
  SCInputRef InputDataLast = sc.Input[7];
  SCInputRef UpdateFlag = sc.Input[8];

  if(sc.SetDefaults)  
  {
    sc.GraphName = "Williams %R";

    sc.GraphRegion= 1;
    sc.ValueFormat = 2;

    PercentR.Name = "%R";
    PercentR.DrawZeros = true;
    PercentR.DrawStyle = DRAWSTYLE_LINE;
    PercentR.PrimaryColor = RGB(0,255,0);

    Length.Name = "Length";
    Length.SetInt(10);
    Length.SetIntLimits(1,MAX_STUDY_LENGTH);

    Invert.Name = "Invert Output";
    Invert.SetYesNo(1);

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

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

    InputDataLast.Name = "Input Data for Last";
    InputDataLast.SetInputDataIndex(SC_LAST);

    UpdateFlag.SetInt(1); //update flag

    sc.AutoLoop = 1;


    //During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;


    return;
  }

  if (UpdateFlag.GetInt() == 0)
  {
    InputDataHigh.SetInputDataIndex(SC_HIGH);
    InputDataLow.SetInputDataIndex(SC_LOW);
    InputDataLast.SetInputDataIndex(SC_LAST);
    UpdateFlag.SetInt(1);
  }

  sc.DataStartIndex = Length.GetInt();

  sc.WilliamsR(
    sc.BaseData[InputDataHigh.GetInputDataIndex()],
    sc.BaseData[InputDataLow.GetInputDataIndex()],
    sc.BaseData[InputDataLast.GetInputDataIndex()],
    PercentR,
    sc.Index,
    Length.GetInt()
    );

  if (Invert.GetYesNo())
    PercentR[sc.Index] *= -1;
}

[2018-02-28 23:13:01]
JoseyWales - Posts: 67
If you were asking about how the sc.WilliamsR() function operates, it calls WilliamsR2_S behind the scenes:


float GetHighest(SCFloatArrayRef In, int StartIndex, int Length)
{
  float High = -FLT_MAX;
  
  // Get the high from the last Length indexes in the In array
  for (int SrcIndex = StartIndex; SrcIndex > StartIndex - Length; --SrcIndex)
  {
    if (SrcIndex < 0 || SrcIndex >= In.GetArraySize())
      continue;
    
    if (In[SrcIndex] > High)
      High = In[SrcIndex];
  }
  
  return High;
}

float GetLowest(SCFloatArrayRef In, int StartIndex, int Length)
{
  float Low = FLT_MAX;
  
  // Get the low from the last Length indexes in the In array
  for (int SrcIndex = StartIndex; SrcIndex > StartIndex - Length; --SrcIndex)
  {
    if (SrcIndex < 0 || SrcIndex >= In.GetArraySize())
      continue;
    
    if (In[SrcIndex] < Low)
      Low = In[SrcIndex];
  }
  
  return Low;
}

SCFloatArrayRef WilliamsR2_S(SCFloatArrayRef InputDataHigh, SCFloatArrayRef InputDataLow, SCFloatArrayRef InputDataLast, SCFloatArrayRef Out, int Index, int Length)
{
  if(Index < Length)
    Out[Index]=0;
  else
  {
    float High = GetHighest(InputDataHigh,Index, Length);
    float Low = GetLowest(InputDataLow,Index,Length);
    Out[Index] = 100 * ( High-InputDataLast[Index]) / (High - Low);
  }

  return Out;
}

[2018-03-01 21:58:45]
Sierra Chart Engineering - Posts: 104368
For reference here is the relevant documentation:
How to Build an Advanced Custom Study from Source Code: Searching for Source Code for Sierra Chart Built-In Studies
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: 2018-03-01 21:58:54

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

Login

Login Page - Create Account