Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 15:50:39 +0000



[Programming Help] - A few basic ACSIL questions

View Count: 1222

[2020-06-24 14:10:17]
grantx - Posts: 244
I see these snippets a lot in the code. Can someone please explain what each one does? I have read the documentation and managed to get a basic study to work but I am not sure exactly how it works.

This seems to be extracting an array using another array -1.
SCDateTime PriorDayCloseDateTime = sc.GetStartDateTimeForTradingDate(sc.GetTradingDayDate(sc.BaseDateTimeIn[sc.ArraySize - 1]) );
  
I have no idea what this is doing:
PriorDayCloseDateTime -= 1 * SECONDS;

  
This is creating an integer variable and assigning an index number to it. What is this index number?
int PriorDayCloseDateTimeIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, PriorDayCloseDateTime);

Here is my full code so that you can see it all in context. I want to get yesterdays close, high and low values printed on todayschart:

// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Grantx Custom Studies")

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.
SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_PreviousCloseLine = sc.Subgraph[0];
  SCInputRef Input_UsePreviousCloseFromQuoteData = sc.Input[0];
  
  // Section 1 - Set the configuration variables and defaults
  if (sc.SetDefaults)
  {
    sc.GraphName = "Previous Close Line";

    Subgraph_PreviousCloseLine.Name = "Prior Day Close";
    Subgraph_PreviousCloseLine.DrawStyle = DRAWSTYLE_TEXT;    
    
    //Subgraph_PreviousCloseLine.LineStyle = LINESTYLE_DOT;
    //Subgraph_PreviousCloseLine.PrimaryColor = RGB(0, 255, 0);
    //Subgraph_PreviousCloseLine.LineWidth = 2;
    Subgraph_PreviousCloseLine.DrawZeros = false;
    //Subgraph_PreviousCloseLine.LL_NAME_REVERSE_COLORS =true;
    Subgraph_PreviousCloseLine.LineLabel = LL_DISPLAY_NAME | LL_NAME_ALIGN_CENTER | LL_NAME_ALIGN_FAR_RIGHT | LL_NAME_REVERSE_COLORS;

    Input_UsePreviousCloseFromQuoteData.Name = "Use Previous Close From Quote Data";
    Input_UsePreviousCloseFromQuoteData.SetYesNo(0);

    sc.GraphRegion = 0;
    sc.AutoLoop = 0;
    
    return;
  }
  
  
  SCDateTime PriorDayCloseDateTime = sc.GetStartDateTimeForTradingDate(sc.GetTradingDayDate(sc.BaseDateTimeIn[sc.ArraySize - 1]) );

  PriorDayCloseDateTime -= 1 * SECONDS;

  int PriorDayCloseDateTimeIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, PriorDayCloseDateTime);

  float PriorDayCloseValue = 0.0;
  if (Input_UsePreviousCloseFromQuoteData.GetYesNo())
    PriorDayCloseValue = sc.PreviousClose;
  else
    PriorDayCloseValue = sc.BaseData[SC_LAST][PriorDayCloseDateTimeIndex];

  for (int BarIndex = sc.UpdateStartIndex ; BarIndex < sc.ArraySize; ++BarIndex)
  {
    if (BarIndex < PriorDayCloseDateTimeIndex)
      continue;

    Subgraph_PreviousCloseLine[BarIndex] = PriorDayCloseValue;
  }
  
  
}


btw I am expecting to hear the sound of crickets on this one :)
Date Time Of Last Edit: 2020-06-24 14:11:39
[2020-06-24 18:54:43]
Sierra Chart Engineering - Posts: 104368
One thing we can tell is you are running an older version of Sierra Chart. Update to the current version because there are some changes with the use of SCDateTime.

Instructions:
Software Download: Fast Update
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
[2020-06-24 23:46:17]
Flipper - Posts: 65
So
SCDateTime PriorDayCloseDateTime = sc.GetStartDateTimeForTradingDate(sc.GetTradingDayDate(sc.BaseDateTimeIn[sc.ArraySize - 1]) );

This give you a single (not array as you state) datetime value as a Double Working with the SCDateTime Variables and Values: SCDateTime Variables
That Datetime value is the Datetime of the first Bar of the trading day. Which you have now set to PriorDayCloseDateTime.

PriorDayCloseDateTime -= 1 * SECONDS;

This subtracts 1 second off that PriorDayCloseDateTime datetime variable. So now its not the start of current day but 1 second before.

int PriorDayCloseDateTimeIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, PriorDayCloseDateTime);

Now this is taking the PriorDayCloseDateTime and finding the Bar Index that is the closest to the DateTime variable you have set above.

PriorDayCloseValue = sc.BaseData[SC_LAST][PriorDayCloseDateTimeIndex];
Then you are using that index value to find the Close price of that bar. Which is of course yesterdays close.
[2020-06-25 10:15:30]
grantx - Posts: 244
Thank you so much flipper. I really appreciate your help!
I think I understand most of that, just this one bit.

In the sample code above it uses an arraysize-1:
(sc.BaseDateTimeIn[sc.ArraySize - 1])

But the help files show it being used at the current array:
SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index]

ACSIL Interface Members - Variables and Arrays: sc.BaseDateTimeIn[]

Is that because we are not interested in the currently forming bar?
[2020-06-25 10:44:09]
Flipper - Posts: 65
sc.ArraySize starts at 1 for the first bar
sc.Index starts at 0 for the first bar

or to put it another way at the last bar sc.ArraySize-1 = sc.Index

Working with ACSIL Arrays and Understanding Looping: Array Indexing and Sizes
[2020-06-25 12:30:49]
grantx - Posts: 244
Thank you Flipper. Very kind of you to explain.

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

Login

Login Page - Create Account