Login Page - Create Account

Support Board


Date/Time: Tue, 07 May 2024 22:35:17 +0000



Post From: A few basic ACSIL questions

[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