ACSIL Interface Members - Functions


On This Page


Functions

Notes About Output Arrays for Functions

In the descriptions below for the functions, Intermediate Study Calculation Functions are identified by Type: Intermediate Study Calculation Function in the description.

Intermediate Study Calculation Functions in most cases require one or more or arrays for output of the results. These can take one of two types.

These types can be: SCFloatArrayRef (a reference to a Sierra Chart array of Float values) or SCSubgraphRef (a reference to a sc.Subgraph[] which contains multiple SCFloatArray arrays).

SCFloatArrayRef: For this type you can pass a sc.Subgraph[].Data array using sc.Subgraph[] or sc.Subgraph[].Data.

Both of these are equivalent to each other. In each case, the sc.Subgraph[].Data[] array of floats will get passed in.

Or, you can pass in a sc.Subgraph[] internal extra array using sc.Subgraph[].Array[]. If you do not need visible output on the chart for the results and you want to conserve the visible/graphable sc.Subgraph[].Data arrays, then use a sc.Subgraph[].Array[] internal extra array by passing a sc.Subgraph[].Array[] for the output array parameter.

SCSubgraphRef: For this type you can only pass a sc.Subgraph[].

The SCSubgraphRef type is required because internally the function will use the available internal extra arrays which are part of a sc.Subgraph. These arrays are either used for internal calculations or are used for additional output.

If they are used for additional output, then that is clearly explained in the documentation for the function. For example, the sc.MACD() function will place output for additional MACD related lines into the sc.Subgraph[].Arrays[].

There is one point of clarification. When a sc.Subgraph is required, you cannot use sc.Subgraph[].Data. You must only use sc.Subgraph[]. This will pass in the entire sc.Subgraph[] object because the function requires a sc.Subgraph[] object.

When using a sc.Subgraph[] object and you do not want to have the result of the Intermediate Study Calculation Function actually drawn on the chart, then set sc.Subgraph[].DrawStyle = DRAWSTYLE_IGNORE.

Array Based Study Functions That Do Not Use the Index Parameter

The Advanced Custom Study Interface has versions of functions (function "overloads" as known in C++) that take input and output arrays as parameters, and do not require the Index parameter.

These functions are called Intermediate Study Calculation Functions whether they require the Index parameter or not.

For example, they may calculate a Moving Average from an input data array and place the results into an output data array.

The versions that do not require the Index parameter simplify the calling of these functions. If your study function uses Automatic Looping by setting sc.AutoLoop = 1; in the if(sc.SetDefaults) block, then you can use these functions.

The function versions that do not use the Index parameter will not function properly when you are using Manual Looping.

You will see an example below of a call to an Intermediate Study Calculation Function, that uses the Index parameter and another call to a second version of that same function that does not use the Index parameter.

If your study function is using Automatic Looping, then you can use a version of an Intermediate Study Calculation Function that takes the Index parameter or the one that does not.

Using the version that does not require the Index parameter simply makes writing your code simpler.

Example

if(sc.SetDefaults)
{
    //...
    sc.AutoLoop = 1;
    //...
}

//Calculates a 20 period moving average of Last prices.
sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], sc.Index, 20);

//Calculates a 20 period moving average of Last prices. 
//Index parameter not used. Same as above, but a more simple function call.
sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);
            

Return Object of Array Based Study Functions

Intermediate Study Calculation Functions that take a SCFloatArrayRef or SCSubgraphRef parameter for output, will return a SCFloatArray object by reference. This return object is either the SCFloatArray parameter, or the sc.SCSubgraph[].Data array of the sc.SCSubgraph parameter.

Example

SCSubgraphRef MidBand = sc.Subgraph[1];

// Copy the middle Bollinger band value to Subgraph 10 at the current index
sc.Subgraph[10][sc.index]= sc.BollingerBands(

sc.BaseDataIn[SC_LAST],
MidBand,
Length.GetInt(),
StandardDeviations.GetFloat(),

MAType.GetMovAvgType() )[sc.index];
            

Cumulative Calculations with Intermediate Study Functions

The Output array parameter of a intermediate study calculation function can be used as the Input array parameter for another intermediate study calculation function.

The scsf_AverageOfAverage function in the /ACS_Source/studies3.cpp file in the Sierra Chart installation folder is an example of a function that shows how to use 2 intermediate study calculation functions (sc.LinearRegressionIndicator, sc.ExponentialMovAvg) together.

It calculates the Exponential Moving Average of a Linear Regression Indicator by passing the Output array from the Linear Regression Indicator to the Input array parameter of Exponential Moving Average.

Working with Intermediate Study Calculation Functions

The code example below demonstrates using Intermediate Study Calculation Functions.

Example

//Below are example calls to ACSIL intermediate study calculation functions.

//In this example we are giving the study function a graphable sc.Subgraph[].Data array.
//Even though that this Subgraph result can be drawn on the chart, it does not need to be
//if it does not have a visible DrawStyle
sc.SimpleMovAvg(sc.BaseData[SC_LAST], sc.Subgraph[0].Data, 10);

//Get the value from the calculation above
float AverageAtIndex = sc.Subgraph[0].Data[sc.Index];

//In this example we are giving the study function a Subgraph internal extra
//array which is not capable of being graphed.
sc.SimpleMovAvg(sc.BaseData[SC_LAST], sc.Subgraph[0].Arrays[0], 10);

AverageAtIndex = sc.Subgraph[0].Arrays[0][sc.Index];
            

sc.AdaptiveMovAvg()

Type: Intermediate Study Calculation Function

SCFloatArrayRef AdaptiveMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length, float FastSmoothConstant, float SlowSmoothConstant);

SCFloatArrayRef AdaptiveMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length, float FastSmoothConstant, float SlowSmoothConstant); Auto-looping only.

The sc.AdaptiveMovAvg() function calculates the standard Adaptive Moving Average study.

Parameters:

Example

sc.AdaptiveMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20, 2.0f, 30.0f);

float MAValue = sc.Subgraph[0][sc.Index];
            

sc.AddAlertLine()

Type: Function

AddAlertLine(SCString Message, int ShowAlertLog = 0);

AddAlertLine(char* Message, int ShowAlertLog = 0);

sc.AddAlertLine() is a function for adding an Alert Message to the Sierra Chart Alerts Log.

To open the Alerts Log, select Window >>Show/Hide Alerts Manager >> Alerts Log.

This function adds a type of Alert Message to the Alerts Log which allows the Go to Chart commands on the Alerts Log to be used.

The Message text can be any text that you want to display in the Alerts Log. Message can be either a SCString type or a plain C++ string ("This is an Example").

ShowAlertLog needs to be set to 1 to cause the Alerts Log to open, if it is not already, when a message is added. Otherwise, ShowAlertLog needs to be 0 or it can be optionally left out to not open the Alerts Log when a message is added.

Refer to the scsf_LogAndAlertExample() function in the /ACS_Source/studies.cpp file in the Sierra Chart installation folder for example code to work with this function.

To make an Alert Message that contains formatted variables, refer to the Working With Text Strings section.

Example

// Add an alert line to the Alerts Log
sc.AddAlertLine("Condition is TRUE");

sc.AddAlertLine("Condition is TRUE. The Alerts Log will open if it is not already.",1);

SCString MyString= "This is my string.";

sc.AddAlertLine(MyString,1);
            

sc.AddAlertLineWithDateTime()

Type: Function

AddAlertLineWithDateTime(const char* Message, int ShowAlertLog, SCDateTime AlertDateTime);

The sc.AddAlertLineWithDateTime function is identical to sc.AddAlertLine except that it has an AlertDateTime parameter of type SCDateTime, which can be set to a Date-Time value which will be included in the Alerts Log message.

When using the Go to Chart commands on the Alerts Log, the chart will be scrolled to this particular Date-Time.

sc.AddElements()

Type: Function

int AddElements(int NumElements);

sc.AddElements() adds the number of elements specified with the NumElements parameter, to all the sc.Subgraph[].Data[] arrays.

The arrays up to the last actually used sc.Subgraph[].Data array, will actually have elements added. Unused sc.Subgraph[].Data arrays will be left un-allocated until they are needed.

This function must only used when you have set sc.IsCustomChart to 1 (TRUE).

The function returns 0 if it fails to add the requested number of elements to all the arrays.

This function also adds elements to the sc.DateTimeOut[] , sc.Subgraph[].DataColor[], and sc.Subgraph[].Arrays[][] arrays if they are used.

Example

sc.AddElements(5); // Add five elements to the arrays
            

sc.AddMessageToLog()

Type: Function

AddMessageToLog( SCString& Message, int Showlog);

sc.AddMessageToLog() is used to add a message to the log. See the scsf_LogAndAlertExample() function in the studies.cpp file inside the ACS_Source folder inside of the Sierra Chart installation folder for example code on how to work with this function.

Example

sc.AddMessageToLog("This line of text will be added to the message log, but the message log will not pop open.", 0);
sc.AddMessageToLog("This line of text will be added to the Message Log, and this call will show the Message Log.", 1);
            

If you want to make a message line that contains formatted variables to add to the Message Log, refer to the Working With Text Strings and Setting Names section.

sc.AdjustDateTimeToGMT()

Type: Function

AdjustDateTimeToGMT( const SCDateTime& DateTime);

The sc.AdjustDateTimeToGMT() function converts the given DateTime from the time zone Sierra Chart is set to, to the GMT time zone.

Example

SCDateTime DateTimeInGMT;
sc.AdjustDateTimeToGMT(sc.BaseDateTimeIn[sc.Index]);
            

sc.ADX()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ADX (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int DXLength, int DXMovAvgLength);

SCFloatArrayRef ADX (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int DXLength, int DXMovAvgLength); Auto-looping only.

The sc.ADX() function calculates the Average Directional Index (ADX) study.

Parameters:

Example

sc.ADX(sc.BaseDataIn, sc.Subgraph[0], 14, 14);

float ADXValue = sc.Subgraph[0][sc.Index]; //Access the study value at the current index
            

sc.ADXR()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ADXR (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int DXLength, int DXMovAvgLength, int ADXRInterval);

SCFloatArrayRef ADXR (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int DXLength, int DXMovAvgLength, int ADXRInterval); Auto-looping only.

The sc.ADXR() function calculates the Average Directional Movement Rating.

Parameters:

Example

sc.ADXR(sc.BaseDataIn, sc.Subgraph[0], 14, 14, 14);

float ADXRValue = sc.Subgraph[0][sc.Index]; //Access the study value at the current index
            

sc.AreDeltaVolumeBars()

Type: Function

int AreDeltaVolumeBars()

sc.AreDeltaVolumeBars() returns TRUE(1) if the bars are Delta Volume Bars. Otherwise returns FALSE(0).

sc.ArePriceChangesBars()

Type: Function

int ArePriceChangesBars()

sc.ArePriceChangesBars() returns TRUE(1) if the bars are Price Changes Bars. Otherwise returns FALSE(0).

sc.AreRangeBars()

Type: Function

int AreRangeBars()

sc.AreRangeBars() returns TRUE(1) if the bars are Range bars. Otherwise returns FALSE(0).

Example

int RangeBars = sc.AreRangeBars();

sc.AreRenkoBars()

Type: Function

int AreRenkoBars()

The sc.AreRenkoBars() function returns TRUE(1) if the chart bars are Renko bars. Otherwise, it returns FALSE(0).

Example

int RenkoBars = sc.AreRenkoBars();

sc.AreNumberOfTradesBars()

Type: Function

int AreTickBars()

sc.AreNumberOfTradesBars() returns TRUE(1) if the chart bars are based upon a specified number of Ticks/Trades. Otherwise, this function returns FALSE(0).

Example

int NumberOfTradesBars = sc.AreNumberOfTradesBars();

sc.AreTimeSpecificBars()

Type: Function

int AreTimeSpecificBars()

sc.AreTimeSpecificBars() returns TRUE(1) if the bars are based upon a fixed amount of time. Example 10 Minutes per bar. Otherwise, this function returns FALSE(0).

Example

int TimeSpecific = sc.AreTimeSpecificBars();

sc.AreVolumeBars()

Type: Function

int AreVolumeBars()

sc.AreVolumeBars() returns a value, TRUE(1) if the bars are volume bars, otherwise returns FALSE(0).

Example

int VolumeBars = sc.AreVolumeBars();

sc.ArmsEMV()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ArmsEMV(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int VolumeDivisor, int Index);

SCFloatArrayRef ArmsEMV(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int VolumeDivisor); Auto-looping only.

The sc.ArmsEMV() function calculates the Arms Ease of Movement Value.

Parameters:

Example

sc.ArmsEMV(sc.BaseDataIn, sc.Subgraph[0], 10);

float ArmsEMV = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.AroonIndicator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef AroonIndicator(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef AroonIndicator(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.AroonIndicator() function calculates the Aroon Indicator.

Parameters:

Example

sc.AroonIndicator(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 10);
float AroonIndicatorUp = sc.Subgraph[0][sc.Index]; //Access the Aroon Indicator Up study value at the current index 
float AroonIndicatorDown = sc.Subgraph[0].Arrays[0][sc.Index]; //Access the Aroon Indicator Down study value at the current index

sc.ArrayValueAtNthOccurrence()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ArrayValueAtNthOccurrence(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, int Index, int NthOccurrence);

SCFloatArrayRef ArrayValueAtNthOccurrence(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, int NthOccurrence ); Auto-looping only.

The sc.ArrayValueAtNthOccurrence() function iterates the FloatArrayIn1 array for non-zero values starting at Index and going back. When the number of non-zero values found in FloatArrayIn1 equals the number specified by NthOccurrence, then the value of FloatArrayIn2 is returned at the Index where the NthOccurrence of non-zero values was found in FloatArrayIn1.

For an example, refer to the scsf_ArrayValueAtNthOccurrenceSample function in the /ACS_Source/studies6.cpp file.

Parameters:

Example

SCSubgraphRef ValueAtOccurence = sc.Subgraph[1];
ValueAtOccurence[sc.Index] = sc.ArrayValueAtNthOccurrence(StochasticData.Arrays[1],
StochasticData, NumberOfOccurrences.GetInt());

sc.ATR()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ATR(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length, unsigned int MovingAverageType);

SCFloatArrayRef ATR(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length, unsigned int MovingAverageType); Auto-looping only.

SCFloatArrayRef ATR(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut_1, SCFloatArrayRef FloatArrayOut_2, int Index, int Length, unsigned int MovingAverageType);

SCFloatArrayRef ATR(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut_1, SCFloatArrayRef FloatArrayOut_2 , int Length, unsigned int MovingAverageType);

THe sc.ATR() function calculates the Average TRUE Range.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, 1 sc.Subgraph[].Arrays[] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length
  • MovingAverageType
  • FloatArrayOut_1. This is the True Range output array. This is for the implementation of sc.ATR which does not require a SCSubgraphRef.
  • FloatArrayOut_2. This is the Average True Range output array. This is for the implementation of sc.ATR which does not require a SCSubgraphRef.

Example

sc.ATR(sc.BaseDataIn, sc.Subgraph[0], 20, MOVAVGTYPE_SIMPLE);

float ATR = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.AwesomeOscillator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef AwesomeOscillator(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length1, int Length2);

SCFloatArrayRef AwesomeOscillator(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length1, int Length2); Auto-looping only.

THe sc.AwesomeOscillator() function calculates the Awesome Oscillator study.

Parameters:

Example

SCSubgraphRef MovAvgDiff = sc.Subgraph[0];
sc.AwesomeOscillator(sc.BaseDataIn[InputData.GetInputDataIndex()], MovAvgDiff, MA1Length.GetInt(), MA2Length.GetInt());

sc.GetAttachedOrderIDsForParentOrder()

Type: Function

void GetAttachedOrderIDsForParentOrder(int ParentInternalOrderID, int& TargetInternalOrderID, int& StopInternalOrderID);

The sc.GetAttachedOrderIDsForParentOrder function is used to get the Internal Order IDs for a Target and Stop order for a given Parent Internal Order ID.

The ParentInternalOrderID parameter specifies the Parent Internal Order ID. The TargetInternalOrderID, StopInternalOrderID parameters receive the Target and Stop Internal Order IDs respectively.

For information about Internal Order IDs, refer to the ACSIL Trading page. These Internal Order IDs can be obtained when submitting an order.

Example

int TargetInternalOrderID = -1;
int StopInternalOrderID = -1;

//This needs to be set to the parent internal order ID search for. Since we do not know what that is in this code example, it is set to zero here.
int ParentInternalOrderID = 0;

sc.GetAttachedOrderIDsForParentOrder(ParentInternalOrderID, TargetInternalOrderID, StopInternalOrderID)
            

sc.GetBarHasClosedStatus()

Type: Function

int GetBarHasClosedStatus(int BarIndex);

int GetBarHasClosedStatus(); Auto-looping only.

The sc.GetBarHasClosedStatus function is used to determine if the data for a particular bar in the sc.BaseData[][] arrays at the specified BarIndex parameter, has completed and will no longer be updated during real-time or replay updating.

This is useful when you only want to perform calculations on a fully completed bar. It is equivalent to "Signal Only on Bar Close" with the Spreadsheet studies.

This function has several return values described below.

Refer to the scsf_GetBarHasClosedStatusExample() function in the /ACS_Source/studies.cpp file in the Sierra Chart installation folder for example code on how to work with this function.

This function can be used with manual or automatic looping. It can be given an index of any bar. sc.BaseData[][] contains the underlying bar data for the chart. In this code: sc.BaseData[][sc.Index], the variable sc.Index is the index the sc.GetBarHasClosedStatus function uses when sc.Index is given through the BarIndex parameter.

The very last bar in the chart is never considered a closed bar until there is a new bar added to the chart. However, if you know a bar consists of a fixed amount of time, you know that time has elapsed, and you have set sc.UpdateAlways , then you can take some action at that time since you then know the bar is considered closed.

Return Values:

  • BHCS_BAR_HAS_CLOSED — Element at BarIndex has closed.
  • BHCS_BAR_HAS_NOT_CLOSED — Element at BarIndex has not closed.
  • BHCS_SET_DEFAULTS — Configuration and defaults are being set. Allow the sc.SetDefaults code block to run. Bar has closed status is not available.

Example

if(sc.GetBarHasClosedStatus(Index)==BHCS_BAR_HAS_NOT_CLOSED)
{

    return;//do not do any processing if the bar at  the current index has not closed
}

sc.GetBasicSymbolData()

Type: Function

void GetBasicSymbolData(const char* Symbol, s_SCBasicSymbolData& BasicSymbolData, bool Subscribe)

The sc.GetBasicSymbolData will fill out the BasicSymbolData data structure with all of the Current Quote data for the specified Symbol. This data is only considered valid when connected to the data feed. The Current Quote data is the data that is found in Window >> Current Quote Window.

Refer to declaration of s_SCBasicSymbolData in the /ACS_Source/scsymboldata.h file in the folder Sierra Chart is installed to for all of the structure members. The data that is returned when calling this function is the most current available data.

The Subscribe parameter will subscribe to market data for the symbol when connected to the data feed. Subscribing to a symbol, does not mean that the study function will be called for all updates on the symbol. The study function will only be called based upon the updates of the symbol of the chart the study instance is on.

As an example, you could have a list of 10 symbols that request data for by calling sc.GetBasicSymbolData() for each symbol. After each call, examine the returned data and do the calculations. So in this scenario, you can form an index by adding all of the last price values together and dividing by 10, and placing the results in a sc.Subgraph[].Data[] array.

Example

// Get the daily high price for another symbol. The first time this  
// function is called after connecting to the data feed, the symbol data 
// will not be available initially. Once the data becomes available, when  
// this function is called after, the symbol data will be available.  If  
// this study is used on a chart for a symbol which does not frequently  
// update, then it will be a good idea to set sc.UpdateAlways = 1. 
const char * Symbol = "ABC"; 
s_SCBasicSymbolData BasicSymbolData; 
sc.GetBasicSymbolData(Symbol,BasicSymbolData, true); 
float DailyHigh = BasicSymbolData.High;
            

sc.BarIndexToXPixelCoordinate()

Type: Function

int BarIndexToXPixelCoordinate(int Index);

The sc.BarIndexToXPixelCoordinate function will calculate the corresponding X-axis pixel coordinate from the given chart bar Index .

Example

 
int X = sc.BarIndexToXPixelCoordinate (sc.Index);
            

sc.BollingerBands()

Type: Intermediate Study Calculation Function

SCFloatArrayRef BollingerBands (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length, float Multiplier, int MovingAverageType);

SCFloatArrayRef BollingerBands (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length, float Multiplier, int MovingAverageType); Auto-looping only.

The sc.BollingerBands() function calculates the Bollinger or Standard Deviation bands.

Parameters:

Example

sc.BollingerBands(sc.BaseData[SC_LAST], sc.Subgraph[0], 10, 1.8, MOVAVGTYPE_SIMPLE);

//Access the individual lines
float Average = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

float UpperBand = sc.Subgraph[0].Arrays[0][sc.Index];

float LowerBand = sc.Subgraph[0].Arrays[1][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = UpperBand;
sc.Subgraph[2][sc.Index] = LowerBand;

sc.CalculateOHLCAverages()

Type: Function

int CalculateOHLCAverages(int Index);

int CalculateOHLCAverages(); Auto-looping only.

sc.CalculateOHLCAverages() calculates the averages from the sc.Subgraph[].Data[] arrays SC_OPEN (0), SC_HIGH (1), SC_LOW (2), SC_LAST (3), and fills in the sc.Subgraph[].Data[] arrays for subgraphs SC_OHLC (4), SC_HLC (5), and SC_HL (6) for the elements at Index. You will want to use this if your study acts as a Main Price Graph. This would be the case when you set sc.UsePriceGraphStyle and sc.DisplayAsMainPriceGraph to 1 (TRUE).

Example

// Fill in the averages arrays
sc.CalculateOHLCAverages(sc.Index);

sc.CalculateTimeSpanAcrossChartBars()

Type: Function

double CalculateTimeSpanAcrossChartBars(int FirstIndex, int LastIndex);

The sc.CalculateTimeSpanAcrossChartBars function calculates the time span across the chart bars specified by the bar index parameters FirstIndex and LastIndex. The time length of the bar specified by LastIndex is also included in the time span.

If FirstIndex and LastIndex are the same, then the time length of the single specified bar will be what is returned.

The return type is a double Which is directly equivalent to a SCDateTime type and can be assigned to this type.

One useful purpose of this function is to determine if the particular span of time is sufficient enough for other calculations. This can be useful for detecting holidays.

sc.CCI()

Type: Intermediate Study Calculation Function

SCFloatArrayRef CCI(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length, float Multiplier);

SCFloatArrayRef CCI(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length, float Multiplier); Auto-looping only.

The sc.CCI() function calculates the Commodity Channel Index.

Parameters:

Example

// Subgraph 0 will contain the CCI output
sc.CCI(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20, 0.015);

float CCI = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.ChaikinMoneyFlow()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ChaikinMoneyFlow(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef ChaikinMoneyFlow(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.ChaikinMoneyFlow() function calculates the Chaikin Money Flow.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0] (Extra Array) is used for internal calculations and additional results output.
  • Index
  • Length

Example

sc.ChaikinMoneyFlow(sc.BaseDataIn, sc.Subgraph[0], 10);

float ChaikinMoneyFlow = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.ChartIsDownloadingHistoricalData()

Type: Function

int ChartIsDownloadingHistoricalData(int ChartNumber);

The sc.ChartIsDownloadingHistoricalData() function returns TRUE (1) if the chart the study instance is on, is downloading historical data. This function returns FALSE(0) if historical data is not being downloaded.

Parameters:

  • ChartNumber: The number of the chart to determine the historical data download status of. Normally this will be set to sc.ChartNumber to determine the historical data download status of the chart the study instance is applied to.

Example

int IsDownloading = sc.ChartIsDownloadingHistoricalData(sc.ChartNumber); SCString MessageText; MessageText.Format("Downloading state: %d", IsDownloading); sc.AddMessageToLog(MessageText.GetChars(), 0);

sc.CloseChart()

Type: Function

void CloseChart(int ChartNumber);

The sc.CloseChart() function closes the chart specified by the ChartNumber parameter. The chart must exist within the same Chartbook that the custom study is also contained in.

For an example, refer to the scsf_CloseChart function in the /ACS_Source/studies5.cpp file in the Sierra Chart installation folder.

sc.CloseChartbook()

Type: Function

void CloseChartbook(const SCString& ChartbookFileName);

The sc.CloseChartbook() function closes the Chartbook specified by the ChartbookFileName filename parameter. The filename should not contain the path, only the filename.

For an example, refer to the scsf_CloseChartbook function in the /ACS_Source/studies5.cpp file in the Sierra Chart installation folder.

sc.CombinedForegroundBackgroundColorRef()

Type: Function

unsigned int CombinedForegroundBackgroundColorRef(COLORREF ForegroundColor, COLORREF BackgroundColor);

The sc.CombinedForegroundBackgroundColorRef function combines foreground and background color values into a single 32-bit value. This function is meant to be used to set the foreground and background colors through the sc.Subgraph[].DataColor[] array when displaying a table of values on a chart.

Since two 24-bit color values are combined into a 32 bit value, reduces the color detail and the exact colors are not necessarily going to be represented.

Refer to the code example below.

sc.Subgraph[0].DataColor[sc.Index] = sc.CombinedForegroundBackgroundColorRef(COLOR_BLACK, COLOR_GREEN);

sc.ConvertToSCTimeZone()

Type: Function

SCDateTime ConvertToSCTimeZone(const SCDateTime& DateTime, const char* TimeZonePOSIXString);

SCDateTime ConvertToSCTimeZone(const SCDateTime& DateTime, TimeZonesEnum TimeZone);

The sc.ConvertToSCTimeZone() function converts the DateTime SCDateTime variable from the specified TimeZone to the Time Zone setting in Global Settings >> Data/Trade Service Settings.

The source time zone can also be specified as a POSIX text string. For a list of these strings refer to the TIME_ZONE_POSIX_STRINGS array in the /ACS_Source/SCConstants.h file in the folder where Sierra Chart is installed to.

List of TimeZone constants that can be used:

  • TIMEZONE_HONOLULU
  • TIMEZONE_ANCHORAGE
  • TIMEZONE_LOS_ANGELES
  • TIMEZONE_PHOENIX
  • TIMEZONE_DENVER
  • TIMEZONE_CHICAGO
  • TIMEZONE_NEW_YORK
  • TIMEZONE_HALIFAX
  • TIMEZONE_UTC
  • TIMEZONE_LONDON
  • TIMEZONE_BRUSSELS
  • TIMEZONE_ATHENS
  • TIMEZONE_MOSCOW
  • TIMEZONE_DUBAI
  • TIMEZONE_ISLAMABAD
  • TIMEZONE_NEW_DELHI
  • TIMEZONE_DHAKA
  • TIMEZONE_JAKARTA
  • TIMEZONE_HONG_KONG
  • TIMEZONE_TOKYO
  • TIMEZONE_BRISBANE
  • TIMEZONE_SYDNEY
  • TIMEZONE_AUCKLAND

Example

// Convert the DateTime from New York time to the time zone used for charts
DateTime = sc.ConvertToSCTimeZone(DateTime, TIMEZONE_NEW_YORK);
DateTime.GetDateTimeYMDHMS(Year, Month, Day, Hour, Minute, Second);

// Write to the message log
SCString MessageString.Format("Converted from New York time: %d-%02d-%02d %02d:%02d:%02d", Year, Month, Day, Hour, Minute, Second);
sc.AddMessageToLog(MessageString, 1);

sc.CrossOver()

Type: Function

int CrossOver (SCFloatArrayRef First, SCFloatArrayRef Second, int Index);

int CrossOver (SCFloatArrayRef First, SCFloatArrayRef Second); Auto-looping only.

sc.CrossOver returns a value indicating if the First study Subgraph has crossed the Second subgraph at the array index specified by Index.

For an example, refer to the scsf_StochasticCrossover function in the /ACS_Source/Systems.cpp file in the Sierra Chart installation folder.

Function return values:

  • CROSS_FROM_TOP - This constant value is returned when the First subgraph crosses the Second subgraph from the top.
  • CROSS_FROM_BOTTOM - This constant value is returned when the First subgraph crosses the Second subgraph from the bottom.
  • NO_CROSS - This constant value is returned when the First subgraph does not cross the Second subgraph.

Example

if (sc.CrossOver(sc.Subgraph[3], sc.Subgraph[4]) == CROSS_FROM_BOTTOM)
{

    //Code
}

// This is an example of looking for a crossover between the values in
// a subgraph and a fixed value. We first have to put the fixed value
// into an array. We are using one of the Subgraph internal arrays.
sc.Subgraph[2].Arrays[8][sc.Index] = 100.0;

if (sc.CrossOver(sc.Subgraph[2], sc.Subgraph[2].Arrays[8]) == CROSS_FROM_BOTTOM)
{

    //Code
}

Checking for a Crossover between an Array of Values and a Fixed Value

When you need to check for a crossover between a Subgraph array and a fixed value, you need to put the fixed value in an array first and pass this array to the sc.Crossover function. It is recommended to use one of the sc.Subgraph. Arrays[] for this purpose.

	
//Check for crossover of Subgraph 0 and a fixed value set into an extra array on the Subgraph
SCFloatArrayRef FixedValueArray = sc.Subgraph[0].Arrays[4];
FixedValueArray[sc.Index] = 100;

//Check if a crossover occurred
if(sc.CrossOver(sc.Subgraph[0], FixedValueArray) != NO_CROSS)
{

}
            

sc.CumulativeDeltaTicks()

Type: Intermediate Study Calculation Function

SCFloatArrayRef CumulativeDeltaTicks(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int ResetCumulativeCalculation);

SCFloatArrayRef CumulativeDeltaTicks(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int ResetCumulativeCalculation); Auto-looping only.

The sc.CumulativeDeltaTicks function calculates the Cumulative Delta Ticks study and provides the Open, High, Low and Last values for each bar. This function can only be used on Intraday charts.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-2] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • ResetCumulativeCalculation: When this is set to TRUE, the cumulative calculations are reset back to 0. You may want to set this to TRUE at the Index which is at the start of a new trading day.

For an example of how to use a function of this type, refer to the scsf_CumulativeDeltaBarsTicks function in the /ACS_Source/studies8.cpp file in the Sierra Chart installation folder.

sc.CumulativeDeltaVolume()

Type: Intermediate Study Calculation Function

SCFloatArrayRef CumulativeDeltaVolume(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int ResetCumulativeCalculation);

SCFloatArrayRef CumulativeDeltaVolume(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int ResetCumulativeCalculation); Auto-looping only.

The sc.CumulativeDeltaVolume function calculates the Cumulative Delta Volume study and provides the Open, High, Low and Last values for each bar. This function can only be used on Intraday charts.

For an example of how to use a function of this type, refer to the scsf_CumulativeDeltaBarsTicks function in the /ACS_Source/studies8.cpp file in the Sierra Chart installation folder.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-2] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • ResetCumulativeCalculation: When this is set to TRUE, the cumulative calculations are reset back to 0. You may want to set this to TRUE at the Index which is at the start of a new trading day.

sc.CumulativeDeltaTickVolume()

Type: Intermediate Study Calculation Function

SCFloatArrayRef CumulativeDeltaTickVolume(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int ResetCumulativeCalculation);

SCFloatArrayRef CumulativeDeltaTickVolume(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int ResetCumulativeCalculation); Auto-looping only.

The sc.CumulativeDeltaTickVolume function calculates the Cumulative Delta Up/Down Tick Volume study and provides the Open, High, Low and Last values for each bar. This function can only be used on Intraday charts.

For an example of how to use a function of this type, refer to the scsf_CumulativeDeltaBarsTicks function in the /ACS_Source/studies8.cpp file in the Sierra Chart installation folder.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-2] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • ResetCumulativeCalculation: When this is set to TRUE, the cumulative calculations are reset back to 0. You may want to set this to TRUE at the Index which is at the start of a new trading day.

sc.CumulativeSummation()

Type: Intermediate Study Calculation Function

SCFloatArrayRef CumulativeSummation (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef CumulativeSummation (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.CumulativeSummation function calculates the summation of all of the elements in FloatArrayIn up to the current Index. Therefore, this function is cumulative in that the summation is across all of the elements in FloatArrayIn from the beginning.

Example

sc.CumulativeSummation(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0]);

float CumulativeSummation = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.DataTradeServiceName()

Type: Function

SCString DataTradeServiceName();

The sc.DataTradeServiceName() function returns the text name of the Service currently set in Global Settings >> Data/trade Service Settings. The return type is a SCString.

sc.DateStringToSCDateTime()

Type: Function

SCDateTime DateStringToSCDateTime(const SCString& DateString);

The sc.DateStringToSCDateTime() function converts the DateString text string to an SCDateTime variable. This function only works with dates.

Example

SCString DateString ("2011-12-1");
SCDateTime DateValue;
DateValue = sc.DateStringToSCDateTime(DateString);

sc.DateTimeToString()

Type: Function

SCDateTime DateTimeToString(const double &DateTime, int Flags);

The sc.DateTimeToString function will convert the given DateTime variable to a text string. The format is specified by the Flags parameter.

The flags can be any of the following:

  • FLAG_DT_YEAR
  • FLAG_DT_MONTH
  • FLAG_DT_DAY
  • FLAG_DT_HOUR
  • FLAG_DT_MINUTE
  • FLAG_DT_SECOND
  • FLAG_DT_PLUS_WITH_TIME
  • FLAG_DT_NO_ZERO_PADDING_FOR_DATE
  • FLAG_DT_HIDE_SECONDS_IF_ZERO
  • FLAG_DT_NO_HOUR_PADDING
  • FLAG_DT_MILLISECOND
  • FLAG_DT_COMPACT_DATE
  • FLAG_DT_COMPLETE_DATE
  • FLAG_DT_COMPLETE_TIME
  • FLAG_DT_COMPLETE_DATETIME
  • FLAG_DT_COMPLETE_DATETIME_MS

Example

 
if(sc.Index == sc.ArraySize - 1)
{
    // Log the current time
    SCString DateTimeString = sc.DateTimeToString(sc.CurrentSystemDateTime,FLAG_DT_COMPLETE_DATETIME_MS);

    sc.AddMessageToLog(DateTimeString, 0);
}
            

sc.Demarker()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Demarker(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef Demarker(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.Demarker() function calculates the Demarker study.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-4] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length

Example

sc.Demarker(sc.BaseDataIn, sc.Subgraph[0], 10);
float Demarker = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.Dispersion()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Dispersion(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef Dispersion(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.Dispersion() function calculates the Dispersion study.

Example

sc.Dispersion(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], 10);

float Dispersion = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.DMI()

Type: Intermediate Study Calculation Function

DMI(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length);

DMI(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.DMI() function calculates the Directional Movement Index study.

Parameters:

  • BaseDataIn: sc.BaseDataIn input arrays.
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-4] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length

Example

sc.DMI(sc.BaseDataIn, sc.Subgraph[0], 10);

//Access the individual study values
float DMIPositive = sc.Subgraph[0][sc.Index];

float DMINegative = sc.Subgraph[0].Arrays[0][sc.Index];

//Copy DMINegative to a visible Subgraph
sc.Subgraph[1][sc.Index] = DMINegative;

sc.DMIDiff()

Type: Intermediate Study Calculation Function

SCFloatArrayRef DMIDiff (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef DMIDiff (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.DMIDiff() function calculates the Directional Movement Index Difference study.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-2] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length

Example

sc.DMIDiff(sc.BaseDataIn, sc.Subgraph[0], 10);

float DMIDiff = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.DoubleStochastic()

Type: Intermediate Study Calculation Function

SCFloatArrayRef DoubleStochastic (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length, int MovAvgLength, int MovingAverageType);

SCFloatArrayRef DoubleStochastic (SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length, int MovAvgLength, int MovingAverageType); Auto-looping only.

The sc.DoubleStochastic() function calculates the Double Stochastic study.

Parameters:

Example

sc.DoubleStochastic(sc.BaseData, sc.Subgraph[0], Length.GetInt(), MovAvgLength.GetInt(), MovAvgType.GetMovAvgType());

//Access the study value at the current index
float DoubleStochastic = sc.Subgraph[0][sc.Index]; 

sc.EnvelopeFixed()

Type: Intermediate Study Calculation Function

SCFloatArrayRef EnvelopeFixed(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, float FixedValue, int Index);

SCFloatArrayRef EnvelopeFixed(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, float FixedValue); Auto-looping only.

The sc.EnvelopeFixed() function calculates the Fixed Envelope study.

Parameters:

  • FloatArrayIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0] (Extra Array) is used for internal calculations and additional results output.
  • FixedValue: This is the amount added and subtracted to FloatArrayIn at the current Index.
  • Index

Example

sc.EnvelopeFixed(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 3.5);
//Access the individual study values at the current index
float EnvelopeTop = sc.Subgraph[0][sc.Index]; 
float EnvelopeBottom = sc.Subgraph[0].Arrays[0][sc.Index];

sc.EnvelopePct()

Type: Intermediate Study Calculation Function

SCFloatArrayRef EnvelopePct(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, float Percent, int Index);

SCFloatArrayRef EnvelopePct(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, float Percent); Auto-looping only.

The sc.EnvelopePct() function calculates the Percentage Envelope study.

Parameters:

Example

sc.EnvelopePct(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], 0.05);

//Access the individual study values at the current index
float Top = sc.Subgraph[0][sc.Index];

float Bottom = sc.Subgraph[0].Arrays[0][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = Bottom;

sc.Ergodic()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Ergodic(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int LongEMALength, int ShortEMALength, float Multiplier);

SCFloatArrayRef Ergodic(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int LongEMALength, int ShortEMALength, float Multiplier); Auto-looping only.

The sc.Ergodic() function calculates the True Strength Index.

Parameters:

Example

sc.Ergodic(
    sc.BaseDataIn[SC_LAST],

    sc.Subgraph[0],
    15, // Long EMA length
    3, // Short EMA length

    1.0f, // Multiplier
);

// You can calculate the signal line and oscillator with the following code:

// Calculate the signal line with an exponential moving average with a length of 10
sc.ExponentialMovAvg(sc.Subgraph[0], sc.Subgraph[1], 10);

// Calculate the oscillator
sc.Subgraph[2][sc.Index] = sc.Subgraph[0][sc.Index] - sc.Subgraph[1][sc.Index];

sc.ExponentialMovAvg()

Type: Intermediate Study Calculation Function

SCFloatArrayRef ExponentialMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef ExponentialMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.ExponentialMovAvg() function calculates the exponential moving average.

Example

sc.ExponentialMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float ExponentialMovAvg = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.FormatDateTime()

Type: Function

SCString FormatDateTime(const SCDateTime& DateTime);

The sc.FormatDateTime() function will create a formatted text string from the DateTime parameter. This text string contains the Date and the Time.

Example

SCString Message;

Message.Format("Current Bar Date-Time: %s, sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars());

sc.AddMessageToLog(Message,0);

sc.FormatGraphValue()

Type: Function

SCString FormatGraphValue(double Value, int ValueFormat);

sc.FormatGraphValue() formats a numeric value as text based on the specified value format. The text is returned as an SCString.

Parameters:

  • Value: The Integer or floating-point value to format.
  • ValueFormat: The formating code. Can be sc.BaseGraphValueFormat. This number sets the number of decimal places to display. If ValueFormat is greater than 100, then it will be a fractional format where the denominator is specified as Denominator + 100 . For example, 132 will format the value in a fractional format using a denominator of 1/32.

Example

SCString CurHigh = sc.FormatGraphValue(sc.BaseData[SC_HIGH][CurrentVisibleIndex], sc.BaseGraphValueFormat);

s_UseTool Tool;
Tool.Text = CurHigh; 

sc.FormatString()

Type: Function

SCString& FormatString(SCString& Out, const char* Format, [Variable list of parameters]);

The sc.FormatString() function creates a text string using the specified Format. For more information, refer to the Setting A Name To A Formatted String section. Out is the SCString you need to provide where the text output is copied to.

Example

SCString Output;

sc.FormatString(Output, "The result is: %f", sc.Subgraph[0].Data[sc.Index]);

sc.FormattedEvaluate()

Type: Function

int FormattedEvaluate(float Value1, int Value1Format, OperatorEnum Operator, float Value2, int Value2Format, float PrevValue1 = 0.0f, float PrevValue2 = 0.0f);

sc.FormattedEvaluate() evaluates the relationship between 2 floating-point numbers using the specified Operator . The evaluation is performed as follows: Value1 Operator Value2. Value1 is rounded to the Value1Format value. Value2 is rounded to the Value2Format value. Returns 1 if the evaluation is TRUE, and 0 if it is FALSE.

The reason why this function needs to be used when performing floating-point number comparisons is due to what is known as floating point error. Refer to Accuracy Problems in the Floating Point Wikipedia article. For example, the number .01 may internally be represented in a single precision floating-point variable as .0099998, therefore making comparisons using the built-in operators of the C++ language not accurate.

Parameters:

  • Value1: Any number to use on the left side of the Operator .
  • Value1Format: The formating code. Can be set to sc.BaseGraphValueFormat or sc.GetValueFormat(). For more information, refer to sc.ValueFormat.
  • Operator:
    • NOT_EQUAL_OPERATOR
    • LESS_EQUAL_OPERATOR
    • GREATER_EQUAL_OPERATOR
    • CROSS_EQUAL_OPERATOR
    • CROSS_OPERATOR
    • EQUAL_OPERATOR
    • LESS_OPERATOR
    • GREATER_OPERATOR
  • Value2: Any number to use on the right side of the Operator .
  • Value2Format: The formating code. Can be set to sc.BaseGraphValueFormat or sc.GetValueFormat(). For more information, refer to sc.ValueFormat.
  • PrevValue1: This only needs to be specified when using the CROSS_OPERATOR operator. In this case, provide the prior value (usually from a line) to use on the left side of the operator in the comparison.
  • PrevValue2: This only needs to be specified when using the CROSS_OPERATOR operator. In this case, provide the prior value (usually from a line) to use on the right side of the operator in the comparison.

Example

int Return = sc.FormattedEvaluate(CurrentClose, sc.BaseGraphValueFormat, LESS_OPERATOR, PriorLow, sc.BaseGraphValueFormat); 

sc.GetChartArray()

Type: Function

GetChartArray(int ChartNumber, int InputData, SCFloatArrayRef PriceArray);

sc.GetChartArray() is for accessing the main/primary base graph data in other loaded charts in the same chartbook containing the chart that your study function is applied to. This is an older function and it is highly recommended that you use sc.GetChartBaseData instead. See the scsf_GetChartArrayExample() function in the studies.cpp file in the ACS_Source folder in the Sierra Chart installation folder for example code to work with this function.

Parameters:

  • ChartNumber: The number of the chart you want to get data from. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • InputData: This can be one of the following:
    • SC_OPEN or 0: The array of opening prices for each bar.
    • SC_HIGH or 1: The array of high prices for each bar.
    • SC_LOW or 2: The array of low prices for each bar.
    • SC_LAST or 3: The array of closing/last prices for each bar.
    • SC_VOLUME or 4: The array of trade volumes for each bar.
    • SC_NUM_TRADES / SC_OPEN_INTEREST or 5: The array of the number of trades for each bar for Intraday charts. Or the open interest for each bar for daily charts.
    • SC_OHLC or 6: The array of the average prices of the open, high, low, and close prices for each bar.
    • SC_HLC or 7: The array of the average prices of the high, low, and close prices for each bar.
    • SC_HL or 8: The array of the average prices of the high and low prices for each bar.
    • SC_BIDVOL or 9: The array of Bid Volumes for each bar. This represents the volumes of the trades that occurred at the bid.
    • SC_ASKVOL or 10:The array of Ask Volumes for each bar. This represents the volumes of the trades that occurred at the ask.
  • PriceArray: A SCFloatArray object which will be set to the data array that you requested. If the data array that you requested could not be retrieved, then the size of this array, PriceArray.GetArraySize(), will be 0.

Example

SCFloatArray PriceArray;

// Get the close/last array from chart #1

sc.GetChartArray(1, SC_LAST, PriceArray);

// The PriceArray may not exist or is empty. Either way we can not do anything with it.
if (PriceArray.GetArraySize() == 0)

    return; 

sc.GetChartBaseData()

Type: Function

GetChartBaseData(int ChartNumber, SCGraphData & BaseData);

The sc.GetChartBaseData() function is for accessing all of the main/primary Base Data arrays in another loaded chart in the same Chartbook as the one containing the chart that your custom study function is applied to.

The main Base Data arrays refer to the arrays of the main price graph in a chart. If the main price graph has been replaced by using a custom chart study such as the Point and Figure chart study, then this function will get this new main price graph from the specified ChartNumber.

Refer to the example below. For a complete working example, refer to Referencing Other Time Frames and Symbols When Using the ACSIL.

For information about getting the corresponding index in the arrays returned, refer to Accessing Correct Array Indexes in Other Chart Arrays.

Parameters:

  • ChartNumber: The number of the chart you want to get data from. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • BaseData: A SCGraphData object which will be set to all of the main/primary base graph arrays from the specified chart.

Example

// The following code is for getting the High array
// and corresponding index from another chart.

// Define a graph data object to get all of the base graph data
SCGraphData BaseGraphData;

// Get the base graph data from the specified chart
sc.GetChartBaseData(ChartNumber.GetInt(), BaseGraphData);

// Define a reference to the High array
SCFloatArrayRef HighArray = BaseGraphData[SC_HIGH];

// Array is empty. Nothing to do.
if(HighArray.GetArraySize() == 0)

return;

// Get the index in the specified chart that is
// nearest to current index.
int RefChartIndex =
sc.GetNearestMatchForDateTimeIndex(ChartNumber.GetInt(), sc.Index);

float NearestRefChartHigh = HighArray[RefChartIndex];

sc.GetChartDateTimeArray()

Type: Function

GetChartDateTimeArray(int ChartNumber, SCDateTimeArray& DateTimeArray);

sc.GetChartDateTimeArray() is used to access the SCDateTime array (sc.BaseDateTimeIn[]) in other loaded charts in the same chartbook containing the chart that your study is applied to. See the scsf_GetChartArrayExample() function in the studies.cpp file inside the ACS_Source folder inside of the Sierra Chart installation folder for example code to work with this function.

Parameters:

  • ChartNumber: The number of the chart you want to get the data from. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • DateTimeArray: A SCDateTimeArray object which will be set to the SCDateTime array that you requested. If the SCDateTime array that you requested could not be retrieved, then the size of this array (DateTimeArray.GetArraySize()) will be 0.

Example

SCDateTimeArray DateTimeArray;

// Get the DateTime array from chart #1
sc.GetChartDateTimeArray(1, DateTimeArray);

// The array may not exist or is empty. Either way we can not do anything with it.
if (DateTimeArray.GetArraySize() == 0)
    return;

sc.GetChartDrawing()

Type: Function

For more information, refer to the sc.GetUserDrawnChartDrawing() section on the Using Tools From an Advanced Custom Study page.

sc.GetChartName()

Type: Function

int GetChartName(int ChartNumber);

The sc.GetChartName() function, gets the name of the chart specified by the ChartNumber parameter. The name contains the symbol of the chart as well as the timeframe per bar and the chart number. For an example of how to use this function, refer to the scsf_Spread3Chart function in the /ACS_Source/studies7.cpp file in the folder where Sierra Chart is installed to.

Example

SCString Chart1Name = sc.GetChartName(sc.ChartNumber);

sc.GetContainingIndexForDateTimeIndex()

Type: Function

int GetContainingIndexForDateTimeIndex(int ChartNumber, int DateTimeIndex);

sc.GetContainingIndexForDateTimeIndex() returns the index into the Base Data arrays of the chart specified by ChartNumber that contains the Date-Time at the index, on the chart your study function is applied to, specified by DateTimeIndex. If the Date-Time at DateTimeIndex is before any Date-Time in the chart specified with ChartNumber, then the index of the first element is given which will be 0. If the Date-Time at DateTimeIndex is after any Date-Time in the chart specified with ChartNumber , then the index of the last element is given which will be sc.ArraySize - 1.

Containing means that the chart bar starting Date-Time and ending Date-Time in ChartNumber contains the Date-Time specified by the DateTimeIndex parameter.

This function can be used on the sc.BaseData[] arrays for the same chart that your study function is applied to when searching for the Date-Time. To do this, pass sc.ChartNumber for the ChartNumber parameter.

If ChartNumber is given as a negative number, the bar period and other Chart Settings are synchronized between the two charts. If it is positive, this does not occur. For example, if you want to get the index from chart #5, and you want to synchronize the charts, then use -5 for the ChartNumber parameter.

Error Return Value

This function will return -1 if the chart it is referencing does not exist or its data is not fully loaded.

When the chart it is referencing is opened and fully loaded, then the study instance that made this call will be called again and will be fully recalculated. What actually happens in this case, is that the chart the reference was made from, will have all of its studies recalculated.

Example

// Get the index in the Base Data arrays for chart #2 that contains
// the Date-Time at the current Index of the chart that this study
// is applied to.

int Chart2Index = sc.GetContainingIndexForDateTimeIndex(2, sc.Index);

sc.GetContainingIndexForSCDateTime()

Type: Function

int GetContainingIndexForSCDateTime(int ChartNumber, SCDateTime DateTime);

sc.GetContainingIndexForSCDateTime() returns the index into the Base Data arrays of the chart specified by ChartNumber that contains DateTime . If DateTime is before any Date-Time in the chart specified with ChartNumber, then the index of the first element is given which is 0. If DateTime is after any Date-Time in the chart specified with ChartNumber , then the index of the last element is given which is sc.ArraySize - 1.

Containing means that the chart bar starting Date-Time and ending Date-Time in ChartNumber contains the Date-Time specified by the DateTime parameter.

This function can be used on the sc.BaseData[] arrays for the same chart that your study function is applied to when searching for the Date-Time. To do this, pass sc.ChartNumber for the ChartNumber parameter.

If ChartNumber is given as a negative number, the bar period and other Chart Settings are synchronized between the two charts. If it is positive, this does not occur. For example, if you want to get the index from chart #5, and you want to synchronize the charts, then use -5 for the ChartNumber parameter.

Error Return Value

This function will return -1 if the chart it is referencing does not exist or its data is not fully loaded.

When the chart it is referencing is opened and fully loaded, then the study instance that made this call will be called again and will be fully recalculated. What actually happens in this case, is that the chart the reference was made from, will have all of its studies recalculated.

Example

// Get the index in the Base Data arrays for chart #2 that contains the specified Date-Time.

SCDateTime DateTime = sc.BaseDateTimeIn[sc.Index];

int Chart2Index = sc.GetContainingIndexForSCDateTime(2, DateTime);

sc.GetCorrelationCoefficient()

Type: Intermediate Study Calculation Function

float GetCorrelationCoefficient(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, int Index, int Length);

float GetCorrelationCoefficient(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, int Length); Auto-looping only.

The sc.GetCorrelationCoefficient() function calculates the Pearson product-moment correlation coefficient from the data in the FloatArrayIn1 and FloatArrayIn2 arrays. The result is returned as a single float value.

Example

float coef = sc.GetCorrelationCoefficient(sc.Subgraph[0], sc.Subgraph[1], 10);

sc.GetCountDownText()

Type: Function

SCString GetCountDownText();

The sc.GetCountDownText() function gets the current countdown timer text for the chart.

Example

s_UseTool Tool;
Tool.Text.Format("%s",sc.GetCountDownText().GetChars());

sc.GetDepthBars()

Type: Function

c_ACSILDepthBars* GetDepthBars();

sc.GetDepthBars returns access to the historical market depth bars that are on the same chart that your custom study is applied to. The return value is a pointer to a c_ACSILDepthBars object, which has various functions for retrieving data from the historical market depth bars. See the c_ACSILDepthBars class for details.

sc.GetDepthBars should never return a null pointer, but it is still good practice to check to make sure the returned pointer is not null before using it.

sc.GetDepthBarsFromChart()

Type: Function

c_ACSILDepthBars* GetDepthBarsFromChart(int ChartNumber);

sc.GetDepthBarFromChrt returns access to the historical market depth bar from the chart that matches the given ChartNumber parameter. The return value is a pointer to a c_ACSILDepthBars object, which has various functions for retrieving data from the historical market depth bars. See the c_ACSILDepthBars class for details.

sc.GetDepthBarFromChrt should never return a null pointer, but it is still good practice to check to make sure the returned pointer is not null before using it.

Parameters:

  • ChartNumber: The number of the chart you want to get data from. This is the number that is shown on the top line in the Chart window, after the #. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.

sc.GetDispersion()

Type: Intermediate Study Calculation Function

float GetDispersion(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetDispersion(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetDispersion() function calculates the dispersion. The result is returned as a single float value.

Example

float Dispersion = sc.GetDispersion(sc.BaseDataIn[SC_HIGH], 10);

sc.GetEndingDateTimeForBarIndex()

Type: Function

double GetEndingDateTimeForBarIndex(int BarIndex);

The sc.GetEndingDateTimeForBarIndex function returns the ending Date-Time of a chart bar specified by its bar index. The chart bar index is specified with the BarIndex parameter.

This Date-Time is calculated for bars other than at the last bar in the chart. For the last bar in the chart, the ending date time is known precisely if the Global Settings >> Data/Trade Service Settings >> Intraday Data Storage Time Unit is 1 Tick or 1 Second Per Bar .

The chart Session Times are also used in the calculation where necessary. For example, if a chart bar is cut short because it has encountered the end of a specified Intraday session, the end of the session is used at the ending Date-Time for the bar.

sc.GetExactMatchForSCDateTime()

Type: Function

GetExactMatchForSCDateTime(int ChartNumber, SCDateTime DateTime);

sc.GetExactMatchForSCDateTime() returns the index into the Base Data arrays of the chart specified by ChartNumber that exactly matches the DateTime. If there is no exact match, this function returns -1.

This function can be used on the sc.BaseData[] arrays for the same chart that your study function is applied to when searching for the Date-Time. To do this, pass sc.ChartNumber for the ChartNumber parameter.

If ChartNumber is given as a negative number, the bar period and other Chart Settings are synchronized between the two charts. If it is positive, this does not occur. For example, if you want to get the index from chart #5, and you want to synchronize the charts, then use -5 for the ChartNumber parameter.

For complete information about the SCDateTime parameter type, refer to SCDateTime.

Example

// Get the index into the Base Data of chart #2
// that exactly matches the DateTime given through the Input 0

// Get the DateTime from Input 0
SCDateTime DateTime = sc.Input[0].GetDateTime();

int Chart2Index = sc.GetExactMatchForSCDateTime(2, DateTime);

if(Chart2Index != -1)
{
    //Your Code
}

sc.GetFirstIndexForDate()

Type: Function

int GetFirstIndexForDate(int ChartNumber, int Date);

The sc.GetFirstIndexForDate() function returns the first array index into the sc.BaseDateTimeIn[][] array for the specified ChartNumber where the given Date first occurs.

Example

FirstIndexOfReferenceDay = sc.GetFirstIndexForDate(sc.ChartNumber, ReferenceDay);

if (sc.GetTradingDayDate(sc.BaseDateTimeIn[FirstIndexOfReferenceDay]) == ReferenceDay)
    --InNumberOfDaysBack;

sc.GetHighest()

Type: Intermediate Study Calculation Function

float GetHighest(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetHighest(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetHighest() function returns the highest value over the specified Length in the FloatArrayIn array.

Example

//Get the highest high from the base graph over the last 20 bars
float Highest = sc.GetHighest(sc.BaseDataIn[SC_HIGH], 20);

//Get the highest value from sc.Subgraph[0] over the last 20 bars
Highest = sc.GetHighest(sc.Subgraph[0], 20);

sc.GetHighestChartNumberUsedInChartBook()

Type: Function

int GetHighestChartNumberUsedInChartBook();

The sc.GetHighestChartNumberUsedInChartBook function returns the highest Chart Number used in the Chartbook the chart the study function is applied to, belongs to.

Each chart has a number which is displayed on its title bar. This is its Chart Number for identification purposes.

sc.GetIndexOfHighestValue()

Type: Function

float GetIndexOfHighestValue(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetIndexOfHighestValue(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetIndexOfHighestValue() function returns the bar index of the highest value over the specified Length in the FloatArrayIn array.

sc.GetIndexOfLowestValue()

(SCFloatArrayRef In, int Length)

Type: Function

float GetIndexOfLowestValue(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetIndexOfLowestValue(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetIndexOfLowestValue() function returns the bar index of the lowest value over the specified Length in the FloatArrayIn array.

sc.GetIslandReversal()

Type: Intermediate Study Calculation Function

int GetIslandReversal(SCBaseDataRef BaseDataIn, int Index);

int GetIslandReversal(SCBaseDataRef BaseDataIn); Auto-looping only.

The sc.GetIslandReversal() function determines an Island Reversal. This function returns one of the following values:
0 = No Gap.
1 = Gap Up.
-1 = Gap Down.

Parameters:

Example

int IslandReversal = sc.GetIslandReversal(sc.BaseDataIn);

sc.GetLastPriceForTrading()

Type: Function

double GetLastPriceForTrading();

GetLastPriceForTrading returns the most current last trade price for the Symbol of the chart either from the connected data feed or from the last bar in the chart if the data feed price is 0 meaning it is not available.

This function also works during a chart replay.

Example

double LastPrice = sc.GetLastPriceForTrading();       
            

sc.GetLowest()

Type: Intermediate Study Calculation Function

float GetLowest(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetLowest(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetLowest() function returns the lowest value over the specified Length in the FloatArrayIn array.

Example

float Lowest = sc.GetLowest(sc.BaseDataIn[SC_LOW], 20);

Lowest = sc.GetLowest(sc.Subgraph[0], 20);

sc.GetMainGraphVisibleHighAndLow()

Type: Function

GetMainGraphVisibleHighAndLow (float& High, float& Low);

sc.GetMainGraphVisibleHighAndLow will get the highest High and lowest Low for the visible bars of the main price graph in the chart.

Example

float High, Low;

sc.GetMainGraphVisibleHighAndLow(High,Low);

sc.GetNearestMatchForDateTimeIndex()

Type: Function

int GetNearestMatchForDateTimeIndex(int ChartNumber, int DateTimeIndex);

sc.GetNearestMatchForDateTimeIndex() returns the index into the Base Data arrays of the chart specified by ChartNumber with the Date-Time closest to the Date-Time at the index specified by DateTimeIndex in the chart your study is applied to. If the Date-Time at DateTimeIndex is before any Date-Time in the specified chart, then the index of the first element is given (0). If the Date-Time at DateTimeIndex is after any Date-Time in the specified chart, then the index of the last element is given (sc.ArraySize - 1).

This function can be used on the sc.BaseData[] arrays for the same chart that your study function is applied to when searching for the Date-Time. To do this, pass sc.ChartNumber for the ChartNumber parameter.

If ChartNumber is given as a negative number, the bar period and other Chart Settings are synchronized between the two charts. If it is positive, this does not occur. For example, if you want to get the index from chart #5, and you want to synchronize the charts, then use -5 for the ChartNumber parameter.

Error Return Value

This function will return -1 if the chart it is referencing does not exist or its data is not fully loaded.

When the chart it is referencing is opened and fully loaded, then the study instance that made this call will be called again and will be fully recalculated. What actually happens in this case, is that the chart the reference was made from, will have all of its studies recalculated.

Matching Rules for a Nearest Date-Time Match

Refer to the Matching Rules for a Nearest Date-Time Match section.

Example

                // Get the index in the Base Data arrays for chart #2 that
// has the nearest matching Date-Time to the Date-Time
// at the current index being calculated for the chart that
// this study is on.

int Chart2Index = sc.GetNearestMatchForDateTimeIndex(2, sc.Index);

SCGraphData ReferenceArrays;
sc.GetChartBaseData(2, ReferenceArrays);

if (ReferenceArrays[SC_HIGH].GetArraySize() < 1)//Array is empty, nothing to do.

   return;

//Get the corresponding High 
float High = ReferenceArrays[SC_HIGH][Chart2Index];

sc.GetNearestMatchForSCDateTime()

Type: Function

int GetNearestMatchForSCDateTime(int ChartNumber, SCDateTime DateTime);

sc.GetNearestMatchForSCDateTime() returns the index into the Base Data arrays of the chart specified by ChartNumber with the Date-Time closest to the DateTime parameter. If the specified DateTime is before any Date-Time in the specified chart, then the index of the first element is given (0). If DateTime is after any Date-Time in the specified chart, then the index of the last element is given (sc.ArraySize - 1).

This function can be used on the sc.BaseData[] arrays for the same chart that your study function is applied to when searching for the Date-Time. To do this, pass sc.ChartNumber for the ChartNumber parameter.

If ChartNumber is given as a negative number, the bar period and other Chart Settings are synchronized between the two charts. If it is positive, this does not occur. For example, if you want to get the index from chart #5, and you want to synchronize the charts, then use -5 for the ChartNumber parameter.

For complete information about the SCDateTime parameter type, refer to SCDateTime.

Error Return Value

This function will return -1 if the chart it is referencing does not exist or its data is not fully loaded.

When the chart it is referencing is opened and fully loaded, then the study instance that made this call will be called again and will be fully recalculated. What actually happens in this case, is that the chart the reference was made from, will have all of its studies recalculated.

Matching Rules for a Nearest Date-Time Match

  1. If an exact match can be done, then the index with the exact match will be returned. If there are repeating timestamps, then the first index in the repeating times is given.
  2. If there is not an exact match, then the index of the nearest matching date-time is given.
  3. If the given date-time is equidistant between two date-times, then the index for the higher date-time is given.

Example

// Get the index in the Base Data arrays for chart #2 that
// has the nearest matching Date-Time to the given DateTime.

SCDateTime DateTime = sc.BaseDateTimeIn[sc.Index];

int Chart2Index = sc.GetNearestMatchForSCDateTime(2, DateTime);

SCGraphData ReferenceArrays;
sc.GetChartBaseData(2, ReferenceArrays);

if (ReferenceArrays[SC_HIGH].GetArraySize() < 1)//Array is empty, nothing to do.

   return;

//Get the corresponding High 
float High = ReferenceArrays[SC_HIGH][Chart2Index];

sc.GetNumberOfBaseGraphArrays()

Type: Function

int GetNumberOfBaseGraphArrays();

The sc.GetNumberOfBaseGraphArrays() function gets the number of arrays allocated in sc.BaseData[].

Example

int NumberOfBaseDataArrays = sc.GetNumberOfBaseGraphArrays();

sc.GetOHLCForDate()

Type: Function

GetOHLCForDate(double Date, float& Open, float& High, float& Low, float& Close);

The sc.GetOHLCForDate() function returns the Open, High, Low and Close of the period of time in an Intraday chart that is for the date specified by the Date parameter.

The Period of time is 1 Day. The starting and ending times are controlled by the Session Times settings in Chart >> Chart Settings for the Chart.

The end of the day is the time set by the End Time. The day includes the 24 hours prior to that time.

For efficiency, this function should only be called once a day while iterating through the chart bars in the study function. The values returned should be saved for the next iteration until a new day is encountered according to the Session Times.

Example

float Open;
float High;

float Low;
float Close;

sc.GetOHLCForDate(sc.BaseDateTimeIn[sc.ArraySize-1], Open, High, Low, Close);

SCString Message;
Message.Format("O: %f, H: %f, L: %f , C: %f",Open,High,Low,Close);

sc.AddMessageToLog(Message,1);

sc.GetOHLCOfTimePeriod()

Type: Function

int GetOHLCOfTimePeriod(SCDateTime StartDateTime, SCDateTime EndDateTime, float& Open, float& High, float& Low, float& Close, float& NextOpen);

sc.GetOHLCOfTimePeriod() returns the Open, High, Low, Close and NextOpen of the period of time in an Intraday chart specified by the StartDateTime and EndDateTime parameters.

Example

// In this example these are not set to anything. You will need to
// set them to the appropriate starting DateTime and ending DateTime
SCDateTime dt_StartTime, dt_EndTime;

float Open;
float High;
float Low;
float Close;

float NextOpen;

sc.GetOHLCOfTimePeriod( dt_StartTime, dt_EndTime, Open, High, Low, Close, NextOpen) ; 

sc.GetOpenHighLowCloseVolumeForDate()

int GetOpenHighLowCloseVolumeForDate(double Date, float& r_Open, float& r_High, float& r_Low, float& r_Close, float& r_Volume);

The sc.GetOpenHighLowCloseVolumeForDate function returns the Open, High, Low, Close and Volume values for the specified trading day Date.

This function is affected by the chart Session Times when determining the specific date-time range for these values.

This function returns 1 if it is successful or 0 if an error was encountered or the date is not found.

sc.GetPersistentInt()

sc.SetPersistentInt()

sc.GetPersistentFloat()

sc.SetPersistentFloat()

sc.GetPersistentDouble()

sc.SetPersistentDouble()

sc.GetPersistentInt64()

sc.SetPersistentInt64()

sc.GetPersistentSCDateTime()

sc.SetPersistentSCDateTime()

sc.GetPersistentPointer()

sc.SetPersistentPointer()

sc.GetPersistentSCString()

sc.SetPersistentSCString()

Type: Function

int& GetPersistentInt(int Key);

void SetPersistentInt(int Key, int Value);

float& GetPersistentFloat(int Key);

void SetPersistentFloat(int Key, float Value);

double& GetPersistentDouble(int Key);

void SetPersistentDouble(int Key, double Value);

__int64& GetPersistentInt64(int Key);

void SetPersistentInt64(int Key, __int64 Value);

SCDateTime& GetPersistentSCDateTime(int Key);

void SetPersistentSCDateTime(int Key, SCDateTime Value);

void*& GetPersistentPointer(int Key);

void SetPersistentPointer(int Key, void* Value);

SCString& GetPersistentSCString(int Key);

void SetPersistentSCString(int Key, SCString Value);

The above GetPersistent* functions are for getting a reference to a persistent variable identified by the Key parameter. The Key parameter is an integer.

The above SetPersistent* functions are for setting a value into a persistent variable identified by the Key parameter. The Key parameter is an integer.

Since the GetPersistent* functions return a reference to a persistent variable, usually this reference is what is used to set a value into the persistent variable and normally the SetPersistent* functions will not be used.

The following example code explains how to define a variable which holds a reference to the reference returned.

        int& Variable = sc.GetPersistentInt(1);
        

All of the basic data types that Sierra Chart works with are supported for persistent variables.

The Get/Set functions for SCDateTime can also be used to hold SCDateTimeMS values since the internal data type is a double.

The initial value for all persistent variables when they have not been previously set, is 0.

You may want to have the value in a variable remain persistent between calls to your study function. For example, when using Automatic-Looping (the default and recommended method of looping) your study function is called for every bar in the chart. If you want to have a variable retain its value between calls into your study function, then you need to use persistent variables.

For each data type, up to 5000 persistent variables are supported. You can use any Key value to identify these 5000 values. When the 5000 values have been exceeded, getting or setting a persistent variable with a new key which exceeds the limit will only set the internal dummy value which is not persistent.

The persistent variables remain persistent between calls to your study function. However, they are not saved when a Chartbook is saved and closed, or when Sierra Chart is closed. They are unique to each and every instance of your study.

Persistence of Persistent Variables: Persistent variables remain persistent until the study is removed from the chart or when a chart is closed either individually or when a Chartbook is closed that the chart is part of.

Therefore, when a study is added to a chart either through the Chart Studies window or through Study Collections, persistent variables are initially set to 0 for that study. When a chart that is saved as part of a chartbook is opened, all of the persistent variables for all of the studies on that chart, are set to 0.

If you want to have permanent storage that is saved when a Chartbook is saved, then you will need to use the sc.StorageBlock instead.

References to Persistent Variables: You can use references to give names to the persistent variables by defining new variables that refer to the persistent variables. This is helpful because it makes your code easier to understand and work with. This is demonstrated in the example below.

Also refer to sc.GetStudyPersistentIntFromChart().

// Use persistent variables to remember attached order IDs so they can be modified or canceled. 
int& Target1OrderID = sc.GetPersistentInt(1);
int& Stop1OrderID = sc.GetPersistentInt(2);

sc.SetPersistentFloat(1, 25.4f);
        

Resetting Persistent Variables Example

Usually you will want to reset persistent variables back to default values when a study is recalculated. This does not happen automatically and must be specifically programmed when there is an indication a study is being fully recalculated. This can be done by using the following code below.

if (sc.IsFullRecalculation)//This indicates a study is being recalculated.
{

    // When there is a full recalculation of the study,
    // reset the persistent variables we are using
    sc.GetPersistentInt(0) = 0;
    sc.GetPersistentInt(1) = 0;
    sc.GetPersistentInt(2) = 0;
    sc.GetPersistentInt(3) = 0;
}
        

sc.GetStudyDataColorArrayFromChartUsingID()

sc.GetStudyPersistentIntFromChart()

sc.GetStudyPersistentDoubleFromChart()

sc.GetStudyPersistentFloatFromChart()

sc.GetStudyPersistentIntFromChart()

sc.GetStudyPersistentInt64FromChart()

sc.GetStudyPersistentPointerFromChart()

sc.GetStudyPersistentSCDateTimeFromChart()

sc.GetStudyPersistentSCStringFromChart()

sc.SetStudyPersistentDoubleFromChart()

sc.SetStudyPersistentFloatFromChart()

sc.SetStudyPersistentIntFromChart()

sc.SetStudyPersistentInt64FromChart()

sc.SetStudyPersistentPointerFromChart()

sc.SetStudyPersistentSCDateTimeFromChart()

sc.SetStudyPersistentSCStringFromChart()

Type: Function

int& GetStudyPersistentIntFromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentIntFromChart(int ChartNumber, int StudyID, int Key, int Value);

float& GetStudyPersistentFloatFromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentFloatFromChart(int ChartNumber, int StudyID, int Key, float Value);

double& GetStudyPersistentDoubleFromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentDoubleFromChart(int ChartNumber, int StudyID, int Key, double Value);

__int64& GetStudyPersistentInt64FromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentInt64FromChart(int ChartNumber, int StudyID, int Key, __int64 Value);

SCDateTime& GetStudyPersistentSCDateTimeFromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentSCDateTimeFromChart(int ChartNumber, int StudyID, int Key, SCDateTime Value);

void*& GetStudyPersistentPointerFromChart(int ChartNumber, int StudyID, int Key);

void SetStudyPersistentPointerFromChart(int ChartNumber, int StudyID, int Key, void* Value);

The sc.GetStudyPersistent*FromChart and sc.SetStudyPersistent*FromChart functions are identical to the GetPersistent* and the SetPersistent* functions except that they will get and set a persistent variable from/for the study specified by the ChartNumber and StudyID parameters.

If the ChartNumber parameter is not valid, then an internal dummy variable is referenced with a value of zero and will not have the intended effect.

If setting or getting a persistent variable in another chart (Source chart), then when that Source chart is updated for any reason, the chart that made the reference to it, will have its studies calculated. In this way your study will be able to be aware of the changes to the persistent variable in a Source chart.

Refer to the code example below for usage.

SCSFExport scsf_GetStudyPersistentVariableFromChartExample(SCStudyInterfaceRef sc)
{
    SCInputRef  ChartStudyReference = sc.Input[0];

    if (sc.SetDefaults)
    {
        // Set the configuration and defaults

        sc.GraphName = "Get Study Persistent Variable from Chart Example";
        sc.AutoLoop = 1;
        sc.FreeDLL = 0;

        ChartStudyReference.Name = "Chart Study Reference";
        ChartStudyReference.SetChartStudyValues(1, 0);

        return;
    }

    //Get a reference to a persistent variable with key value 100 in the chart and study specified by the ChartStudyReference Input.
    float & FloatFromChartStudy =  sc.GetStudyPersistentFloatFromChart(ChartStudyReference.GetChartNumber(), ChartStudyReference.GetStudyID(), 100);
}
        

sc.GetStandardError()

Type: Intermediate Study Calculation Function

double GetStandardError(SCFloatArrayRef FloatArrayIn, int Index, int Length);

double GetStandardError(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetStandardError() function calculates the Standard Error. The result is returned as a double precision float value.

Example

double StandardErrorValue = sc.GetStandardError(sc.BaseDataIn[SC_LAST], Length.GetInt());

sc.GetStartDateTimeForTradingDate()

Type: Function

double GetStartDateTimeForTradingDate(int TradingDate);

The sc.GetStartDateTimeForTradingDate() function returns a Date-Time as a double which can be assigned to a SCDateTime variable, which is the starting Date and Time of the trading session that the given TradingDate is within. TradingDate is considered the date of the trading day independent of the actual date of trading. For example, trading during the evening session the day before next days Day session will have a TradingDate 1 day ahead of the actual date of trading. Therefore, if a trading session spans over midnight according to the Session Times of the chart the study is applied to, then the Date of the returned Date-Time will always be one less than the given TradingDate.

Example

SCDateTime TradingDate;
SCDateTime SessionStartDateTime = sc.GetStartDateTimeForTradingDate(TradingDate);

sc.GetStartOfPeriodForDateTime()

Type: Function

SCDateTime GetStartOfPeriodForDateTime(SCDateTime DateTime, unsigned int TimePeriodType, int TimePeriodLength, int PeriodOffset);

The sc.GetStartOfPeriodForDateTime() function gets the beginning of a time period of a length specified by the TimePeriodType and TimePeriodLength parameters, for a given Date-Time. The specified time length, will organize time into blocks of the specified length. For example, if the specified time length is 30 minutes, time will be organized this way, assuming the Session Times in Chart Setting use a Start Time that begins at the beginning of an hour: |9:30--------------|10:00--------------|10:30--------------. Given a DateTime with a time of 10:07, this function will return 10:00 and the Date of DateTime, since it falls within that section. The return type is an SCDateTime.

Parameters:

  • DateTime: The Date-Time value used to return the starting Date-Time of the time period that it is contained within.
  • TimePeriodType: The type of time period. This can be any of:
    • TIME_PERIOD_LENGTH_UNIT_MINUTES
    • TIME_PERIOD_LENGTH_UNIT_DAYS
    • TIME_PERIOD_LENGTH_UNIT_WEEKS
    • TIME_PERIOD_LENGTH_UNIT_MONTHS
    • TIME_PERIOD_LENGTH_UNIT_YEARS
  • TimePeriodLength: The number of units specified with TimePeriodType. For example if you want 1 Day, then you will set this to 1 and TimePeriodType to TIME_PERIOD_LENGTH_UNIT_DAYS.
  • PeriodOffset: This normally should be set to 0. When it is set to -1, the function will return the prior block of time which is before the block of time that DateTime is within. When it is set to +1, the function will return next block of time which is after the block of time that DateTime is within. Any positive or negative nonzero number can be used to shift the period forward or backward. For example, +2 will get 2 periods forward from the block of time that DateTime is within.

Example

For an example, refer to the scsf_PivotPointsVariablePeriod function in the /ACS_Source folder in the folder that Sierra Chart is installed to.

sc.GetStudyArray()

Type: Function

GetStudyArray(int StudyNumber, int StudySubgraphNumber, SCFloatArrayRef SubgraphArray);

It is recommended that you use the sc.GetStudyArrayUsingID function. It is a newer function which replaces this function.

sc.GetStudyArray() works similar to the sc.GetChartArray() function. It gets a sc.Subgraph[].Data array from another study on a chart. This way you can use the data from other studies on the same chart as your Advanced Custom Study function is on. The StudyNumber is 1-based, where 1 refers to the first study on the chart. If you specify 0 for StudyNumber, then this function will refer to the main price graph of the chart your study instance is applied to. The StudySubgraphNumber is 1-based and refers to a Subgraph of the study, where 1 is the first subgraph.

Refer to the scsf_GetStudyArrayExample() function in the studies.cpp file inside the ACS_Source folder inside of the Sierra Chart installation folder for example code to work with this function. When calling this function, it fills in the SubgraphArray parameter. If the function fails to get the requested study array for any reason, SubgraphArray will be empty and indicated by SubgraphArray.GetArraySize() equaling 0.

A reason you would want to access studies on a chart rather than internally calculating them and putting the results into sc.Subgraph[].Data[] or Extra Arrays, is so that you can see the studies on the chart and allow the inputs to be easily adjusted by the user. This saves memory and calculations if the studies that you are working with internally in your study are needed to be viewed on the chart anyway.

You need to set the Calculation Precedence to LOW_PREC_LEVEL, in the sc.SetDefaults code block when using this function. Otherwise, you may get an array that has a size of zero and is empty. By setting the calculation precedence to LOW_PREC_LEVEL, you ensure that your custom study will get calculated after other studies on the chart. This will ensure you get an array filled with up to date values.

Example

if (sc.SetDefaults)
{

    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    return;
}

SCFloatArray SubgraphArray;

// Get the third (3) Subgraph data array from the second (2) study
sc.GetStudyArray(2, 3, SubgraphArray);

if (SubgraphArray.GetArraySize() == 0)

    return; // The SubgraphArray may not exist or is empty. Either way we can not do anything with it.

sc.GetStudyArrayFromChart()

Type: Function

GetStudyArrayFromChart(int ChartNumber, int StudyNumber, int StudySubgraphNumber, SCFloatArrayRef SubgraphArray);

sc.GetStudyArrayFromChart() works identically to the sc.GetStudyArray() function, except that it will also access studies on another chart.

It is recommended to use the sc.GetStudyArrayFromChartUsingID study instead as it references a study by its unique ID, rather than the sc.GetStudyArrayFromChart() function.

Parameters:

  • ChartNumber: The number of the chart you want to get data from. This is the number that is shown on the top line in the Chart window, after the #. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • StudyNumber: The 1-based number for the study on the chart, where 1 refers to the first study on the specified chart. If you specify 0 for StudyNumber, then this function will refer to the main price graph of the chart.
  • StudySubgraphNumber: The 1-based number for the subgraph in the study, where 1 is the first Subgraph.
  • SubgraphArray: This will be filled in with the found data.

If the function is unable to get the subgraph array, the array's size will be zero (For example, SubgraphArray.GetArraySize() == 0).

One reason you may want to access a study from another chart is to use the results of a study which is calculated over a different time period per bar.

Example

SCFloatArray SubgraphArray;

// Get the subgraph number 3 data array from the study number 2 on chart number 1
sc.GetStudyArrayFromChart(1, 2, 3, SubgraphArray);

if (SubgraphArray.GetArraySize() == 0)
    return; // The SubgraphArray may not exist or is empty. Either way we can not do anything with it.

sc.GetStudyArrayFromChartUsingID()

Type: Function

void GetStudyArrayFromChartUsingID(const s_ChartStudySubgraphValues& ChartStudySubgraphValues, SCFloatArrayRef SubgraphArray);

The sc.GetStudyArrayFromChartUsingID() function gets a sc.Subgraph[].Data[] array from another study on another chart specified with the ChartStudySubgraphValues parameter. The array is set into the SubgraphArray parameter. This function works with the sc.Input[].GetChartStudySubgraphValues() input function.

Note: if ChartStudySubgraphValues.ChartNumber is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.

Example

SCInputRef StudySubgraphReference = sc.Input[0];

if (sc.SetDefaults)
{
    StudySubgraphReference.Name = "Study And Subgraph To Display";

    StudySubgraphReference.SetChartStudySubgraphValues(1,1, 0);
    return;
}

SCFloatArray StudyReference;
sc.GetStudyArrayFromChartUsingID(StudySubgraphReference.GetChartStudySubgraphValues(), StudyReference);

sc.GetStudyArrayUsingID()

Type: Function

int GetStudyArrayUsingID(unsigned int StudyID, unsigned int StudySubgraphIndex, SCFloatArrayRef SubgraphArray);

sc.GetStudyArrayUsingID() gets the specified sc.Subgraph[].Data array from a study using the study's unique identifier. These are studies that are on the same chart that your custom study is applied to.

If the study you are referencing is moved up or down in the list of Studies to Graph in the Chart Studies window for the chart, the reference still stays valid.

This function works with the sc.Input functions sc.Input[].SetStudyID() or sc.Input[].SetStudySubgraphValues and the related functions for getting the study ID and the study Subgraph values.

StudySubgraphIndex parameter: This is a 0 based index indicating which Subgraph to get from the study specified by StudyID.

Set the Calculation Precedence to LOW_PREC_LEVEL, in the sc.SetDefaults code block when using this function.

Otherwise, you may get an array that has a size of zero and is empty. By setting the calculation precedence to LOW_PREC_LEVEL, you ensure that the custom study will get calculated after other studies on the chart. This will ensure the study instance receives an array filled with up to date values.

When using this function or any of the ACSIL functions for getting a study array, it is possible to get the sc.Subgraph.Data[] arrays of a Spreadsheet study on the chart. This will allow you to get any of the formula columns data (K-Z and more depending upon the setting of the Number of Formula Columns input). Additionally, by using the appropriate formulas in the Spreadsheete formula columns, you are able to reference other data on the Spreadsheet by having those formula column formulas reference the particular cells that you need.

Return Value: Returns 1 on success or 0 if the StudyID is not found or the StudySubgraphIndex parameter is outside the valid range of subgraph indexes.

For an example, refer to the scsf_ReferenceStudyData function in the /ACS_Source/studies8.cpp file or to the scsf_StudySubgraphsDifference function in the /ACS_Source/studies5.cpp file which are located in the Sierra Chart installation folder.

Example

if(sc.SetDefaults)
{

    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    sc.Input[1].Name = "Study Reference";

    sc.Input[1].SetStudyID(1);
}
SCFloatArray StudyReference;

//Get the first (0) subgraph from the study the user has selected.

sc.GetStudyArrayUsingID(sc.Input[1].GetStudyID(),0,StudyReference);

//Copy the study data that we retrieved using the prior function call, into a subgraph data output array
sc.Subgraph[0][sc.Index]=StudyReference[sc.Index]; 

sc.GetStudyArraysFromChart()

Type: Function

GetStudyArraysFromChart(int ChartNumber, int StudyNumber, SCGraphData& GraphData);

sc.GetStudyArraysFromChart() is for getting all of the Subgraph arrays from a study on another chart or the same chart. A more up-to-date version of this function is the sc.GetStudyArraysFromChartUsingID() function.

One reason you may want to access a study from another chart is to use the results of a study which is calculated over a different time frame per bar.

Parameters:

  • ChartNumber: The number of the chart you want to get data from. This is the number that is shown on the top line in the Chart window, after the #. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • StudyNumber: This is 1-based, where 1 refers to the first study on the specified chart number. If you specify 0 for StudyNumber, then this function will refer to the main price graph of the chart.
  • GraphData: A SCGraphData object.

Example


int ChartNumber = 1;

// Get the study arrays from the first study in the specified chart
SCGraphData StudyData;
sc.GetStudyArraysFromChart(ChartNumber, 1, StudyData);

// Check if we got the data and then get the first subgraph array from the study data

if(StudyData.GetArraySize() == 0)
    return;

SCFloatArrayRef StudyArray = StudyData[0];

if(StudyArray.GetArraySize() == 0)

    return; 

sc.GetStudyArraysFromChartUsingID()

Type: Function

void GetStudyArraysFromChartUsingID(int ChartNumber, int StudyID, SCGraphData& GraphData);

The sc.GetStudyArraysFromChartUsingID() function gets all of the study arrays from the study specified by the ChartNumber and the unique StudyID parameters. The StudyID is the unique study ID and the best way to get that is through the sc.Input[].SetStudyID() and sc.Input[].GetStudyID() Input functions

Parameters:

  • ChartNumber: The number of the chart you want to get data from. This is the number that is shown on the top line in the Chart window, after the #. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • StudyID: The unique ID for the study you want to get data from.
  • GraphData: A SCGraphData object.

Example

 

// Define a graph data object to get all of the study data
SCGraphData StudyData;

// Get the study data from the specified chart
sc.GetStudyArraysFromChartUsingID(ChartStudyInput.GetChartNumber(), ChartStudyInput.GetStudyID(), StudyData);

//Check if the study has been found.  If it has, GetArraySize() will return the number of Subgraphs in the study.
if(StudyData.GetArraySize() == 0)
return;

// Define a reference to the first subgraph array
SCFloatArrayRef SubgraphArray = StudyData[0];

// Array is empty. Nothing to do.
if(SubgraphArray.GetArraySize() == 0)
return;

//Make a reference to the first study subgraph
SCFloatArrayRef Array1 = StudyData[0];

            

sc.GetStudyDataStartIndexUsingID()

Type: Function

int GetStudyDataStartIndexUsingID(unsigned int StudyID);

The sc.GetStudyDataStartIndexUsingID() function gets the sc.DataStartIndex value from another study on the same chart that your custom study is applied to, using the study's unique ID. This is for specialised purposes.

Example

SCInputRef StudyReference = sc.Input[0];

sc.DataStartIndex = sc.GetStudyDataStartIndexUsingID(StudyReference.GetStudyID());

sc.GetStudyExtraArrayFromChartUsingID()

Type: Function

int GetStudyExtraArrayFromChartUsingID(int ChartNumber, int StudyID, int SubgraphIndex, int ExtraArrayIndex, SCFloatArrayRef ExtraArrayRef);

The sc.GetStudyExtraArrayFromChartUsingID() function is used for getting one of the sc.Subgraph[].Arrays[][] on a sc.Subgraph from another study. This study can also be on another chart.

Example

       
SCFloatArray ExtraArrayFromChart ; 
sc.GetStudyExtraArrayFromChartUsingID(1, 1, 0, 0, ExtraArrayFromChart); 
if (ExtraArrayFromChart.GetArraySize()>0) 
{ 

}
            

sc.GetStudyName()

Type: Function

SCString GetStudyName(int StudyIndex);

sc.GetStudyName() returns the name of the study at the index StudyIndex.

sc.GetStudyNameFromChart()

Type: Function

SCString GetStudyNameFromChart(int ChartNumber, int StudyID);

The sc.GetStudyNameFromChart() function gets the name of the study identified by StudyID from the chart specified by ChartNumber. StudyID can be 0 to get the name of the underlying main graph of the chart.

Example

SCInputRef ChartStudySubgraphReference = sc.Input[4];

int ChartNumber = ChartStudySubgraphReference.GetChartNumber();
int StudyID = ChartStudySubgraphReference.GetStudyID();

SCString StudyName = sc.GetStudyNameFromChart(ChartNumber, StudyID);

sc.GetStudyNameUsingID()

Type: Function

SCString GetStudyNameUsingID(unsigned int StudyID);

The sc.GetStudyNameUsingID() function gets the name of a study on the same chart that your custom study is applied to, using the study's unique ID.

Example

SCInputRef StudyReference = sc.Input[3];

SCString StudyName = sc.GetStudyNameUsingID(StudyReference.GetStudyID());

sc.GraphName.Format("Avg of %s", StudyName);

sc.GetStudyPersistentVariablesFromChartUsingID()

Type: Function

s_PersistentVariables const* GetStudyPersistentVariablesFromChartUsingID(int ChartNumber, int StudyID);

The sc.GetStudyPersistentVariablesFromChartUsingID() function gets the persistent variables structure from another study on the same or different chart within the same chartbook.

ChartNumber can be obtained by using the sc.Input[].SetChartNumber() and sc.Input[].GetChartNumber() Input functions.

StudyID can be obtained by using the sc.Input[].SetStudyID() and sc.Input[].GetStudyID() functions.

When you get persistent variables from another chart, this establishes a reference between the charts. The chart that you get the persistent variables from is known as the Source chart. If the Source chart data changes, the Destination chart, or the chart that is getting the persistent variables, will be tagged for an update and will be updated and calculated. When running a multiple chart back test, charts will be calculated in the proper order as well.

Example

const s_sc::s_PersistentVariables * p_PersistVars = sc.GetStudyPersistentVariablesFromChartUsingID(ChartNumber, StudyID);
// Only use the returned pointer if it is not NULL
if (p_PersistVars)
{

    //...

}

sc.GetSummation()

Type: Intermediate Study Calculation Function

float GetSummation(SCFloatArrayRef FloatArrayIn, int Index, int Length);

float GetSummation(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.GetSummation() function calculates the sum of the values in FloatArrayIn over the specified Length. The result is returned as a single float value.

Example

float Summation = sc.GetSummation(sc.BaseDataIn[SC_LAST],sc.Index,10);

sc.GetTimeAndSales()

Type: Function

GetTimeAndSales(SCTimeAndSalesArray& TSArray);

sc.GetTimeAndSales() gets the Time and Sales data for the symbol of the chart that the study is on. This function returns an array of s_TimeAndSales structure.

This data also includes Bid and Ask price and size/quantity updates as well.

Refer to any of the following functions in the folder Sierra Chart is installed to for an example to work with the sc.GetTimeAndSales function:

Type is a member of the s_TimeAndSales structure. Refer to the list below for each of the possible constants that Type can be set to:

  1. SC_TS_MARKER: This indicates a gap in the time and sales data.
  2. SC_TS_BID: This is a trade and it is considered to have occurred at Bid price or lower.
  3. SC_TS_ASK: This is a trade and it is considered to have occurred at Ask price or higher.
  4. SC_TS_BIDASKVALUES: This is a Bid and Ask quote data update only.

For the definition of the s_TimeAndSales structure, refer to the /ACS_Source/sierrachart.h file in the Sierra Chart installation folder.

This function also gets all Bid, Ask, Bid Size, and Ask Size data received from the data feed.

For Time and Sales related settings, select Global Settings >> Data/Trade Service Settings on the menu. You are able to set the number of time and sales records to maintain. This setting controls the maximum Time and Sales records you will receive when calling sc.GetTimeAndSales.

After changing this setting, you need to reconnect to the data feed using the Disconnect and Connect commands on the File menu. You will only be able to get Time and Sales data when there is active trading activity for a symbol. It is only maintained during a Sierra Chart session. When you restart Sierra Chart, it is lost.

Every Time and Sales record has a unique sequence number (s_TimeAndSales::Sequence member). This number is not reset when reconnecting to the data feed. The only time it is reset back to 1, is when Sierra Chart is restarted. In that case, Time and Sales data is lost. This unique sequence number is used to determine what Time and Sales records the study function has already processed and what records it needs to process.

In the case of a Chart Replay the record sequence number is reset back to 1 when the replay is started and any other time the chart is reloaded which can occur if the chart is scrolled back in time and the replay is started again.

If the last record sequence number available during the prior call to your function was 100, then only records after that number will your study function need to process. You can store the last sequence number processed by using the sc.GetPersistentInt() function, in order to know it on the next call into your function.

For a particular symbol, the Time and Sales sequence numbers are not necessarily consecutive. There can be skipped sequence numbers. However, the sequence number will always ascend.

If you require your study function to be aware of every new tick/trade as it occurs, then you will want to use the sc.GetTimeAndSales function to get all of the trades that occurred between calls to your study function. Your study function is not called at every trade, rather instead at the Chart Update Interval. The Chart Update Interval is set through Global Settings >> General Settings. You might want to reduce that setting in this particular case.

The DateTime member of the s_TimeAndSales data structure is in UTC time. The below code example shows how to adjust it to the time zone in Sierra Chart.

Example

 
// Get the Time and Sales
SCTimeAndSalesArray TimeSales;
sc.GetTimeAndSales(TimeSales);

if (TimeSales.Size() == 0)
    return;  // No Time and Sales data available for the symbol

// Loop through the Time and Sales
int OutputArrayIndex = sc.ArraySize;
for (int TSIndex = TimeSales.Size() - 1; TSIndex >= 0; --TSIndex)
{
    //Adjust timestamps to Sierra Chart TimeZone
    SCDateTime AdjustedDateTime = TimeSales[TSIndex].DateTime;
    AdjustedDateTime += sc.TimeScaleAdjustment;
}
            

Alternative Way For Obtaining Time and Sales Data

Open a chart that is set to 1 Number of Trades Per Bar for the symbol you want Time and Sales for.

Select Global Settings >> Data/Trade Service Settings and make sure the Intraday Data Storage Time Unit is set to 1 Tick.

Use the sc.GetChartArray and the sc.GetChartDateTimeArray functions to access the price, volume and DateTime arrays. Every element in these arrays is 1 trade. This may actually be a preferred way of accessing trade by trade data since there will be an abundant amount of history available.

Total Bid and Ask Depth Data

The s_TimeAndSales data structure also contains the s_TimeAndSales::TotalBidDepth and the s_TimeAndSales::TotalAskDepth members.

These members are only set when s_TimeAndSales::Type is set to the constant SC_TS_BIDASKVALUES which means that the Time and Sales record contains a Bid and Ask quote update.

The s_TimeAndSales::TotalBidDepth and s_TimeAndSales::TotalAskDepth members are set to the total of the Bid Sizes/Quantities and Ask Sizes/Quantities, respectively for all of the market depth levels available for the symbol.

If there are no market depth features being used in Sierra Chart or the ACSIL function has not set sc.UsesMarketDepthData to a nonzero value, then market depth data usually is not being received and maintained for the symbol. Therefore, these members will equal the best Bid Size and Ask Size, respectively at each record with a s_TimeAndSales::Type set to SC_TS_BIDASKVALUES.

sc.GetTimeAndSalesForSymbol()

Type: Function

int GetTimeAndSalesForSymbol(const SCString& Symbol, SCTimeAndSalesArray& TSArray);

The sc.GetTimeAndSalesForSymbol function is identical to sc.GetTimeAndSales except that it has a Symbol parameter allowing the study to get Time and Sales data for a different symbol.

Refer to the documentation for sc.GetTimeAndSales for the documentation for this function.

sc.GetTradeStatisticsForSymbol()

Type: Function

int GetTradeStatisticsForSymbol(int Unused, int DailyStats, s_ACSTradeStatistics & TradeStats);

The sc.GetTradeStatisticsForSymbol() function obtains the trade statistics for the symbol of the chart that the study is applied to.

The trade statistics are calculated in the internal Trades list in the chart which references all of the available order fills in the Trade >> Trade Activity Log for the particular Symbol and Trade Account set in the chart.

In order for this function to work properly, there needs to be a Trades list being maintained in the chart the study is applied to. Therefore, it is necessary to set sc.MaintainTradeStatisticsAndTradesData = TRUE in the sc.SetDefaults section of the study function when using sc.GetTradeStatisticsForSymbol.

When the Trade >> Trade Simulation Mode On setting is enabled, then the trade statistics will be for simulated trading. When the Trade >> Trade Simulation Mode On setting is disabled, then the trade statistics will be for non-simulated trading.

Parameters

  • Unused: Not currently used.
  • DailyStats: Set this to TRUE to get the statistics for the current trading day. Otherwise, trade statistics will cover all available Order Fill data in the Trade >> Trade Activity Log. The beginning time for the current trading day is set by Global Settings >> General Trade Settings >> Daily Stats Reset Time.
  • TradeStats: The passed s_ACSTradeStatistics structure is filled with the requested Trade Statistics data. The Trade Statistics values can then be retrieved from either the provided fields or the provided functions that calculate values from the other data. Refer to s_ACSTradeStatistics for defintion of the structures fields and functions.

s_ACSTradeStatistics Structure Members

All Trade Statistics are calculated for all of the Order Fills in the requested period. All break even trades are counted as winning trades.

[Type: double] ClosedProfitLoss()

Total Closed Profit and Loss across all closed trades.

[Type: double] ClosedProfit

Total Closed Profit across all winning trades.

[Type: double] ClosedLoss

Total Closed Loss across all losing trades.

[Type: double] ProfitFactor()

Ratio of Closed Profit to Closed Loss

[Type: double] TotalCommission

Total Commissions across all trades. This currently does not apply.

[Type: double] MaximumRunup

Highest net equity value across all trades (includes open profit/loss).

[Type: double] MaximumDrawdown

Lowest net equity value across all trades (includes open profit/loss).

[Type: double] MaximumTradeRunup

Largest single trade runup across all trades. For fill-to-fill trade matching, this is the same as MaximumOpenPositionProfit.

[Type: double] MaximumTradeDrawdown

Largest single trade drawdown across all trades. For fill-to-fill trade matching, this is the same as MaximumOpenPositionLoss.

[Type: double] MaximumOpenPositionProfit

Largest single trade open position profit across all trades. Also known as Maximum Favorable Excursion.

[Type: double] MaximumOpenPositionLoss

Largest single trade open position loss across all trades. Also known as Maximum Adverse Excursion.

[Type: int] TotalTrades()

Total number of trades.

[Type: int] TotalWinningTrades

Total number of winning trades, includes break-even trades.

[Type: int] TotalLosingTrades

Total number of losing trades.

[Type: double] TotalPercentProfitable()

Ratio of number of winning trades over total number of trades.

[Type: int] TotalLongTrades

Total number of long trades.

[Type: int] TotalShortTrades

Total number of losing trades.

[Type: int] TotalClosedQuantity()

Total quanity traded for all closed trades.

[Type: int] TotalWinningQuantity

Total quantiy traded for all winning trades.

[Type: int] TotalLosingQuantity

Total quantity traded for all losing trades.

[Type: int] TotalFilledQuantity

Total filled quantity for all trades. This quantity includes both sides of the trade.

[Type: int] LargestTradeQuantity

The largest trade quantity across all individual trades.

[Type: double] AvgQuantityPerTrade()

Average quantity per trade across all trades.

[Type: double] AvgQuantityPerWinningTrade()

average quantity per winning trade.

[Type: double] AvgQuantityPerLosingTrade()

Average quantity per losing trade.

[Type: double] AvgProfitLoss()

Average profit loss per trade.

[Type: double] AvgProfit()

Average profit per winning trade.

[Type: double] AvgLoss()

Average loss per losing trade.

[Type: double] AvgProfitFactor()

Ratio of average profit per trade to average loss per trade.

[Type: double] LargestWinningTrade

Profit for single largest winning trade.

[Type: double] LargestLosingTrade

Loss for single largest losing trade.

[Type: double] LargestWinnerPercentOfProfit()

Ratio of largest winning trade profit to the total closed profit.

[Type: double] LargestLoserPercentOfLoss()

Ratio of largest losing trade loss to the total closed loss

[Type: int] TimeInTrades()

Total seconds in all trades.

[Type: int] TimeInWinningTrades

Total seconds in all winning trades.

[Type: int] TimeInLosingTrades

Total seconds in all losing trades.

[Type: int] AvgTimeInTrade()

Average time in seconds per trade.

[Type: int] AvgTimeInWinningTrade()

Average time in seconds per winning trade.

[Type: int] AvgTimeInLosingTrade()

Average time in seconds per losing trade.

[Type: int] MaxConsecutiveWinners()

Maximum number of consecutive winning trades.

[Type: int] MaxConsecutiveLosers()

Maximum number of consecutive losing trades.

sc.GetTradingDayStartDateTimeOfBar()

Type: Function

SCDateTime GetTradingDayStartDateTimeOfBar(SCDateTime& BarDateTime);

The sc.GetTradingDayStartDateTimeOfBar() function will return the starting Date-Time of the trading day given a SCDateTime variable. Typically this will be the Date-Time of a bar. The starting Date-Time is based upon the Intraday Session Times settings for the chart.

For an example, refer to the function scsf_CumulativeSumOfStudy in the /ACS_Source/studies8.cpp file in the folder Sierra Chart is installed to.

Parameters:

  • BarDateTime: A SCDateTime variable.

sc.GetTrueHigh()

Type: Intermediate Study Calculation Function

float GetTrueHigh(SCBaseDataRef BaseDataIn, int Index);

float GetTrueHigh(SCBaseDataRef BaseDataIn); Auto-looping only.

The sc.GetTrueHigh() function calculates the True High of a bar. The result is returned as a single float value. The True High is either the high of the bar at Index or the close of the prior bar, whichever is higher.

Parameters:

Example

float TrueHigh = sc.GetTrueHigh(sc.BaseDataIn);

sc.GetTrueLow()

Type: Intermediate Study Calculation Function

float GetTrueLow(SCBaseDataRef BaseDataIn, int Index);

float GetTrueLow(SCBaseDataRef BaseDataIn); Auto-looping only.

The sc.GetTrueLow() function calculates the True Low of a bar. The result is returned as a single float value. The True Low is either the low of the bar at Index or the close of the prior bar. Whichever is lower.

Parameters:

Example

float TrueLow = sc.GetTrueLow(sc.BaseDataIn);

sc.GetTrueRange()

Type: Intermediate Study Calculation Function

float GetTrueRange(SCBaseDataRef BaseDataIn, int Index);

float GetTrueRange(SCBaseDataRef BaseDataIn); Auto-looping only.

The sc.GetTrueRange() function calculates the True Range of a bar at Index. The result is returned as a single float value.

Parameters:

Example

float TrueRange = sc.GetTrueRange(sc.BaseDataIn);

sc.HeikinAshi()

Type: Function

void HeikinAshi(SCBaseDataRef BaseDataIn, SCSubgraphRef HeikinAshiOut, int Index, int Length, int SetCloseToCurrentPriceAtLastBar);

void HeikinAshi(SCBaseDataRef BaseDataIn, SCSubgraphRef HeikinAshiOut, int Length, int SetCloseToCurrentPriceAtLastBar); Auto-looping only.

Parameters:

  • BaseDataIn
  • HeikinAshiOut. For this function, sc.Subgraph[].Arrays[0-2] (Extra Arrays) are used for additional results output. HeikinAshiOut.Data is the Open price array. HeikinAshiOut.Arrays[0] is the High price array. HeikinAshiOut.Arrays[1] is the Low price array. HeikinAshiOut.Arrays[2] is the Last/Close price array.
  • Index
  • Length
  • SetCloseToCurrentPriceAtLastBar: When this is set to a nonzero value, then the last/close price of the last Heikin-Ashi bar is set to the current price of the underlying data.

sc.Highest()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Highest(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef Highest(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.Highest() function calculates the highest value of the data in FloatArrayIn over the specified Length beginning at Index. The result is put into the FloatArrayOut array.

Example

sc.Highest(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], 20);

float Highest = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.HullMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef HullMovingAverage (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef HullMovingAverage (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.HullMovingAverage() function calculates the Hull Moving Average study.

Parameters:

Example

sc.HullMovingAverage(sc.BaseData[SC_LAST], sc.Subgraph[0], 10);

float HullMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.IsChartDataLoadingInChartbook()

Type: Function

int IsChartDataLoadingInChartbook();

The sc.IsChartDataLoadingInChartbook() function returns 1 when it is called and an Intraday chart is loading data in the same Chartbook that the chart belongs to that the study instance is applied to. So this can be during the time the Chartbook is in the process of being opened or at any time after. An example of an intraday chart loading data would be when certain chart settings are changed through Chart >> Chart Settings.

If none of the Intraday charts are loading data within the Chartbook, then the return value is 0.

sc.IsDateTimeContainedInBarIndex()

Type: Function

int IsDateTimeContainedInBarIndex(const SCDateTime& DateTime, int BarIndex) const;

sc.IsDateTimeInDaySession()

Type: Function

int IsDateTimeInDaySession(const SCDateTime& DateTime);

The sc.IsDateTimeInDaySession() function returns TRUE (non-zero value) or FALSE indicating whether the given DateTime is within the Day Session Times in Chart >> Chart Settings. DateTime is a SCDateTime type.

Example

int IsInDaySession = sc.IsDateTimeInDaySession(sc.BaseDateTimeIn[sc.Index]+ 1*HOURS);

sc.IsDateTimeInSession()

Type: Function

int IsDateTimeInSession(const SCDateTime& DateTime);

The sc.IsDateTimeInSession() function returns TRUE (non-zero value) or FALSE indicating whether the given DateTime is within the Session Times in Chart >> Chart Settings. DateTime is a SCDateTime type.

Example

int IsInSession = sc.IsDateTimeInSession(sc.BaseDateTimeIn[sc.Index]+ 1*HOURS);

sc.IsMarketDepthDataCurrentlyAvailable()

Type: Function

int IsMarketDepthDataCurrentlyAvailable()

The sc.IsMarketDepthDataCurrentlyAvailable function returns 1 when the sc.SymbolData->BidDOM and sc.SymbolData->AskDOM contain market depth data at levels 1 and 2. This is an indication that market depth data is currently available in those arrays.

For additional information, refer to sc.SymbolData.

sc.IsReplayRunning()

Type: Function

int IsReplayRunning()

sc.IsReplayRunning() returns TRUE (1) if a replay is running, otherwise it returns FALSE (0).

Example

int ReplayRunning = sc.IsReplayRunning();

sc.IsSwingHigh()

Type: Intermediate Study Calculation Function

int IsSwingHigh (SCFloatArrayRef FloatArrayIn, int Index, int Length);

int IsSwingHigh (SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.IsSwingHigh() function returns TRUE (1) if there is a Swing High. Otherwise, it returns FALSE (0).

Example

int SwingHigh = sc.IsSwingHigh(sc.BaseData[SC_HIGH],2);

sc.IsSwingLow()

Type: Intermediate Study Calculation Function

int IsSwingLow (SCFloatArrayRef FloatArrayIn, int Index, int Length);

int IsSwingLow (SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.IsSwingLow() function returns TRUE (1) if there is a Swing Low. Otherwise, it returns FALSE (0).

Example

int SwingLow = sc.IsSwingLow(sc.BaseData[SC_LOW],2);

sc.Keltner()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Keltner(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayIn, SCSubgrapRef SubgraphOut, int Index, int KeltnerMovAvgLength, unsigned int KeltnerMovAvgType, int TrueRangeMovAvgLength, unsigned int TrueRangeMovAvgType, float TopBandMultiplier, float BottomBandMultiplier);

SCFloatArrayRef Keltner(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayIn, SCSubgrapRef SubgraphOut, int KeltnerMovAvgLength, unsigned int KeltnerMovAvgType, int TrueRangeMovAvgLength, unsigned int TrueRangeMovAvgType, float TopBandMultiplier, float BottomBandMultiplier); Auto-looping only.

The sc.Keltner() function calculates the Keltner study.

Parameters:

Example

sc.Keltner(
    sc.BaseDataIn,

    sc.BaseDataIn[SC_LAST],
    sc.Subgraph[0],
    10,

    MOVAVGTYPE_SIMPLE,
    10,
    MOVAVGTYPE_WILDERS,
    1.8f,
    1.8f,
);

//Access the individual Keltner lines
float KeltnerAverageOut = sc.Subgraph[0][sc.Index];

float TopBandOut = sc.Subgraph[0].Arrays[0][sc.Index];

float BottomBandOut = sc.Subgraph[0].Arrays[1][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = TopBandOut;
sc.Subgraph[2][sc.Index] = BottomBandOut; 

sc.LinearRegressionIndicator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef LinearRegressionIndicator(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef LinearRegressionIndicator(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.LinearRegressionIndicator() function calculates the linear regression indicator study.

Example

sc.LinearRegressionIndicator(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float LinearRegression = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.ChartDrawingExists()

Type: Function

For more information, refer to the sc.ChartDrawingExists() section on the Using Tools From an Advanced Custom Study page.

sc.Lowest()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Lowest(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef Lowest(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.Lowest() function calculates the lowest value of the data in FloatArrayIn over the specified Length beginning at Index. The result is put into the FloatArrayOut array.

Example

sc.Lowest(sc.BaseDataIn[SC_LOW], sc.Subgraph[0], 20);

float Lowest = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.MACD()

Type: Intermediate Study Calculation Function.

SCFloatArrayRef sc.MACD (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int FastMALength, int SlowMALength, int MACDMALength, int MovAvgType);

SCFloatArrayRef sc.MACD (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int FastMALength, int SlowMALength, int MACDMALength, int MovAvgType); Auto-looping only.

The sc.MACD() function calculates the standard Moving Average Convergence Divergence study.

Parameters:

Example

sc.MACD(sc.BaseData[SC_LAST], sc.Subgraph[0], 5, 10, 10, MOVAVGTYPE_SIMPLE);

//Access the individual lines
float MACD = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

float MACDMovingAverage = sc.Subgraph[0].Arrays[2][sc.Index];

float MACDDifference = sc.Subgraph[0].Arrays[3][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = MACDMovingAverage;
sc.Subgraph[2][sc.Index] = MACDDifference;

sc.MakeHTTPRequest()

Type: Function

int MakeHTTPRequest(const SCString& URL);

The sc.MakeHTTPRequest() function makes a website/HTTP request over the network. The website address and the file to request are contained in the URL parameter. The URL parameter needs to contain the website address and the file to retrieve. Standard HTTP GET parameters can also be added.

This function is nonblocking and immediately returns.

When the request is complete, the response will be placed into the sc.HTTPResponse SCString member. At the time the request is complete, the study instance which made the request will be called and at that time the sc.HTTPResponse member can be checked.

If there is an error with making the request to the remote server or the server returns an error, sc.HTTPResponse will be set to "ERROR".

Returns 1 if successful. Returns 0 on error.

If sc.MakeHTTPRequest returns 0, then sc.HTTPResponse will be set to "HTTP_REQUEST_ERROR". Otherwise, sc.HTTPResponse will be set to an empty string after calling the sc.MakeHTTPRequest function and sc.HTTPResponse will be set to the response from the server when the server later responds after the study function returns.

It is only supported to make one request at a time. The current request must finish before another one can be made.

Example

enum {REQUEST_NOT_SENT = 0,  REQUEST_SENT, REQUEST_RECEIVED};
int& RequestState = sc.GetPersistentInt(1);

if (sc.Index == 0)
{
    if (RequestState == REQUEST_NOT_SENT)
    {
        // Make a request for a text file on the server. When the request is complete and all of the data
        //has been downloaded, this study function will be called with the file placed into the sc.HTTPResponse character string array.

        if (!sc.MakeHTTPRequest("http://www.sierrachart.com/ACSILHTTPTest.txt"))
        {
            sc.AddMessageToLog("Error making HTTP request.", 1);
            
            // Indicate that the request was not sent. 
            // Therefore, it can be made again when sc.Index equals 0.
            RequestState = REQUEST_NOT_SENT;
        }
        else
            RequestState = REQUEST_SENT;
    }
}

if (RequestState == REQUEST_SENT && sc.HTTPResponse != "")
{
    RequestState = REQUEST_RECEIVED;

    // Display the response from the Web server in the Message Log

    sc.AddMessageToLog(sc.HTTPResponse, 1); 
}
else if (RequestState == REQUEST_SENT && sc.HTTPResponse == "")
{
    //The request has not completed, therefore there is nothing to do so we will return
    return;
}
            

sc.Momentum()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Momentum(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);
SCFloatArrayRef Momentum(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.Momentum() function calculates the momentum.

Example

sc.Momentum(sc.BaseDataIn[SC_LAST], sc.Subgraph[0].Arrays[0], 20);

float Momentum = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.MovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef MovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, unsigned int MovingAverageType, int Index, int Length);

SCFloatArrayRef MovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, unsigned int MovingAverageType, int Length); Auto-looping only.

The sc.MovingAverage() function calculates a Moving Average of the specified Type and Length.

Example

sc.MovingAverage(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], MOVAVGTYPE_SIMPLE, 20);

float MovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.MovingMedian()

Type: Function

SCFloatArrayRef MovingMedian(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef MovingMedian(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length);

The sc.MovingMedian() function calculates the Moving Median study of the specified Length.

Example

SCSubgraphRef Median = sc.Subgraph[0];

SCInputRef InputData = sc.Input[0];
SCInputRef Length = sc.Input[1];
SCFloatArrayRef In = sc.BaseDataIn[InputData.GetInputDataIndex()];

sc.MovingMedian(In, Median,  Length.GetInt());

sc.NumberOfBarsSinceHighestValue()

Type: Intermediate Study Calculation Function

int NumberOfBarsSinceHighestValue (SCFloatArrayRef FloatArrayIn, int Index, int Length);

int NumberOfBarsSinceHighestValue (SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.NumberOfBarsSinceHighestValue() function calculates the number of bars between the highest value in the FloatArrayIn array, which is determined over the specified Length, and the Index element of the FloatArrayIn array. The highest value is calculated over the range from Index to Index-Length+1.

Example

int NumBars = sc.NumberOfBarsSinceHighestValue(sc.BaseDataIn[SC_LAST],  10);

sc.NumberOfBarsSinceLowestValue()

Type: Intermediate Study Calculation Function

int NumberOfBarsSinceLowestValue (SCFloatArrayRef FloatArrayIn, int Index, int Length);

int NumberOfBarsSinceLowestValue (SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

The sc.NumberOfBarsSinceLowestValue() function calculates the number of bars between the lowest value in the FloatArrayIn array, which is determined over the specified Length, and the Index element of the FloatArrayIn array. The lowest value is calculated over the range from Index to Index-Length+1.

Example

int NumBars = sc.NumberOfBarsSinceLowestValue(sc.BaseDataIn[SC_LAST],  10);

sc.OnBalanceVolume()

Type: Intermediate Study Calculation Function

SCFloatArrayRef OnBalanceVolume (SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef OnBalanceVolume (SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.OnBalanceVolume() function calculates the On Balance Volume study.

Example

sc.OnBalanceVolume(sc.BaseDataIn, sc.Subgraph[0]);

float OnBalanceVolume = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.OnBalanceVolumeShortTerm()

Type: Intermediate Study Calculation Function

SCFloatArrayRef OnBalanceVolumeShortTerm(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef OnBalanceVolumeShortTerm(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.OnBalanceVolumeShortTerm() function calculates the On Balance Volume Short Term study.

Example

sc.OnBalanceVolumeShortTerm(sc.BaseDataIn, sc.Subgraph[0], 20);

float ShortTermOnBalanceVolume = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.OpenChartOrGetChartReference()

Type: Function

int OpenChartOrGetChartReference(s_ACSOpenChartParameters & ACSOpenChartParameters);

The sc.OpenChartOrGetChartReference function returns the Chart Number of a chart matching a given set of parameters if there is already an open chart within the Chartbook that contains the study calling the sc.OpenChartOrGetChartReference function, that matches all of the given set of parameters. In this case the Chart Number of that chart will be returned.

Otherwise, a new chart will be automatically opened with the given set of parameters, and the Chart Number of the new chart will be returned.

If there is an error encountered within the function, the function return value will be 0.

For an example to use this function, refer to the scsf_OpenChartOrGetChartReferenceExample function in the /ACS_Source/studies.cpp file located in the Sierra Chart installation folder on your system.

If the chart that has been automatically opened with this function, does not need to be viewed, then its window can be minimized to prevent any graphics output which eliminates the CPU load related to graphics output.

After you obtain the Chart Number with this function, then you can access the data from this chart with the sc.GetChartBaseData() function.

For efficiency, only call the sc.OpenChartOrGetChartReference function when sc.IsFullRecalculation is nonzero.

Parameters:

The parameters of the requested chart are specified using the s_ACSOpenChartParameters structure. This structure contains the following parameters:

  • PriorChartNumber: This is the first parameter that gets checked. If the sc.OpenChartOrGetChartReference function has been called at least once before, remember the Chart Number that gets returned, and set it into this parameter. This allows for a more efficient lookup. Set this parameter to 0 if the Chart Number is unknown.
  • ChartDataType: Set this to DAILY_DATA for a Historical Daily data chart, or INTRADAY_DATA for an Intraday data chart.
  • Symbol: Set this to the symbol for the requested chart. The symbol must be in the format required by the selected Service in Global Settings >> Data/Trade Service Settings.

    These will be the same symbols that you will see listed in File >> Find Symbol.

    When you need to use the Symbol of the chart the study function is on, the easiest way to get the correct symbol is to use the sc.Symbol ACSIL structure member.
  • IntradayBarPeriodType: This is used for an Intraday chart and sets the period/type of the chart bar. Must be one of the below values. It is also necessary to set the actual associated value through the IntradayBarPeriodLength member.
    • IBPT_DAYS_MINS_SECS : Specify the time length in seconds through IntradayBarPeriodLength.
    • IBPT_VOLUME_PER_BAR
    • IBPT_NUM_TRADES_PER_BAR : The number of trades per bar.
    • IBPT_RANGE_IN_TICKS_STANDARD
    • IBPT_RANGE_IN_TICKS_NEWBAR_ON_RANGEMET
    • IBPT_RANGE_IN_TICKS_TRUE
    • IBPT_RANGE_IN_TICKS_FILL_GAPS
    • IBPT_REVERSAL_IN_TICKS
    • IBPT_RENKO_IN_TICKS
    • IBPT_DELTA_VOLUME_PER_BAR
    • IBPT_FLEX_RENKO_IN_TICKS
    • IBPT_RANGE_IN_TICKS_OPEN_EQUAL_CLOSE
    • IBPT_PRICE_CHANGES_PER_BAR
    • IBPT_MONTHS_PER_BAR
    To determine the Bar Period Type that the chart currently uses, call functions like sc.AreTimeSpecificBars().
  • IntradayBarPeriodLength: This is used for Intraday charts, in conjunction with the IntradayBarPeriodType parameter.
  • DaysToLoad: This sets the number of days of data that will be loaded into the chart whether it is a Historical Daily chart or an Intraday chart. If this value is left at 0, then the Chart >> Chart Settings >> Use Number of Days to Load >> Days to Load setting of the calling chart is used.
  • SessionStartTime, SessionEndTime: These specify the primary Session Start and End times. These session times are optional and only apply to Intraday charts. If the session times are not specified, then the Intraday Session Times from Global Symbol Settings are used.
  • EveningSessionStartTime, EveningSessionEndTime: The evening session times are optional, and only apply to Intraday charts. If the evening session times are not specified, then the Intraday Session Times from Global Symbol Settings are used.
  • IntradayBarPeriodParm2: This is used when IntradayBarPeriodType is set to IBPT_FLEX_RENKO_IN_TICKS. This is the Trend Offset.
  • IntradayBarPeriodParm3: This is used when IntradayBarPeriodType is set to IBPT_FLEX_RENKO_IN_TICKS. This is the Reversal Offset.
  • IntradayBarPeriodParm4: This is used when IntradayBarPeriodType is set to IBPT_FLEX_RENKO_IN_TICKS. This is the New Bar When Exceeded option. This can be set to 1 or 0.
  • HistoricalChartBarPeriod: In the case of when ChartDataType is set to DAILY_CHART , then this specifies the time period for each chart bar. It can be one of the following constants:
    • HISTORICAL_CHART_PERIOD_DAYS
    • HISTORICAL_CHART_PERIOD_WEEKLY
    • HISTORICAL_CHART_PERIOD_MONTHLY
    • HISTORICAL_CHART_PERIOD_QUARTERLY
    • HISTORICAL_CHART_PERIOD_YEARLY
  • int ChartLinkNumber: This can be optionally set to a nonzero Chart Link Number. The default is 0.
  • ContinuousFuturesContractOption: This can be set to one of the following constants:
    • CFCO_NONE
    • CFCO_DATE_RULE_ROLLOVER
    • CFCO_VOLUME_BASED_ROLLOVER
    • CFCO_DATE_RULE_ROLLOVER_BACK_ADJUSTED
    • CFCO_VOLUME_BASED_ROLLOVER_BACK_ADJUSTED
  • LoadWeekendData: Set this to 1 to load weekend (Saturday and Sunday) data, the default, or to zero to not load weekend data. This only applies to Intraday charts.

sc.Oscillator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Oscillator(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef Oscillator(SCFloatArrayRef FloatArrayIn1, SCFloatArrayRef FloatArrayIn2, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.Oscillator() function calculates the difference between FloatArrayIn1 and FloatArrayIn2.

Example

//Calculate the Oscillator between the first two extra arrays in sc.Subgraph[0]
// and output the results to sc.Subgraph[0].Data.
sc.Oscillator(sc.Subgraph[0].Arrays[0], sc.Subgraph[0].Arrays[1], sc.Subgraph[0])

 //Access the study value at the current index
float Oscillator = sc.Subgraph[0][sc.Index];

sc.Parabolic()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Parabolic(SCBaseDataRef BaseDataIn, SCDateTimeArray BaseDateTimeIn, SCSubgraphRef SubGraphOut, int Index, float InStartAccelFactor, float InAccelIncrement, float InMaxAccelFactor, unsigned int InAdjustForGap);

SCFloatArrayRef Parabolic(SCBaseDataRef BaseDataIn, SCDateTimeArray BaseDateTimeIn, SCSubgraphRef SubGraphOut, float InStartAccelFactor, float InAccelIncrement, float InMaxAccelFactor, unsigned int InAdjustForGap); Auto-looping only.

The sc.Parabolic() function calculates the standard parabolic study.

Parameters:

  • BaseDataIn
  • BaseDateTimeIn
  • SubGraphOut. For this function, sc.Subgraph[].Arrays[0-4] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • InStartAccelFactor: The starting acceleration factor. For reference, refer to the default value with the Parabolic study in Sierra Chart.
  • InAccelIncrement: The acceleration increment. For reference, refer to the default value with the Parabolic study in Sierra Chart.
  • InMaxAccelFactor: The maximum acceleration factor. For reference, refer to the default value with the Parabolic study in Sierra Chart.
  • InAdjustForGap: Set this to 1 to adjust the parabolic for price gaps. Otherwise, set it to 0.

Example

SCSubgraphRef Parabolic = sc.Subgraph[0];

sc.Parabolic(
    sc.BaseDataIn,
    sc.BaseDateTimeIn,

    Parabolic,
    sc.Index,
    StartAccelerationFactor.GetFloat(),
    AccelerationIncrement.GetFloat(),

    MaxAccelerationFactor.GetFloat(),
    AdjustForGap.GetYesNo(),
    InputDataHigh.GetInputDataIndex(),

    InputDataLow.GetInputDataIndex()
);

float SAR = Parabolic[sc.Index]; //Access the study value at the current index

sc.PlaySound()

Type: Function

int PlaySound(int AlertNumber);

int PlaySound(int AlertNumber, SCString &AlertMessage, int ShowAlertLog = 0)

int PlaySound(SCString &AlertPathAndFileName, int NumberTimesPlayAlert = 1);

int PlaySound(const char *AlertPathAndFileName, int NumberTimesPlayAlert = 1);

int PlaySound(SCString &AlertPathAndFileName, int NumberTimesPlayAlert, SCString &AlertMessage, int ShowAlertLog = 0)

To play an alert sound when a condition is TRUE, it is recommended to use the sc.SetAlert function, instead of the sc.PlaySound function, since it provides a more controlled logic for providing alerts.

The sc.PlaySound function is used to play the alert sound associated with the AlertNumber parameter or the file specified by the AlertPathAndFileName parameter. A sound will be played every time this function is called. There is no restriction logic used as is the case with the sc.SetAlert() function.

The alerts sounds are queued up and played asynchronously. This function returns 1 on success, and 0 on failure.

Refer to the scsf_LogAndAlertExample() function in the /ACS_Source/studies.cpp file in the Sierra Chart installation folder for example code to work with this function.

An Alert Message is added to the Alerts Log when this function is called. To open the Alerts Log, select Window >> Show/Hide Alerts Manager >> Alerts Log.

Parameters:

  • AlertNumber: The AlertNumber parameter specifies a particular alert sound to play which is associated with this number. These Alert Numbers are configured through the Global Settings >> General Settings window. For complete documentation, refer to Alert Sound Settings. Specify one of the numbers which is supported in the Alert Sound Settings.
  • AlertMessage: The alert message to add to the Alerts Log. AlertMessage can either be a SCString type or a plain C++ string. For information about AlertMessage and how to set this parameter, refer to the sc.AddAlertLine() function.
  • ShowAlertLog: ShowAlertLog needs to be set to 1 to cause the Alerts Log to open up when a message is added. Otherwise, ShowAlertLog needs to be 0 or it can be left out.
  • AlertPathAndFileName: The complete path and filename text string for the wav sound file to play.
  • NumberTimesPlayAlert: The number of times to play the specified Alert Number or specified sound file.

Example

sc.PlaySound(45); // Plays Alert Sound Number 45


sc.PlaySound(1,"My Alert Message");

sc.PlaySound(1,"My Alert Message that opens the Alerts Log",1);

sc.PlaySound("C:\WavFiles\MyAlert.wav",1,"My Alert Message"); 

sc.PriceValueToTicks()

Type: Function

unsigned int PriceValueToTicks(float PriceValue);

sc.PriceVolumeTrend()

Type: Intermediate Study Calculation Function

SCFloatArrayRef PriceVolumeTrend(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef PriceVolumeTrend(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.PriceVolumeTrend() function calculates the Price Volume Trend study.

Example

sc.PriceVolumeTrend(sc.BaseDataIn, sc.Subgraph[0]);

float PriceVolumeTrends = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.RefreshTradeData()

Type: Function

int RefreshTradeData();

sc.RefreshTradeData()function performs the very same action as selecting Trade >> Refresh Trade Data from Service. Refer to the Refresh Trade Data From Service documentation.

sc.ResizeArrays()

Type: Function

int ResizeArrays(int NewSize);

sc.ResizeArrays() resizes all of the sc.Subgraph[].Data[] arrays to the size specified with the NewSize parameter. This function is only useful when you have set sc.IsCustomChart to 1 (TRUE). The function returns 0 if it fails to resize all the arrays. This function also affects the sc.DateTimeOut[] and sc.Subgraph[].DataColor[] arrays.

Example

sc.ResizeArrays(100); // Resize the arrays to 100 elements

sc.RGBInterpolate()

Type: Function

COLORREF RGBInterpolate(const COLORREF& Color1, const COLORREF& Color2, float ColorDistance);

The sc.RGBInterpolate() function returns the color at the RGB distance between Color1 and Color2, where ColorDistance is a value between 0 and 1. If ColorDistance is 0, then Color1 is returned. If ColorDistance is 1, then Color2 is returned. If ColorDistance is 0.5f, then the color half way between Color1 and Color2 is returned.

Example

COLORREF NewColor = sc.RGBInterpolate(RGB(255,0,0), RGB(0,255,0), 0.5);

sc.Round()

Type: Function

int Round(float Number)

The sc.Round() function rounds the given floating-point Number to the nearest integer.

Example

int Rounded = sc.Round(1.2);

//1.2 rounded will be equal to 1

sc.RoundToTickSize() / sc.RoundToIncrement()

Type: Function

float RoundToTickSize(float Number, float Increment)

The sc.RoundToTickSize() and sc.RoundToIncrement() functions round the given floating-point Number to the nearest Increment. These functions are the same, they just have different names.

Example

int Rounded = sc.RoundToTickSize(1.2,0.25);

//1.2 rounded to the increment of .25 will equal 1.25

sc.RSI()

Type: Intermediate Study Calculation Function

SCFloatArrayRef RSI(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, unsigned int MovingAverageType, int Length)

SCFloatArrayRef RSI(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, unsigned int MovingAverageType, int Length) Auto-looping only.

The sc.RSI() function calculates the Wilders Relative Strength Index study.

Parameters:

Example

sc.RSI(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], MOVAVGTYPE_SIMPLE, 20);

float RSI = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.RandomWalkIndicator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef RandomWalkIndicator(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef RandomWalkIndicator(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.RandomWalkIndicator() function calculates the Random Walk Indicator study.

Parameters:

  • BaseDataIn
  • SubgraphOut. For this function, sc.Subgraph[].Arrays[0-3] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length

Example

sc.RandomWalkIndicator(sc.BaseDataIn, sc.Subgraph[0], 10);

//Access the individual lines
float High = sc.Subgraph[0][sc.Index];

float Low = sc.Subgraph[0].Arrays[0][sc.Index];

//Copy Low to a visible Subgraph
sc.Subgraph[1][sc.Index] = Low; 

sc.SaveChartbook()

Type: Function

int SaveChartbook();

The sc.SaveChartbook() function will save the Chartbook containing the chart the study function instance is applied to.

This saving occurs immediately when this function is called and will be complete when it returns. So it occurs synchronously.

sc.SaveChartImageToFileExtended()

Type: Function

void SaveChartImageToFileExtended(int ChartNumber, SCString& OutputPathAndFileName, int Width, int Height, int IncludeOverlays);

The sc.SaveChartImageToFileExtended() function saves the chart specified by the ChartNumber parameter to the file specified by the OutputPathAndFileName parameter. The saving of the chart occurs on a delay and happens after the study function returns.

If this function is called multiple times during a call into a study function, only the most recent call will be processed. The other calls to this function will be disregarded.

Parameters:

  • ChartNumber: The Chart Number of the chart to save. The chart must be within the same Chartbook as the chart containing study instance this function is called from.
  • OutputPathAndFileName: The path and filename to save the chart image to.
  • Width: The width of the chart image in pixels. The chart will be resized if this is set to a nonzero value. Set this to 0 to not use this parameter.
  • Height: The height of the chart image in pixels. The chart will be resized if this is set to a nonzero value. Set this to 0 to not use this parameter.
  • IncludeOverlays: When this is set to 1 or a nonzero value, then any other windows which overlay the chart will also be included in the chart image.

sc.SecondsSinceStartTime()

Type: Function

int SecondsSinceStartTime(const SCDateTime& BarDateTime);

The sc.SecondsSinceStartTime() function

sc.SessionStartTime()

Type: Function

int SessionStartTime();

The sc.SessionStartTime() function gets the start of the trading day in Intraday charts which is based on the Session Times set in Chart >> Chart Settings. Normally this is the Session Times >>Start Time.

If Use Evening Session is enabled in the Chart Settings, then this function returns the Start Time of the evening session.

The value returned is a Time Value.

Example

int StartTime = sc.SessionStartTime();

sc.SetAlert()

Type: Function

int SetAlert(int AlertNumber, int Index, SCString Message);

int SetAlert(int AlertNumber, int Index);

int SetAlert(int AlertNumber, SCString Message); Auto-looping only.

int SetAlert(int AlertNumber); Auto-looping only.

The sc.SetAlert() function will play an alert sound and add a message to the Alerts Log. This can be used when you have a condition that you want to provide a signal for at the specified sc.Subgraph[].Data array Index.

To open the Alerts Log, select Window >> Show/Hide Alerts Manager >> Alerts Log on the menu.

Since the sc.Subgraph[].Data[] arrays directly correspond to the sc.BaseData[][] arrays, Index corresponds to the sc.BaseData[][] arrays indexes. If you are using Automatic Looping, then the Index parameter is auto set for you and does not need to be specified.

The AlertNumber parameter sets an Alert Sound Number to play. This can be anywhere from 1 to 150. To configure the specific sound file to play for a particular Alert Number, select Global Settings >> General Settings >> Alerts on the Sierra Chart menu. For more information, refer to the Alert Sound Settings.

Using an AlertNumber of 0 means there will be no Alert Sound played.

The optional Message parameter specifies the text message to be added to the Alerts Log. If it is not specified, a standard message will be added to the log.

If you set an Alert on an Index that is not at the end of a sc.Subgraph[].Data array, it will be ignored. However, if there are multiple chart bars added during an update, the alerts will be processed for those new bars as well as the prior bar. Therefore, if you are providing an alert on a bar which has just closed, it will be processed.

If historical data is being downloaded in the chart, then calls to sc.SetAlert() are ignored. This is to prevent Alert sounds and Messages from occurring when historical data is being downloaded.

During a call into a study function, if there are multiple calls to sc.SetAlert() at the same or different bar indexes, only one will actually generate an alert. The rest will be ignored. However, if sc.ResetAlertOnNewBar is set to a nonzero value, then calling sc.SetAlert() at different bar indexes will generate separate alerts.

If at every call into the study function you make a call to sc.SetAlert(), only the first time sc.SetAlert() is called will that generate an alert. There must be at least one call into the study function where sc.SetAlert() is not called, to reset the internal alert state for the study to allow for another call to sc.SetAlert() to generate an alert. However, if sc.ResetAlertOnNewBar is set to a nonzero value, then calling sc.SetAlert() at a new bar index will generate a new alert.

The sc.AlertOnlyOncePerBar and the sc.ResetAlertOnNewBar variables work with sc.SetAlert(). They control the alert processing. These variables only need to be set once in the sc.SetDefaults code block.

Even if sc.AlertOnlyOncePerBar it is set to 0, then multiple calls to sc.SetAlert() during a call into a study function at the same or different bar indexes, will still only generate one alert, as explained above.

For an example to work with the sc.SetAlert() function, see scsf_SimpMovAvg() in studies.cpp inside the ACS_Source folder in the Sierra Chart installation folder.

Example

sc.SetAlert(5, "Condition #1 is TRUE.");

sc.SetNumericInformationDisplayOrderFromString

Type: Function

void SetNumericInformationDisplayOrderFromString(const SCString& CommaSeparatedDisplayOrder);

The sc.SetNumericInformationDisplayOrderFromString function is used when sc.GraphDrawType is set to GDT_NUMERIC_INFORMATION.

This function takes a comma separated text string, CommaSeparatedDisplayOrder , with the one-based sc.Subgraph[] indexes in the order that you want to display in the table. For example, "5,4,1,2" would display Subgraphs in the order given. Any other sc.Subgraphs which will be displayed in the table that are left out of the CommaSeparatedDisplayOrder texturing will be appended to the end of the table in their natural order.

sc.SetNumericInformationGraphDrawTypeConfig()

Type: Function

void SetNumericInformationGraphDrawTypeConfig(const s_NumericInformationGraphDrawTypeConfig& NumericInformationGraphDrawTypeConfig);

sc.SetStudySubgraphDrawStyle()

Type: Function

void SetStudySubgraphDrawStyle(int ChartNumber, int StudyID, int StudySubgraphNumber, int DrawStyle);

The sc.SetStudySubgraphDrawStyle() function sets the Draw Style of another study in the Chartbook. The study can be in a different chart. The ChartNumber StudyID, and StudySubgraphNumber parameters should be obtained using the sc.Input[].GetChartStudySubgraphValues function.

Example

sc.SetStudySubgraphDrawStyle(1, 1, 0, DRAWSTYLE_LINE);

sc.SetStudyVisibilityState

Type: Function

int SetStudyVisibilityState(int StudyID, int Visible);

The sc.SetStudyVisibilityState() function .

Parameters:

Example

sc.SimpleMovAvg()

Type: Intermediate Study Calculation Function

SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.SimpleMovAvg() function calculates the simple moving average study.

Example

sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float SimpleMovAvg = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.Slope()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Slope(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut);

SCFloatArrayRef Slope(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index); Auto-looping only.

The sc.Slope() function calculates the Slope study. This is the difference between the FloatArrayIn at the Index currently being calculated and the prior FloatArrayIn value.

Example

sc.Slope(sc.BaseData[SC_LAST], sc.Subgraph[0]);

//Access the study value at the current index
float SlopeValue = sc.Subgraph[0][sc.Index]; 

sc.SmoothedMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef SmoothedMovingAverage (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef SmoothedMovingAverage (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.SmoothedMovingAverage() function calculates the Smoothed Moving Average study.

Example

sc.SmoothedMovingAverage(sc.BaseData[SC_LAST], sc.Subgraph[0], 10);

float SmoothedMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.StdDeviation()

Type: Intermediate Study Calculation Function

SCFloatArrayRef StdDeviation(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef StdDeviation(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.StdDeviation() function calculates the standard deviation of the data.

Example

sc.StdDeviation(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float StdDeviation = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.StdError()

Type: Intermediate Study Calculation Function

SCFloatArrayRef StdError(SCFloatArrayRef FloarArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef StdError(SCFloatArrayRef FloarArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.StdError() function calculates the standard error of the data.

Example

sc.StdError(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float StdError = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.Stochastic()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Stochastic(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int Index, int FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType);

SCFloatArrayRef Stochastic(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut, int FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType); Auto-looping only.

The sc.Stochastic() function calculates the Fast %K, Fast %D, and Slow %D Stochastic lines.

Parameters:

Example

sc.Stochastic(sc.BaseDataIn, sc.Subgraph[0], 10, 3, 3, MOVAVGTYPE_SIMPLE);

//Access the individual study values at the current index
float FastK = sc.Subgraph[0][sc.Index];

float FastD = sc.Subgraph[0].Arrays[0][sc.Index];

float SlowD = sc.Subgraph[0].Arrays[1][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = FastD;
sc.Subgraph[2][sc.Index] = SlowD;

sc.Summation()

Type: Intermediate Study Calculation Function

SCFloatArrayRef Summation (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef Summation (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.Summation function calculates the summation over the specified Length.

Example

Summation(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], 10);

float Summation = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.RegionValueToYPixelCoordinate()

Type: Function

int RegionValueToYPixelCoordinate (float RegionValue, int ChartRegionNumber);

The sc.RegionValueToYPixelCoordinate function calculates the Y-axis coordinate for the given RegionValue and ChartRegionNumber. RegionValue is a value within the Scale Range of the specified chart region. ChartRegionNumber is zero-based.

sc.TEMA()

Type: Intermediate Study Calculation Function

SCFloatArrayRef TEMA (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef TEMA (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.TEMA() function calculates the Triple Exponential Moving Average study.

Parameters:

Example

sc.TEMA(sc.BaseData[SC_LAST], sc.Subgraph[0], 10);

float TEMA = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.TicksToPriceValue()

Type: Function

float TicksToPriceValue(unsigned int Ticks);

The sc.TicksToPriceValue() function

Example

//Example Code
            

sc.TimeStringToSCDateTime()

Type: Function

double TimeStringToSCDateTime(const SCString& TimeString)

The sc.TimeStringToSCDateTime() function converts the given TimeString parameter to an SCDateTime type.

The value returned from this function can also be assigned to a SCDateTimeMS type to access millisecond functionality on the returned time value.

The supported time format is: HH:MM:SS.MS. Milliseconds are optional. The hours can have a negative sign in front of it.

For information about the SCString type, refer to Working With Text Strings and Setting Names.

sc.TradingDayStartsInPreviousDate()

Type: Function

int TradingDayStartsInPreviousDate();

The sc.TradingDayStartsInPreviousDate() function

Example

//Example Code
            

sc.TriangularMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef TriangularMovingAverage (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef TriangularMovingAverage (SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.TriangularMovingAverage() function calculates the Triangular Moving Average study.

Parameters:

Example

sc.TriangularMovingAverage(sc.BaseData[SC_LAST], sc.Subgraph[0], 10);

float TriangularMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.TRIX()

Type: Intermediate Study Calculation Function

SCFloatArrayRef TRIX(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Index, int Length);

SCFloatArrayRef TRIX(SCFloatArrayRef FloatArrayIn, SCSubgraphRef SubgraphOut, int Length); Auto-looping only.

The sc.TRIX() function calculates the TRIX study.

Parameters:

Example

sc.TRIX(sc.BaseDataIn[SC_LAST], sc.Subgraph[0].Arrays[0], 20);

float TRIX = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.GetTradingDayDate()

Type: Function

int GetTradingDayDate(const SCDateTime& DateTime);

The sc.GetTradingDayDateForChartNumber() function returns a Date Value which is the trading day date for the given DateTime parameter.

The trading day date is the date of the trading day that the DateTime belongs to based upon the Session Times set in Chart >> Chart Settings for the chart the study function is applied to.

The returned date will be the same date as the given DateTime parameter when the Session Times do not span over midnight. However, in the case where the Session Start Time is greater than the Session End Time and spans over midnight, then the trading day date will always be the date of the day beginning with midnight during the trading session.

Example

SCDateTime TradingDayDate = sc.GetTradingDayDate(sc.BaseDataDateTimeIn[sc.Index]);
            

sc.GetTradingDayDateForChartNumber()

Type: Function

int GetTradingDayDateForChartNumber(int ChartNumber, const SCDateTime& DateTime);

The sc.GetTradingDayDateForChartNumber() function returns a Date Value which is the trading day date for the given ChartNumber and DateTime parameters.

The trading day date is the date of the trading day that the DateTime belongs to based upon the Session Times set in Chart >> Chart Settings for the chart the study function is applied to.

The returned date will be the same date as the given DateTime parameter when the Session Times do not span over midnight. However, in the case where the Session Start Time is greater than the Session End Time and spans over midnight, then the trading day date will always be the date of the day beginning with midnight during the trading session.

Parameters:

  • ChartNumber: The number of the chart to use. This is the number that is shown on the top line in the Chart window, after the #. If this is negative, the bar period and other Chart Settings are synchronized between the two charts. The relevant Chart Settings for the specified ChartNumber are set to the same settings as the chart your study is applied to. If it is positive, this does not occur. For example, if you want to get the base data from chart #5 and you want to synchronize the charts, then pass -5.
  • DateTime: The date and time to use to find the correspoding trading day date.

Example

SCDateTime TradingDayDate = sc.GetTradingDayDateForChartNumber(sc.ChartNumber, sc.BaseDataDateTimeIn[sc.Index]);
            

sc.TrueRange()

Type: Intermediate Study Calculation Function

SCFloatArrayRef TrueRange(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef TrueRange(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.TrueRange() function calculates the True Range study.

Example

sc.TrueRange(sc.BaseDataIn, sc.Subgraph[0]);

float TrueRange = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.UltimateOscillator()

Type: Intermediate Study Calculation Function

SCFloatArrayRef UltimateOscillator(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut1, SCSubgraphRef SubgraphOut2, int Index, int Length1, int Length2, int Length3);

SCFloatArrayRef UltimateOscillator(SCBaseDataRef BaseDataIn, SCSubgraphRef SubgraphOut1, SCSubgraphRef SubgraphOut2, int Length1, int Length2, int Length3); Auto-looping only.

The sc.UltimateOscillator() function calculates the Ultimate Oscillator.

Parameters:

  • BaseDataIn
  • SubgraphOut1. For this function, sc.Subgraph[].Arrays[0-8] (Extra Arrays) are used for internal calculations and additional results output.
  • SubgraphOut2. For this function, sc.Subgraph[].Arrays[0-3] (Extra Arrays) are used for internal calculations and additional results output.
  • Index
  • Length1
  • Length2
  • Length3

Example

sc.UltimateOscillator(sc.BaseDataIn, sc.Subgraph[0], sc.Subgraph[1], 7, 14, 28);

 //Access the study value at the current index
float UltimateOscillator = sc.Subgraph[0][sc.Index];

sc.UseTool()

Type: Function

For more information, refer to the Using Tools with sc.UseTool() section on the Using Tools From an Advanced Custom Study page.

sc.VHF()

Type: Intermediate Study Calculation Function

SCFloatArrayRef VHF(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef VHF(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.VHF() function calculates the Vertical Horizontal Filter study.

Example

sc.VHF(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], 10);

float VHF = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.VolumeWeightedMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef VolumeWeightedMovingAverage (SCFloatArrayRef FloatArrayDataIn, SCFloatArrayRef FloatArrayVolumeIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef VolumeWeightedMovingAverage (SCFloatArrayRef InData, SCFloatArrayRef InVolume, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.VolumeWeightedMovingAverage() function calculates the Volume Weighted Moving Average study.

Example

sc.VolumeWeightedMovingAverage(sc.BaseData[SC_LAST], sc.BaseData[SC_VOLUME], sc.Subgraph[0], 10);

float VolumeWeightedMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.WeightedMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef WeightedMovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef WeightedMovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.WeightedMovingAverage() function calculates the Weighted Moving Average study.

Example

sc.WeightedMovingAverage(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float WeightedMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.WellesSum()

Type: Intermediate Study Calculation Function

SCFloatArrayRef WellesSum (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef WellesSum (SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.WellesSum() function calculates the Welles Summation of the FloatArrayIn data.

Example

sc.WellesSum(sc.Subgraph[1], sc.Subgraph[0], 10);

float WellesSum = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.WildersMovingAverage()

Type: Intermediate Study Calculation Function

SCFloatArrayRef WildersMovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef WildersMovingAverage(SCFloatArrayRef FloatArrayIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.WildersMovingAverage() function calculates the Wilders Moving Average study.

Example

sc.WildersMovingAverage(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);

float WildersMovingAverage = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.WilliamsAD()

Type: Intermediate Study Calculation Function

SCFloatArrayRef WilliamsAD(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index);

SCFloatArrayRef WilliamsAD(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut); Auto-looping only.

The sc.WilliamsAD() function calculates the Williams Accumulation/Distribution study.

Example

sc.WilliamsAD(sc.BaseDataIn, sc.Subgraph[0]);

float WilliamsAD = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.WilliamsR()

Type: Intermediate Study Calculation Function

SCFloatArrayRef WilliamsR(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Index, int Length);

SCFloatArrayRef WilliamsR(SCBaseDataRef BaseDataIn, SCFloatArrayRef FloatArrayOut, int Length); Auto-looping only.

The sc.WilliamsR() function calculates the Williams %R study.

Example

sc.WilliamsR(sc.BaseDataIn, sc.Subgraph[0], 10);

float WilliamsR = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

sc.YPixelCoordinateToGraphValue()

Type: Function

double YPixelCoordinateToGraphValue(int YPixelCoordinate);

The sc.YPixelCoordinateToGraphValue() function calculates the graph value from the given Y-axis pixel coordinate. Each chart is divided into Chart Regions and each Chart Region can contain one or more graphs. This function will determine the value used by a graph based upon the scaling of the Chart Region for the given Y-axis coordinate.

Example

float GraphValue= sc.YPixelCoordinateToGraphValue(sc.ActiveToolYPosition);
            

min()

Type: Function

min(a, b)

min() takes two parameters (a and b) and returns the lesser of the two.

Example

int MinValue = min(-5, 3);

// MinValue will equal -5

max()

Type: Function

max(a, b)

max() takes two parameters (a and b) and returns the greater of the two.

Example

int MaxValue = max(-5, 3);

// MaxValue will equal 3

Common Parameters for Intermediate Study Calculation Functions

This is a list of all of the parameter descriptions for the common parameters for Intermediate Study Calculation functions. For example, sc.SimpleMovAvg() is an intermediate study calculation function.

  • FloatArrayIn(#): The FloatArrayIn parameter is defined as a reference to a SCFloatArray. This is a data array of float values which is used as input to the intermediate study calculation function. This parameter type can be one of the following types: sc.Subgraph[], sc.Subgraph[].Data, sc.Subgraph[].Arrays[], sc.BaseDataIn[ArrayIndex], or sc.BaseData[ArrayIndex].
  • BaseDataIn: The BaseDataIn parameter is defined as a reference to a SCFloatArrayArray. This is the main chart graph arrays. The only object that you can use is sc.BaseDataIn for this parameter type.
  • BaseDateTimeIn: The type is a reference to a SCDateTimeArray . This is the main price/chart graph date and time array. Can only be sc.BaseDateTimeIn.
  • FloatArrayOut: The type is a reference to a SCFloatArray. This is an output data array of float values. You need to pass a sc.Subgraph[], sc.Subgraph[].Data or sc.Subgraph[].Arrays array.
  • SubgraphOut: The type is a reference to a sc.Subgraph[]. You need to pass a sc.Subgraph[] object. The results are written to the sc.Subgraph[].Data and sc.Subgraph[].Arrays arrays. The sc.Subgraph[].Arrays arrays are used for intermediate calculations and additional output.
  • Index: This parameter is the Index to the element in an output array (SubgraphOut, FloatArrayOut ) where the calculation result is outputted to. And the Index to the element or elements in the input array or arrays (FloatArrayIn, BaseDataIn, BaseDateTimeIn ) that are used in the internal calculations of the intermediate study calculation function, and where the calculation begins when back referencing the data in the input arrays. This parameter is optional when using Automatic Looping. It can be left out in all of the intermediate study calculation functions and will internally be set to sc.Index .
  • Length: The number of data array elements used in the calculations. This definition applies to all parameters with Length in their name.
  • MovingAverageType: MovingAverageType needs to be set to the type of moving average you want to use. This description also applies to parameters that have MovAvgType, MovingAverageType, or MAType in their name. The following are the Moving Average type constants that you can use:
    • MOVAVGTYPE_SIMPLE: Simple moving average.
    • MOVAVGTYPE_EXPONENTIAL: Exponential moving average.
    • MOVAVGTYPE_LINEARREGRESSION: Linear regression or least-squares moving average.
    • MOVAVGTYPE_WEIGHTED : Weighted moving average.
    • MOVAVGTYPE_WILDERS: Wilder's moving average.
    • MOVAVGTYPE_SIMPLE_SKIP_ZEROS: Simple Moving Average that skips zero values.
    • MOVAVGTYPE_SMOOTHED: Smoothed moving average.
  • Multiplier: A multiplier parameter is simply a value which is used to multiply another value used in the calculation. Such as multiplying the data from the input data array or a sub calculation from that input data array.

*Last modified Tuesday, 27th September, 2016.