Sierra Chart - Definitions of Advanced Custom Study Interface Members

Definitions of Advanced Custom Study Interface Members

The information on this page applies to the Sierra Chart Advanced Custom Study Interface and Language. For more information see: Advanced Custom Study Interface and Language

On this page, you will find all of the members of the Advanced Custom Study Interface available to your study function. These include variables, arrays, functions, and structures. These members need to be prefixed with sc. when using them in your study function.

In previous versions, the interface structure members begin with sg. Now they begin with sc. sg can still be used though.

From time to time new interface members are added. If you use one of the members and receive a compiler error, then the possible cause is that you are not running the latest version of Sierra Chart. If a compiled Advanced Custom Study uses a member which is not supported in an older version of Sierra Chart, then when the study is added an error will be given.

A new shorthand method to access a sc.Subgraph[].Data array element is available. Example: sc.Subgraph[0][i] is equivalent to sc.Subgraph[0].Data[i]. These two methods are used interchangeably in this documentation.


Table of Contents


Variables and Arrays

sc.BaseDataIn[][] / sc.BaseData[][]

Read-only, Array of float arrays

sc.BaseDataIn[][] / sc.BaseData[][] is an array of float arrays that contain the data for the main graph in the chart. The first use of square brackets on this object will get the specified array of the main graph on the chart. For example: sc.BaseDataIn[SC_OPEN] will get the array of opening prices for each bar on the chart. The second use of square brackets will get an element inside the array that you received with the first set of square brackets. For example: sc.BaseDataIn[SC_OPEN][sc.Index] will get the opening price for the bar at the array index your study function should do processing at when using Auto-Looping. The main graph is not necessarily the underlying data in the chart. For example, if you are using the Point and Figure study, then sc.BaseData will contain the Point and Figure data.

For information about indexing and array sizes see Array Indexing and Sizes.

The following list describes each of the arrays available from the chart. These are used with the first array operator on sc.BaseData[].:

The index value returned by sc.Input[].GetInputDataIndex() , corresponds to the array index constants given above. You can use this Input to select any of these array index constants to use with sc.BaseData[].

sc.BaseData is short-hand for sc.BaseDataIn.

Example

// Get the volume at the current index.
// This requires sc.AutoLoop = 1;
float Volume = sc.BaseData[SC_VOLUME][sc.Index];

// Copy the Last price from the current index to sc.Subgraph 0
sc.Subgraph[0][sc.Index]=sc.BaseData[SC_LAST][sc.Index];

References

A useful technique to make it easier to work with a single array from the chart is to use a reference to the array. A reference to one of these arrays would be declared as SCFloatArrayRef. SCFloatArrayRef is a reference to the type of the arrays that are used in sc.BaseDataIn[]. Below is an example of using a reference to one of the arrays in the chart.

Example

// Make a reference to the array of High prices called Highs
SCFloatArrayRef Highs = sc.BaseData[SC_HIGH];

// Get the high price at the current index
// This is the same as sc.BaseData[SC_HIGH][sc.Index]
float HighValue = Highs[sc.Index];

sc.BaseDateTimeIn[]

Read Only, SCDateTime array

sc.BaseDateTimeIn[] is an array of the DateTimes for each bar in the chart. Each element is a SCDateTime.

For information about indexing and array sizes see Array Indexing and Sizes.

Example

// Get the DateTime at the current index.
SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index];

Since this is a SCDateTime array, you can use the DateAt() and TimeAt() member functions to get just the date or just the time at a single bar.

Example

// Get the date
int BarDate = sc.BaseDateTimeIn.DateAt(sc.Index);
// Get the time
int BarTime = sc.BaseDateTimeIn.TimeAt(sc.Index);

sc.ArraySize

Read variable

sc.ArraySize is set to the number of elements that are in the arrays for this chart. This applies to the sc.BaseDateTimeIn[], sc.BaseDataIn[][], and sc.Subgraph[][] arrays.

If you set sc.IsCustomChart to 1 (true), sc.ArraySize does not apply to the sc.Subgraph[][] arrays. Look at sc.OutArraySize for more information. Setting sc.IsCustomChart is uncommon, so in most cases this is not something you need to worry about.

Example

// Copy all the Close elements from the BaseDataIn array to the Data array of the first subgraph
for (int i = 0; i < sc.ArraySize; ++i)
{
    sc.Subgraph[0][i] = sc.BaseDataIn[SC_LAST][i]; // SC_LAST is for the Close values in OHLC bars
}

sc.AutoLoop

Read/Write variable. Default

Initial value: 0 (false)

When sc.AutoLoop is set to 1 (true), then array element looping is automatically performed. Otherwise you will need to create your own internal loop. It is preferred that you set sc.AutoLoop to 1 (true) unless you do not require it. For complete information, please see Automatic Looping/Iterating.

Example

if (sc.SetDefaults)
{
    sc.AutoLoop = 1; // Enable auto-looping
}

sc.CurrentIndex / sc.Index

Read variable

sc.CurrentIndex and sc.Index are the same. They are two different variables that are set to the same index value always. You can use either one. Normally the documentation will refer to sc.Index. sc.Index is equal to the elements in the sc.BaseDataIn[][] arrays that need to be processed and/or the elements in the sc.Subgraph[][] arrays that need to be filled in.

If you are creating a custom chart by setting sc.IsCustomChart to 1 (true), this is very unlikely, then sc.Index only refers to the elements in the sc.BaseDataIn[][] arrays to process, assuming your custom chart function uses the sc.BaseDataIn[][] arrays.

For complete information see Automatic Looping/Iterating.

sc.UpdateStartIndex

Read variable

sc.UpdateStartIndex is only used with manual looping. For more information on manual looping, please see Working With Arrays and Looping. sc.Index, sc.CurrentIndex and sc.UpdateStartIndex are all set to the same value. All three of these variables can be used interchangeably. However, the behavior of sc.Index/sc.CurrentIndex/sc.UpdateStartIndex differs significantly depending whether you are using Auto Looping or Manual Looping.

sc.UpdateStartIndex is set by Sierra Chart to the index where your primary for loop will start looping from. This is the index into the sc.BaseDataIn[][] arrays where data updating has begun. This is the same index where updating should begin in the sc.Subgraph[][] arrays. If you are creating a custom chart, sc.IsCustomChart is set to true (this is very unlikely), then sc.UpdateStartIndex only refers to the index into the sc.BaseDataIn[][] arrays to begin processing at.

For example:
When a chart is opened, reloaded or recalculated, your study function will be called and sc.UpdateStartIndex will be 0. This means you need to update all elements in the sc.Subgraph[].Data[] arrays you are using. During updating, if there are 100 bars in a chart and a trade occurs and either the last bar is updated or a new bar is added to the chart, then this variable will be set to 99 indicating the value at index 99 (bar 100) has been updated. For example: sc.BaseDataIn[SC_LAST][99] (bar 100) has been updated. During normal chart updating sc.UpdateStartIndex will always be equal to the last index of the prior sc.ArraySize before the chart update. If a new bar was added, then there will also be a new array element at sc.BaseDataIn[][100] (bar 101). In this case, you need to update the sc.Subgraph[].Data[] arrays at index 99 and index 100. The reason you need to use sc.UpdateStartIndex is to only perform calculations on the modified data and only update the study values starting from this index. This makes your study very efficient.

It is very possible that more than 1 bar will be added to a chart between updates. There could be hundreds or thousands of bars potentially added when historical data is downloaded into the chart after the initial data load from the data file. Therefore, you need to update from sc.UpdateStartIndex to the end in all the sc.Subgraph[][] arrays you are using, and not just the element at this index.

sc.SetDefaults

Read variable

sc.SetDefaults is a true (1) or false (0) value that gets set to 1 (true) when the study is added to a chart or when a chartbook is opened and the study is contained on one of the charts in the chartbook. If the study is on more than one chart in the chartbook or there are multiple instances of it, then the study function will be called once for each instance with sc.SetDefaults set to 1. This variable is also true (1) and your study function is called whenever the studies from your DLL are listed in the Add Custom Study window. This is so that the names and descriptions of your studies can be shown.

All study functions must include a code block at the top of the function that checks this member before doing any data processing. See example below. If this value is 1 (true), then the study function should return before doing any data processing.

The purpose of sc.SetDefaults is to allow the study function to configure itself and set defaults. This can include setting the names and styles of Subgraphs, the names and default values of inputs, and a variety of other things. At the very least, sc.GraphName should be set in the sc.SetDefaults code block.

The codeblock for setting your configuration and defaults is not meant to be used for anything other than configuring the study or "setting the defaults" of the study.

Items on this page that are marked with Default are items that can be set when sc.SetDefaults is 1 (true). In other words, they can be located within the code block for setting your configuration and defaults. Items marked with Default can also be used outside the SetDefaults code block. However, it is recommended that items that are not marked with Default should not be used when sc.SetDefaults is 1 (true), although there is no harm in doing so.

Example

SCSFExport scsf_UniqueFunctionName(SCStudyGraphRef sc)
{

    if
(sc.SetDefaults)
    {

        // Set the defaults

        sc.GraphName = "My New Study Function";

        sc.Subgraph[0].Name = "Subgraph name";
        sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
        sc.AutoLoop = 1;

        // You can also enter additional configuration code

        return;
    }


    // Perform your data processing here.

    //This is an example that multiplies the last price by 10.

    sc.Subgraph[0][sc.Index] = sc.BaseData[SC_LAST][sc.Index] * 10;

    return
;
}

sc.GraphName

Read/Write variable. Default

sc.GraphName is the name of your study. This must be set when sc.SetDefaults is 1 (true).

Example

sc.GraphName = "My Study";

sc.StudyDescription

Read/Write string variable. Default

sc.StudyDescription is a string that can be set to a description of the study. This is optional. If you use this, it needs to be in the code block for setting your configuration and defaults. This study description will be shown in the Add Custom Study window when the study is selected.

Example

sc.StudyDescription = "Here is a description for this study. This description will be shown in the Add Custom Study window when this study is selected.";

sc.FreeDLL

Read/Write variable. Default

Initial value: 1 (true)

sc.FreeDLL can be a true (1) or false (0) value indicating whether or not to free the DLL your study is in after running your study function. By default the DLL is freed after your function is called. Set this to 0 (false) to tell Sierra Chart not to free the DLL. Setting it to 0 (false) will significantly speed up calling your Advanced Custom Study function because the overhead of loading and freeing the DLL will be eliminated. It is critical with Sierra Chart versions 297 and higher that after your study development is done that you set this member to false (0) otherwise CPU usage will be noticeably increased. The disadvantage of setting this to false (0) is you can not make changes to your function while Sierra Chart is running since the DLL file is opened and cannot be modified. For this reason, you should set sc.FreeDLL to 1 (true), the default, while developing your study, and set it to 0 (false) once you are finished.

Example

sc.FreeDLL = 0; // Don't unload the DLL every time this function is called

sc.CalculationPrecedence

Read/Write variable. Default.

Initial value: STD_PREC_LEVEL

sc.CalculationPrecedence is a variable that can be set to 3 possible values. The default value is STD_PREC_LEVEL (standard precedence level), and means your study is calculated relative to other studies on the same chart that your custom study is applied to, based on its position in the Studies to Graph list in Sierra Chart. A value of LOW_PREC_LEVEL (low precedence level) will mean your study gets calculated after all other studies with a standard precedence level. A value of VERY_LOW_PREC_LEVEL (very low precedence level) will mean your study gets calculated after all other studies with standard and low precedence levels. You will want to use a very low precedence level if your study depends on other studies that have low precedence level, such as Study Moving Average or a study based on other study. The reason why you would want to set this variable to a lower precedence level, is when you are using a function such as sc.GetStudyArray(). It is not necessary to set a low precedence when you are internally calculating study formulas, such as when using sc.SimpleMovAvg().

Example

sc.CalculationPrecedence = STD_PREC_LEVEL;

sc.UpdateAlways

Read/Write variable. Default

Initial value: 0 (false)

When the sc.UpdateAlways variable is set to 1 (true), the study will update continuously rather than only when new data is available. This means your study function will be called continuously at the update interval. The update interval is set through Global Settings >> General Settings. One use of this setting is to simulate real time updating during testing. This setting does not affect other studies on the same chart.

To maintain efficiency, beginning with version 281, your study function will not be called more often than every 500 ms when setting this variable to true and new data is not available. Otherwise, setting this variable to true would significantly increase CPU usage if your chart update interval is very low.

Example

sc.UpdateAlways = 1; // Set this study to update always

sc.GraphRegion

Read/Write variable. Default

Initial value: 1 or the next available region

sc.GraphRegion is the zero-based index of the region for the graph to display in. A value of 0 mean Region 1, which is where the main price graph is drawn. A value of 1 means Region 2, which is right under the main price graph.

Example

sc.GraphRegion = 0; // Use the main price graph region

sc.ValueFormat

Read/Write variable. Default

Initial value: 2 (2 decimal places, For example, 0.01)

sc.ValueFormat indicates the format in which values will be displayed for the study. This can be one of the following values:

Example

sc.ValueFormat = 4; // Set this study to show values with four decimal places

sc.DrawZeros

Read/Write variable. Default

Initial value: 0 (disabled)

sc.DrawZeros can be a true (1) or false (0) value to enable or disable the drawing of subgraph data array elements that have a value of zero. Set this value to 1 to enable the drawing of zero values. Set this value to 0 to disable the drawing of zero values. When this is disabled, the Subgraph Draw Style of DRAWSTYLE_LINE will draw a continuous line between the chart columns that have non-zero values.

Example

sc.DrawZeros = 0; // Don't draw zero values

sc.ScaleType

Read/Write variable. Default

Initial value: SCALE_LINEAR

sc.ScaleType is the type of value scaling that is used on the study. This can be set to either SCALE_LINEAR for a basic linear scale, or SCALE_LOGARITHMIC for a logarithmic scale.

Example

sc.ScaleType = SCALE_LOGARITHMIC; // Set this study to use a logarithmic scale

sc.ScaleRangeType

Read/Write variable. Default

Initial value: SCALE_AUTO

sc.ScaleRangeType is the method that Sierra Chart uses to determine the range of the values' scale (Y axis) for the study. This can be set to SCALE_AUTO, SCALE_USERDEFINED, SCALE_INDEPENDENT, SCALE_SAMEASREGION, SCALE_CONSTRANGE, or SCALE_CONSTRANGECENTER. These scale range types are the same as those found in the Scale window that can be brought up from the Settings and Inputs tab on the Technical Study Settings window.

Example

sc.ScaleRangeType = SCALE_INDEPENDENT; // Set this study to use an independent scale

sc.ScaleRangeTop

Read/Write variable. Default

Initial value: 0

sc.ScaleRangeTop is the maximum value shown in the scale range when using a user-defined scale range (sc.ScaleRangeType = SCALE_USERDEFINED;). Whenever you use this, this should always be greater than sc.ScaleRangeBottom.

Example

sc.ScaleRangeType = SCALE_USERDEFINED; // Set this study to use a user-defined scale
sc.ScaleRangeTop = 100.0f; // Set the top of the user-defined range to 100
sc.ScaleRangeBottom = -100.0f; // Set the bottom of the user-defined range to -100

sc.ScaleRangeBottom

Read/Write variable. Default

Initial value: 0

sc.ScaleRangeBottom is the minimum value shown in the scale range when using a user-defined scale range (sc.ScaleRangeType = SCALE_USERDEFINED;). Whenever you use this, this should always be less than sc.ScaleRangeTop.

Example

sc.ScaleRangeType = SCALE_USERDEFINED; // Set this study to use a user-defined scale
sc.ScaleRangeTop = 100.0f; // Set the top of the user-defined range to 100
sc.ScaleRangeBottom = -100.0f; // Set the bottom of the user-defined range to -100

sc.ScaleConstRange

Read/Write variable. Default

Initial value: 0

sc.ScaleConstRange is the range, that is the difference between the high and the low, for the constant range scale types. This is only used when sc.ScaleRangeType is either SCALE_CONSTRANGE or SCALE_CONSTRANGECENTER. If sc.ScaleRangeType is set to one of these constant range types, sc.ScaleConstRange needs to be greater than 0.

Example

sc.ScaleRangeType = SCALE_CONSTRANGECENTER; // Set this study to use a centered constant range scale
sc.ScaleConstRange = 10.0f; // Set the range of the scale to 10 points

sc.ScaleIncrement

Read/Write variable. Default

Initial value: 0 (auto)

sc.ScaleIncrement is the amount at which values in the scale area on the chart are shown. This is the same as the Scale Increment setting in the Scale window that can be brought up from the Settings and Inputs tab in the Technical Study Settings window. A value of 0 means the scale increment is automatically determined by Sierra Chart.

Example

sc.ScaleIncrement = 0.01f; // Draw values on the scale at every 0.01 point

sc.ScaleValueOffset

Read/Write variable. Default

Initial value: 0

sc.ScaleValueOffset is a percentage value with a range from -1 to 1 for the offset of the scale from the center. A value of 1 means the graph will be pushed all the way off the bottom, and a value of -1 means the graph will be pushed all the way off the top. This is the value that gets changed when you use the Interactive Scale Move feature when you left click and drag the scale on the right side of the chart.

Example

sc.ScaleValueOffset = 0.25f

sc.AutoScalePaddingPercentage

Read/Write variable. Default

Initial value: 0

sc.AutoScalePaddingPercentage is a percentage value within the range of -1 to 1 where positive values mean more padding, and negative values mean inverse padding. A value of 0.4 means that padding takes up 40% of the chart, and the graph uses the rest of the 60%. This is the value that gets changed when you use the Interactive Scale Range feature when you left click and drag the scale on the right side of the chart.

Example

sc.AutoScalePaddingPercentage = 0.3f;

sc.NumberOfArrays

Read variable

Initial value: 1

sc.NumberOfArrays is the number of sc.Subgraph[].Data[] arrays that are allocated for the study to use. This gets set automatically as you use the sc.Subgraph[].Data[] arrays.

Example

// Loop through all of the subgraph arrays that are used
for (int SubgraphIndex = 0; SubgraphIndex < sc.NumberOfArrays; ++SubgraphIndex)
{
    sc.Subgraph[SubgraphIndex].Data[0] = 0;
}

sc.IsCustomChart

Read/Write integer variable. Default

Initial value: 0 (false)

Set sc.IsCustomChart to 1 (true) to make your study work as a custom chart. As a custom chart, your study will need to control the size of it's sc.Subgraph[].Data arrays using the sc.ResizeArrays() and sc.AddElements() functions. Your study will also need to set the DateTimes in the sc.DateTimeOut[] array. For a complete example, see the scsf_CopyOfBaseGraph() function in customchart.cpp in the ACS_Source folder in the Sierra Chart installation folder.

The only reason you would want to create a custom chart and use this variable, is if you need to create a bar chart or some other style chart that is of a different size, either or smaller or greater, than the underlying data it is based on. In other words, either smaller or greater than the existing price bars in the chart. For example, you may want to create your own specialized range bar chart or Point and Figure chart. The customchart.cpp file provided gives an example of a simple custom chart.

Example

sc.IsCustomChart = 1; // Set this study as a custom chart
sc.GraphRegion = 0; // Custom charts need to be set to use chart region 0

sc.GraphDrawType

Read/Write variable. Default

Initial value: GDT_CUSTOM

sc.GraphDrawType can be set to one of the values in the list below. If you use GDT_CUSTOM, which is the default, then your study will be able to use the sc.Subgraph[].DrawStyle member to set the style for each subgraph. If you us a value other than GDT_CUSTOM, then the draw type will be a type of price bar which uses the data in sc.Subgraph[0 through 4]. Use the: sc.Subgraph[SC_OPEN][] array for Open values, sc.Subgraph[SC_HIGH][] array for High values, sc.Subgraph[SC_LOW][] array for Low values, and the sc.Subgraph[SC_LAST][] array for Close or Last values.

If you set this to a value other than GDT_CUSTOM and you also set the sc.DisplayAsMainPriceGraph variable to 1 (true), you should also calculate the average values and fill in the sc.Subgraph[SC_VOLUME][] and sc.Subgraph[SC_NT][] arrays. To calculate the averages, make a call to sc.CalculateOHLCAverages().

When you use a sc.GraphDrawType setting value other than GDT_CUSTOM, then the sc.Subgraph[].DrawStyle variable is automatically set for each of the relevant sc.Subgraphs needed by the sc.GraphDrawType. You cannot change them. Additionally, it is not possible when you're drawing a price bar type of graph (GraphDrawType not equal to GDT_CUSTOM), to also use standard study lines or other Draw Styles using the other available sc.Subgraphs which are not used by the GraphDrawType. You will need to use a separate study for those.

Possible Values

Example

sc.GraphDrawType = GDT_OHLCBAR;

sc.DisplayAsMainPriceGraph

Read/Write variable. Default

Initial value: 0 (false)

If sc.DisplayAsMainPriceGraph is set to 1 (true), then your study will become the main Price Graph for the chart. All other studies applied to the chart, will be based on it. You probably will want the set sc.GraphRegion to 0, when setting this variable to 1 (true). If it is set to 0 (false), then your study is a normal study based on the existing main Price Graph.

Example

sc.DisplayAsMainPriceGraph = 1; // Set the study to the main Price Graph

sc.StandardChartHeader

Read/Write variable. Default

Initial value: 0 (false)

If sc.StandardChartHeader is set to 1 (true), then your study will use the standard main Price Graph text header. This text header can be configured by going to Global Settings >> Customize Chart Header on the menu. If you set this to 1 (true), you must also set sc.DisplayAsMainPriceGraph to 1 (true), otherwise it will be ignored.

Example

sc.DisplayAsMainPriceGraph = 1; // Set the study to the main Price Graph
sc.StandardChartHeader = 1;

sc.TextInput

Read/Write variable. Default

Initial value: "" (empty string)

sc.TextInput is the text input string that's made available in the study's inputs. The text input can be found at the bottom of the list of inputs shown on the Inputs and Settings tab in the Technical Study Settings window. This string can not be longer than 255 characters.

You must have the sc.TextInputName set if you want to have the text input available to the user.

Example

// Make a copy of the text input into our own c-style string. Be very careful
// when using this and make sure you will not use an invalid index into the
// string array. If this string is not used properly, the study could crash.
char TextInputCopy[256];
strncpy(TextInputCopy, sc.TextInput.GetChars(), sizeof(TextInputCopy) - 1);

sc.TextInputName

Read/Write variable. Default

Initial value: "" (empty string)

sc.TextInputName is a string of the name that is shown in the table of inputs on the Inputs and Settings tab in the Technical Study Settings window. You must set this to make the text input available to the user.

Example

sc.TextInputName = "Letters"; // Show the text input with the name Letters

sc.Input[]

Type: Array of Input structures

sc.Input[] is an array of the inputs available to the study. There is a maximum of SC_INPUTS_AVAILABLE (64) inputs available for your study to use. There are up to 64 inputs beginning with version 298 and higher.

Remember that all arrays are indexed starting at 0. That means the first element is at index 0, the second element is at index 1, and so on. For example: sc.Input[0] refers to the first input and sc.Input[9] refers to the tenth input. The highest index you can use for this is 31 (SC_INPUTS_AVAILABLE - 1). For example, sc.Input[31] is the last input.

Using References to an Input.

The following are the members of the input structure:

Using References to Inputs

The Input reference type, SCInputRef, can be used to set a reference to any of the available inputs to simplify writing code. It is most recommended you use SCInputRef, to make your code more readable. Please see the example below.

Example

SCSFExport scsf_StudySubgraphDifference(SCStudyGraphRef sc)
{
    SCSubgraphRef Diff = sc.Subgraph[0];
    SCInputRef Study1 = sc.Input[0];
    SCInputRef Study1Subgraph = sc.Input[1];
    SCInputRef Study2 = sc.Input[2];
    SCInputRef Study2Subgraph = sc.Input[3];

    if (sc.SetDefaults)
    {

        sc.GraphName = "Study Subgraph Difference";
        sc.StudyDescription = "Study Subgraph Difference";

        sc.DrawZeros = 1;
        sc.AutoLoop = 1;
        sc.CalculationPrecedence = LOW_PREC_LEVEL;

        sc.FreeDLL=0;

        Diff.Name = "Diff";
        Diff.DrawStyle = DRAWSTYLE_LINE;
        Diff.LineWidth = 1;

        Study1.Name = "Input Study 1";
        Study1.SetStudyID(0);

        Study1Subgraph.Name = "Study 1 Subgraph";
        Study1Subgraph.SetSubgraphIndex(0);

        Study2.Name = "Input Study 2";
        Study2.SetStudyID(0);

        Study2Subgraph.Name = "Study 2 Subgraph";
        Study2Subgraph.SetSubgraphIndex(0);


        return;
    }

    SCFloatArray Study1Array;

    sc.GetStudyArrayUsingID(Study1.GetStudyID(),Study1Subgraph.GetSubgraphIndex(),Study1Array);


    SCFloatArray Study2Array;

    sc.GetStudyArrayUsingID(Study2.GetStudyID(),Study2Subgraph.GetSubgraphIndex(),Study2Array);

    int i = sc.Index;
    Diff[i] = Study1Array[i] - Study2Array[i];
}

sc.Subgraph[]

Type: Array of Subgraph structures.

sc.Subgraph[] is an array of the subgraphs available to the study. There is currently a maximum of SC_SUBGRAPHS_AVAILABLE (40) subgraphs available for your study to use.

Subgraphs have two purposes. The first is to display data which is part of the study onto the chart. The individual drawings in a study graph are considered subgraphs. The second purpose is to hold data for background calculations or to hold data that needs to be maintained between function calls. If you are using the Data[] member array of a subgraph for the second purpose, then do not name a subgraph unless you want the data to appear on the chart. By default, subgraphs do not have names unless you set them. If you do want to make the background data visible for debugging purposes, then a subgraph can have a name. However in this case, set its draw style to DRAWSTYLE_IGNORE. This is very useful for debugging. The data can be viewed in the Window >> Chart Values Window.

There are also the Extra Arrays to hold data for background calculations and hold data that needs to be maintained between function calls. Please refer to the Extra Arrays member of this Subgraph structure.

The following are the members of the subgraph structure:

sc.OutArraySize

Read integer variable

sc.OutArraySize is the number of elements that are in the output arrays. This includes the sc.Subgraph[].Data[] arrays, the sc.Subgraph[].DataColor[] arrays if used, and the sc.DateTimeOut[] array. Normally this is the same as sc.ArraySize, but in the case when sc.IsCustomChart is used, the output arrays can have a different number of elements than the sc.BaseData[][] arrays.

sc.OutArraySize gets updated when you use the sc.ResizeArrays() and sc.AddElements() functions.

Example

// Resize the output arrays to be half the current size of the output arrays
sc.ResizeArrays(sc.OutArraySize / 2);

sc.DateTimeOut[]

Read/Write SCDateTime array.

sc.DateTimeOut[] is an array of the DateTimes for each of the bars you have created in a study which is set up as a custom chart. Each element is a SCDateTime. This array is only used when sc.IsCustomChart is set to 1 (true).

For additional information about indexing and array sizes, see Array Indexing and Sizes.

Code Example

// Set the element at our CustomIndex in sc.DateTimeOut to match the current index in sc.BaseDateTimeIn
sc.DateTimeOut[CustomIndex] = sc.BaseDateTimeIn[sc.Index];

sc.DataStartIndex

Read/Write variable

Initial value: 0

Set sc.DataStartIndex to the index of the first element at which subgraphs should start to be drawn. This is to prevent Sierra Chart from drawing elements at the beginning of the subgraph arrays that don't have enough prior data to be properly calculated. For example: if you have a 10-bar moving average, this value should be set to 9. It should be set to 9 instead of 10 because array index values always begin at 0.

Example

sc.DataStartIndex = 9; // Start drawing the subgraphs at element index 9 (the 10th bar)

sc.TimeScaleAdjustment

Read Only. SCDateTime variable

sc.TimeScaleAdjustment is the difference between your Time Zone setting in Sierra Chart and GMT/UTC time. This variable is a SCDateTime variable. You can add or subtract this variable with any SCDateTime variable.

Example

// Figure out the DateTime of the last bar without the time offset applied.
// The DateTime values of sc.BaseDateTimeIn[] are already adjusted, so
// subtracting sc.TimeScaleAdjustment will undo the adjustment.
SCDateTime AdjustedDateTime = sc.BaseDateTimeIn[sc.ArraySize - 1] - sc.TimeScaleAdjustment;

Example

// Adjust a time and sales record time
// Assume TSRecord is a s_TimeAndSales record that we got from sc.GetTimeAndSales()
SCDateTime TSDateTime;
TSDateTime.SetDate(TSRecord.Date);
TSDateTime.SetTimeHMS(TSRecord.Hour, TSRecord.Minute, TSRecord.Second);
TSDateTime += sc.TimeScaleAdjustment;
// TSDateTime is now adjusted to match times on the chart

sc.ChartNumber

Read variable

sc.ChartNumber is set to the identifying number of the chart that the study is applied to. This is the same number that is shown on the top line of the chart. If the identifying number of the chart calling your function is #1, then the value of sc.ChartNumber will be 1.

sc.ChartDataType

Read variable

sc.ChartDataType is set to the data type of the underlying chart, that is intraday data or daily data.

Example

if (sc.ChartDataType == DAILY_DATA)
{
    // The chart is a daily chart
}
else if (sc.ChartDataType == INTRADAY_DATA)
{
    // The chart is an intraday chart
}

sc.SecondsPerBar

Read/Write variable

sc.SecondsPerBar is the number of seconds in one bar. This is set by the Days-Mins-Secs setting in the Chart Settings window. For example: for a 1-minute chart this would be 60, and for a 30-minute chart this would be 1800. This variable can be modified by you. Any changes to this variable will not go into effect until you return from your study function. But before the next call to the study function.

Example

// Make sure this chart has no more than 30 seconds per bar
if (sc.SecondsPerBar > 30)
    sc.SecondsPerBar = 30;

sc.TicksPerBar

Read/Write variable

In version 281 and up this variable has been renamed from sc.NumberOfTicks to sc.TicksPerBar.

sc.TicksPerBar is the number of ticks per bar setting for the chart. Changing this value will change the ticks per bar setting on the chart.

Example

// Make sure the number of ticks per bar is at least 100
if (sc.TicksPerBar < 100)
    sc.TicksPerBar = 100;

sc.VolumePerBar

Read/Write variable

In version 281 and up this variable has been renamed from sc.volumePerBar to sc.VolumePerBar.

sc.VolumePerBar is the volume per bar setting for the chart. Changing this value will change the volume per bar setting on the chart.

Example

// Make sure the volume per bar is at least 500
if (sc.VolumePerBar < 500)
    sc.VolumePerBar = 500;

sc.RangeBarValue

Read/Write variable

sc.RangeBarValue is the range bar value setting for the chart. Changing this value will change the range bar value setting on the chart.

sc.RangeBarType

Read variable

sc.RangeBarType can be a true (1) or false (0) value indicating the Range Bar Type 2 check option found in the Chart Settings window. This is 0 if the Range Bar Type 2 option is disabled, 1 if it is enabled.

sc.DailyDataBarPeriod

Read/Write integer variable

sc.DailyDataBarPeriod can be set to one of the following values: 1 = Days, 2 = Weekly, 3 = Monthly, 4 = Quarterly, 5 =, Yearly. Changing this value will change the Historical Chart Period setting for the chart. After you change this variable, the chart will be reloaded with the new Historical Chart Period only after your function returns. Therefore, during the current function call when you have changed this variable, the historical chart bars will still be at the prior period.

Example

sc.DailyDataBarPeriod = 2; // Set the chart to show weekly bars

sc.DaysPerBar

Read/Write variable

If the sc.DailyDataBarPeriod has a value of 1 (days), then sc.DaysPerBar is the number of days per bar on the Chart. Changing this value will change the number of days per bar setting on the chart.

Example

if (sc.DailyDataBarPeriod == 1) // 1 = days
    sc.DaysPerBar = 10; // Set the chart to 10 days per bar

sc.NumFillSpaceBars

Read/Write variable

sc.NumFillSpaceBars is the number of bars in the fill space.

Example

// Make sure there are at least 10 bars of fill space
if (sc.NumFillSpaceBars < 10)
    sc.NumFillSpaceBars = 10;

sc.PreserveFillSpace

Read/Write variable

This is the same as the Lock Fill Space command on the Chart menu. Set sc.PreserveFillSpace to 1 (true) to prevent the fill space from being filled in as new bars are added to the chart or when the chart is being scrolled. Set it to 0 (false) to allow the fill space to be filled in.

sc.SymbolData

Type: Read-Only data structure.

sc.SymbolData is a pointer to a data structure containing all of the current pricing and related data for the symbol of the chart. This includes the Depth of Market data, if supported for your service. The data in this structure is only valid when Sierra Chart is connected to the data feed and the symbol is receiving updates. Please see the /ACS_Source/scsymboldata.h file in the folder that Sierra Chart is installed to for the structure definition.

For an example to access Depth of Market data, see the scsf_DOMAccess() function in the /ACS_Source/studies.cppfile in the folder where Sierra Chart is installed to.

For some Data and Trading services you will need to start depth of market updates for the symbol. To do this select Chart >> Chart Settings >> Start Depth of Market Updates.

sc.DailyHigh

Type: Read-Only Variable.

sc.DailyHigh is the current daily high for the symbol.

sc.DailyLow

Read variable

sc.DailyLow is the current daily low for the symbol.

sc.DailyVolume

Read variable

sc.DailyVolume is set to the daily trade volume for the symbol of the chart. The value of this will only be valid while Sierra Chart is connected to the data feed.

sc.Bid

Read variable

sc.Bid is the current bid value for the symbol if bid and ask data is available.

sc.Ask

Read variable

sc.Ask is the current ask value for the symbol if bid and ask data is available.

sc.BidSize

Read variable

sc.BidSize is the current size of the bid when bid and ask data is available.

sc.AskSize

Read variable

sc.AskSize is the current size of the ask when bid and ask data is available.

sc.LastSize

Read variable

sc.LastSize is the size of the last trade.

sc.Symbol

Read - string variable

sc.Symbol is the symbol of the chart. To perform comparisons to this symbol, or to directly access it see How To Compare Strings and Directly Accessing a SCString, respectively.

sc.DataFile

Read variable

sc.DataFile is a string of the complete path and file name of the chart data file. If you change this, the new data file will be loaded. The new data file will not be loaded until after you return from your study function. But it will occur before the next call to the study function.

Example

sc.DataFile = "C:\\SierraChart\\Data\\QQQQ.scid"; // Specify a new chart data file, including the path, for the chart.

sc.DateTimeOfLastFileRecord

Read variable

sc.DateTimeOfLastFileRecord is the DateTime as a SCDateTime value of the last record in the data file. The time zone offset is applied.

sc.CurrentSystemDateTime

Read variable

sc.CurrentSystemDateTime is the current DateTime as a SCDateTime value. The time zone offset is applied.

sc.StartTime1

Read variable

sc.StartTime1 is the first start time for a day on the chart. This is a time value given as the number of seconds since midnight. For more information about how this variable can be used, please see SCDateTime.

sc.EndTime1

Read variable

sc.EndTime1 is the first end time for a day on the chart. This is a time value given as the number of seconds since midnight. For more information about how this variable can be used, please see SCDateTime.

sc.StartTime2

Read variable

sc.StartTime2 is the second start time for a day on the chart. This is only used if sc.UseSecondStartEndTimes is set to 1 (true). This is a time value given as the number of seconds since midnight. For more information about how this variable can be used, please see SCDateTime.

sc.EndTime2

Read variable

sc.EndTime2 is the second end time for a day on the chart. This is only used if sc.UseSecondStartEndTimes is set to 1 (true). This is a time value given as the number of seconds since midnight. For more information about how this variable can be used, please see SCDateTime.

sc.UseSecondStartEndTimes

Read variable

sc.UseSecondStartEndTimes has a true (1) or false (0) value indicating that the second set of start and end times (i.e. sc.StartTime2 and sc.EndTime2) are used.

sc.StartTimeOfDay

Read variable

sc.StartTimeOfDay Is set to the starting time of the trading session for the day. This is based on the Session Times settings. It is an integer value representing seconds since midnight. For more infromation see SCDateTime. It can be converted to an SCDateTime type by using SCDateTimeVariable.SetTime(sc.StartTimeOfDay);.

Example

SCDateTime DT;
DT.SetTime(sc.StartTimeOfDay);

sc.LastCallToFunction

Read variable

sc.LastCallToFunction is set to 1 (true) when your Advanced Custom Study is in the process of being removed from the chart. This flag is useful if you want to do something before the study is removed from the chart.

Example

if (sc.LastCallToFunction)
{
    // This study is being removed from the chart
    // Insert cleanup code here
}

sc.PersistVars

Pointer to structure of Read/Write variables

Initial value: 0 (for all the persistent variables in the structure)

sc.PersistVars is a pointer to a data structure of persistent variables. There are 16 integers, 16 floats and 24 doubles in the persistent variables structure, all of which are reserved for you to use for whatever you need in your study. These 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.

Structure Members:

You can use references to give names to the persistent variables. This is helpful because it makes your code easier to understand and work with.

Example

// You can use references to give the persistent variables
// more descriptive names that you can use.

// MyCounter is a reference to sc.PersistVars->i1
int& MyCounter = sc.PersistVars->i1;

// MyAverage is a reference to sc.PersistVars->f3
float& MyAverage = sc.PersistVars->f3;

// We are using the reference we made above.
// This is the same as: sc.PersistVars->i1 += 1;
MyCounter += 1;

// We are using the reference we made above.
// This is the same as: sc.PersistVars->f3 = 10.0f;
MyAverage = (10.0f+24.0f)/2.0f;

// We are using the reference we made above.
MyAverage = (sc.Subgraph [2][sc.Index]+24.0f)/2.0f;

sc.StorageBlock

Read/Write variable

sc.StorageBlock is a pointer to a block of 512 bytes of permanent memory storage. This block of memory can be used for your custom data storage, and it is saved to disk when the chartbook is saved.

Example

// This is the structure of our data that is to be stored in the storage block
struct s_PermData
{
    int Number;
    char Text[32];
};

// Here we make a pointer to the storage block as if it was a pointer to our structure
s_PermData* PermData;
PermData = (s_PermData*)sc.StorageBlock;

// Here we set data using the members of our structure
// This uses the memory of the storage block
PermData->Number = 10;
strcpy(PermData->Text, "Sample Text");

sc.ActiveToolIndex

Read variable

sc.ActiveToolIndex is the data index at which the current tool is over.

When you use this variable it may be a good idea to use sc.UpdateAlways so that you are aware of the new tool position more often.

Example

float OpenValueAtTool = sc.BaseDataIn[SC_OPEN][sc.ActiveToolIndex]; // Get the Open value of the bar that the tool is over

sc.ActiveToolYPosition

Read variable

sc.ActiveToolYPosition is the Y- coordinate in pixels of the current tool's position over the chart your study function is applied to.

When you use this variable it may be a good idea to use sc.UpdateAlways so that you are aware of the new tool position more often.

sc.IndexOfFirstVisibleBar

Read variable

sc.IndexOfFirstVisibleBar is the data index of the first bar that is drawn on the chart. If you are relying on this member and want to be aware of changes such as when the user scrolls the chart, you may want to set sc.UpdateAlways to 1 (true).

Example

float OpenValueAtTool = sc.BaseDataIn[SC_LAST][sc.IndexOfFirstVisibleBar]; // Get the Close value of the first bar that's drawn

sc.IndexOfLastVisibleBar

Read variable

sc.IndexOfLastVisibleBar is the data index of the last bar that is drawn on the chart. This may not always be accurate. For example, it will be 0 when the chart is first loaded. If you are relying on this member and want to be aware of changes such as when the user scrolls the chart, you may want to set sc.UpdateAlways to 1 (true).

Example

float OpenValueAtTool = sc.BaseDataIn[SC_LAST][sc.IndexOfLastVisibleBar]; // Get the Close value of the last bar that's drawn

sc.ChartBackgroundColor

Read/Write variable

sc.ChartBackgroundColor is the background color of the chart. This can be either the global color setting, or the chart specific setting. You can change the chart background color with this variable. If you do change it, it is necessary to set sc.UseGlobalChartBackgroundColor = 0;.

Example

sc.UseGlobalChartBackgroundColor = 0;
sc.ChartBackgroundColor = RGB(123,123,123);

sc.ChartTextFont

Read variable

sc.ChartTextFont is a string of the font face that is used for text on the chart in Sierra Chart. This is useful if you want to create a font that that matches the chart text.

sc.StudyRegionTopCoordinate

Read variable

sc.StudyRegionTopCoordinate is the Y-coordinate of the top of the region that the study is in. This value is given in the coordinate system of the client window.

sc.StudyRegionBottomCoordinate

Read variable

sc.StudyRegionBottomCoordinate is the Y-coordinate of the bottom of the region that the study is in. This value is given in the coordinate system of the client window.

sc.VersionNumber

Read string variable

sc.VersionNumber is a string containing the current version number of Sierra Chart the user is using. Note: If your Advanced Custom Study is used on a version of Sierra Chart that does not support all of the interface members compared with the version it was built under, then a warning message will be given and the study cannot be used. Therefore, using this version number member to perform a check to see if your study will work on a certain version, is unnecessary.

Example

if (atoi(sc.VersionNumber) < 145)
{}//do something

sc.FileRecordIndexOfLastDataRecordInChart

Read Integer variable

FileRecordIndexOfLastDataRecordInChart is the index of the last data record read from the data file for the chart. This is not necessarily the very last data record in the file. For example, if a replay is in progress, it can be earlier than the last record in the file.

sc.UserName

Read-only Character string (SCString)

sc.UserName is the Account Name that was entered at the Sierra Chart Login window which displays when Sierra Chart starts.

sc.ChartWindowHandle

Read-Only HWND variable

sc.ChartWindowHandle is the Windows API handle (HWND) for the chart window that the study is applied to. This is useful when making Windows API function calls that require a window handle. This is for advanced programming only.

sc.ProcId

Read Integer variable

sc.ProcId is the ID of Sierra Chart process. This variable is for advanced programming only.

sc.TickSize

Read variable

sc.TickSize is a float that is set to the Tick Size of the chart.

sc.AlertOnlyOncePerBar

Read/Write variable. Default

sc.AlertOnlyOncePerBar can be set to 1 or 0 (true/false) to make the alert only activate once per bar. This works with the sc.SetAlert() function.

sc.ResetAlertOnNewBar

Read/Write integer variable. Default

sc.AlertOnlyOncePerBar can be set to 1 or 0 (true/false) to force an alert set with sc.SetAlert() to reset when there is a new bar. This works with the sc.SetAlert() function.

sc.DownloadingHistoricalData

Type: Read-only integer variable. Default

sc.DownloadingHistoricalData will be set to 1 when historical data is being downloaded in the chart. Otherwise, it will be set to 0. This variable can be useful when calling functions that play alert sounds. For example, if this is set to 1, then avoid calling the sc.PlaySound() function because many alerts may be generated by your study function from historical data being downloaded.

Example

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

sc.VolumeAtPriceForBars

Type: Read-only STL (C++ Standard Template Library) vector of STL map objects.

Sierra Chart internally maintains volume at price data for each price tick, based upon the Tick Size setting for the chart, within a loaded bar in the chart. This data is maintained when sc.MaintainVolumeAtPriceData is set to 1 (TRUE) in your custom study function. Or when there is a study on the chart which requires this data such as the Volume by Price study. This data is fully accessible through the ACSIL using the member sc.VolumeAtPriceForBars. For an example on how to use sc.VolumeAtPriceForBars, see the function scsf_VolumeAtPriceArrayTest in the studies7.cpp file in the /ACS_Source in the folder where Sierra Chart is installed to.

It is necessary to use the same version of Microsoft Visual C++ that we use to develop Sierra Chart when using this member to avoid compatibility problems. At the time of this writing we are using Microsoft Visual C++ 2008. It is fine if you are using the Express edition. Additionally, your DLL (dynamic link library) file must be built as a Release build and not a Debug build. Using the proper version of Visual C++ and building your DLL as a Release build are both essential. Otherwise you're going to have problems using this member.

sc.StudyIDNumber

Type: Read-only integer variable.

The StudyIDNumber is a unique number assigned to each study on a chart. This ID number is for the particular instance of your custom study which is applied to the chart. This ID number can be seen in the Chart Studies window on the right side of the study name in the Studies to Graph list.

Example

int StudyID = sc.StudyIDNumber;

sc.DrawBaseGraphOverStudies

Type: Read/Write Integer variable.

The sc.DrawBaseGraphOverStudies variable is the same as the Chart >> Chart Settings >> Display Main Chart Graph on Top of Studies setting. When it is set to a nonzero value, then the main chart graph will be displayed on top of other studies on the chart. Otherwise, the studies will be on top of the main chart graph.

Example

sc.DrawBaseGraphOverStudies = 1;


Functions

Notes About Output Arrays for Functions

Study functions require output arrays. These can take one of two types. Either a SCFloatArrayRef or SCSubgraphRef. The parameter name is either Out or contains the word Out.

SCFloatArrayRef: For this type you can pass a Subgraph Data array using sc.Subgraph[] or sc.Subgraph[].Data. Both of these are equivalent to each other. In each case the sc.Subgraph[]'s Data array of floats will get passed in. Or, you can pass in a Subgraph 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 sc.Subgraph[] Data arrays, then use a Subgraph Extra array by using sc.Subgraph[].Array[] .

SCSubgraphRef: For this type you can only pass a sc.Subgraph[]. This type is required because internally the function will use the available 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 documented in the corresponding functions. 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 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 Subgraph.

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 Subgraph Data arrays as parameters and do not require the Index parameter. These functions are also known as intermediate array based study functions, whether they use 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. These versions that do not require the Index parameter simplify the calling of these functions. If your study function uses auto looping, sc.AutoLoop = 1; in the if(sc.SetDefaults) block, then you can use these functions. These functions will not function properly when you are using Manual Looping. You will see an example below where we make a call to an array based study function that uses the Index parameter and another call to a second version of the function that does not use the Index parameter.

Most of the study code that Sierra Chart comes with, makes calls to the versions that do use the Index parameter. This is because the versions that do not require the Index parameter have been added after most of the code was written.

If you are using Automatic looping, then you can use a version of an array based study 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 easier.

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 array-based study functions that take a SCFloatArrayRef or SCSubgraphRef parameter, will return a SCFloatArray object by reference. This is the Out parameter and is either the SCFloatArray or the Data member of the SCSubgraph passed in.

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[InputData.GetInputDataIndex()],
MidBand,
Length.GetInt(),
StandardDeviations.GetFloat(),
MAType.GetMovAvgType() )[sc.index];


sc.AdaptiveMovAvg()

Type: Function

SCFloatArrayRef AdaptiveMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length, float FastSmoothConstant, float SlowSmoothConstant);

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

sc.AdaptiveMovAvg() calculates the adaptive moving average of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.AddAlertLine()

Type: Function

void AddAlertLine(SCString Message, long ShowAlertLog = 0);

void AddAlertLine(char* Message, long ShowAlertLog = 0);

sc.AddAlertLine() is a function for allowing you to add an alert line to the Sierra Chart Alert Log (Window >>Show/Hide Alert Log). This function creates a special text line so that the Go to Chart command on the Alert Log can be used. The message text can be any text that you want to display in the log. Message can be either a SCString or a plain C++ string ("This is an Example"). ShowAlertLog should be set to 1 to cause the alert log to open, if it is not already, when a message is added. Otherwise, ShowAlertLog should be 0 or it can be optionally left out to not open the log when a message is added. 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

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

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

SCString MyString= "This is my string.";
sc.AddAlertLine(MyString,1);

If you want to make an alert line that contains formatted variables, please see the Working With Strings and Setting Names section on the Advanced Custom Study Interface and Language page.

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

void AddMessageToLog( SCString& Message, long 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 line that contains formatted variables to add to the log, please see the Working With Strings and Setting Names section on the Advanced Custom Study Interface and Language page.

sc.ADX()

Type: Function

4 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2], Arrays[3])

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

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

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

Parameters

Example

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

sc.ADXR()

Type: Function

5 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2], Arrays[3], Arrays[4])

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

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

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

Parameters

Example

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

sc.AreRangeBars()

Type: Function

int AreRangeBars()

sc.AreRangeBars() returns a value, true(1) if the bars are range bars, otherwise returns false(0).

Example

int RangeBars = sc.AreRangeBars();

sc.AreTickBars()

Type: Function

int AreTickBars()

sc.AreTickBars() returns a value, true(1) if the bars are tick bars, otherwise returns false(0).

Example

int TickBars = sc.AreTickBars();

sc.AreTimeSpecificBars()

Type: Function

int AreTimeSpecificBars()

sc.AreTimeSpecificBars() returns a value, true(1) if the bars are time specific, otherwise 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: Function

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

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

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

Parameters:

Example

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

sc.ATR()

Type: Function

1 extra arrays used (Arrays[0]).

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

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

sc.ATR() calculates the true range of the data in the BaseDataIn arrays, and performs a moving average over the length specified by Length for the element at Index. The average true range is written to the ATROut subgraph array at the Index element. MovingAverageType needs to be set to the type of moving average you want to use. For the MovingAverageType values, please see the Moving Average Types section.

Example

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

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 index, specified with BarIndex, 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 Worksheet studies. It has several return values described below. See the scsf_GetBarHasClosedStatusExample() 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. 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[][index], the variable index is the index this function looks at when it is specified through BarIndex.

Return Values:

Example

if(sc.GetBarHasClosedStatus(index)==BHCS_BAR_HAS_NOT_CLOSED)
{
return;//do not do any processing if the bar at our current index has not closed
}

sc.BollingerBands()

Type: Function

SCFloatArrayRef BollingerBands (SCFloatArrayRef In, SCSubgraphRef Out, int Index, int Length, float Multiplier, int MovingAverageType);

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

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

Parameters:

Example

sc.BollingerBands(sc.BaseData[SC_LAST], sc.Subgraph[0], sc.Index, 10, MOVAVGTYPE_SIMPLE);
//Access the individual lines
float Average = sc.Subgraph[0][sc.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.CCI()

Type: Function

Internally uses 1 sc.Subgraph[].Arrays[] (Arrays[0]).

SCFloatArrayRef CCI(SCFloatArrayRef In, SCSubgraphRef Out, int Index, int Length, float Multiplier);

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

sc.CCI() calculates the commodity channel index of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.ChaikinMoneyFlow()

Type: Function

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

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

sc.ChaikinMoneyFlow() calculates the Chaikin Money Flow.

Parameters:

Example

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

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 subgraph has crossed the Second subgraph at the index specified by Index. For example code please see the scsf_StochasticCrossover function inside the systems.cpp file inside the ACS_Source folder inside of the Sierra Chart installation folder.

Function return values:

Example

if (sc.CrossOver(sc.Subgraph[3], sc.Subgraph[4], sc.Index) == CROSS_FROM_BOTTOM)
{
    //Code
}

sc.CummulativeSummation()

Type: Function

SCFloatArrayRef CummulativeSummation (SCFloatArrayRef In, SCFloatArrayRef Out, int Index);

SCFloatArrayRef CummulativeSummation (SCFloatArrayRef In, SCFloatArrayRef Out); Auto-looping only.

sc.CummulativeSummation calculates the cumulative summation of all elements up to and including the element at Index.

Parameters:

Example

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

sc.DeleteLineOrText()

Type: Function

For more information please see the sc.DeleteLineOrText() section on the Using Tools From an Advanced Custom Study page.

sc.Dispersion()

Type: Function

SCFloatArrayRef Dispersion(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef Dispersion(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.Dispersion() calculates the dispersion.

Parameters:

Example

//sc.BaseDataIn[SC_HIGH] - Input array of HIGH values.
//sc.Subgraph[0] - Output array.
//sc.Index - Index element where result is written to.
//10 - The number of elements or length used in the calculation.
sc.Dispersion(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], sc.Index, 10);

sc.DMI()

Type: Function

5 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2], Arrays[3], Arrays[4])

void DMI(SCBaseDataRef BaseDataIn, SCSubgraphRef Out, int Index, int Length);

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

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

Parameters

Example

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

//Access the individual lines
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: Function

3 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2])

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

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

sc.DMIDiff() calculates the Directional Movement Index Difference.

Parameters

Example

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

sc.EnvelopePct()

Type: Function

1 extra array used. (Arrays[0])

SCFloatArrayRef EnvelopePct(SCFloatArrayRef In, SCSubgraphRef Out, float Percent, int Index);

SCFloatArrayRef EnvelopePct(SCFloatArrayRef In, SCSubgraphRef Out, float Percent); Auto-looping only.

sc.EnvelopePct() calculates a Percentage Envelope.

Parameters:

Example

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

//Access the individual lines
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: Function

6 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2], Arrays[3], Arrays[4], Arrays[5])

SCFloatArrayRef Ergodic(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int LongEMALength, int ShortEMALength, float Multiplier);

SCFloatArrayRef Ergodic(SCFloatArrayRef In, SCFloatArrayRef Out, int LongEMALength, int ShortEMALength, float Multiplier); Auto-looping only.

sc.Ergodic() calculates the True Strength Index. The true strength index (TSI) is calculated by the following formula:

Numerator = EMA( EMA( Price - LastPrice, LongEMALength), ShortEMALength)
Denominator = EMA( EMA( Abs(Price - LastPrice), LongEMALength), ShortEMALength)
TSI = Multiplier * Numerator / Denominator

Parameters:

Example

sc.Ergodic(
    sc.BaseDataIn[SC_LAST], // In
    sc.Subgraph[0], // Out (TSI)
    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: Function

SCFloatArrayRef ExponentialMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef ExponentialMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.ExponentialMovAvg() calculates the exponential moving average of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.FormatGraphValue()

Type: Function

SCString FormatGraphValue(double Value, int ValueFormat);

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

Parameters:

Example

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

sc.FormattedEvaluate()

Type: Function

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

sc.FormattedEvaluate() evaluates as an expression the given numbers and operator. The expression is as follows, Value1 Operator Value2. Value1 is rounded to the Value1Format value. Value2 is rounded to the Value2Format value. Returns 1 if the expression is true, and 0 if it is false.

Parameters:

Example

int Return = sc.FormattedEvaluate(currentClose, sc.ValueFormat, LESS_OPERATOR, priorLow, sc.ValueFormat);

sc.GetChartArray()

Type: Function

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

sc.GetChartArray() is for accessing the Base Data in other loaded charts in the same chartbook containing the chart that your study 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 inside the ACS_Source folder inside of the Sierra Chart installation folder for example code to work with this function.

Parameters:

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't do anything with it. if (PriceArray.GetArraySize() == 0)
    return;

sc.GetChartBaseData()

Type: Function

void GetChartBaseData(int ChartNumber, SCGraphData& BaseData);

sc.GetChartBaseData() is for accessing all of the Base Data arrays in another loaded chart in the same chartbook as the one containing the chart that your custom study is applied to. The 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 Renko chart study, then this function will get this new main price graph from the specified ChartNumber (be sure you are running the latest version for this). See the example below. For a complete working example, see Referencing Other Time Frames and Symbols When Using the ACSIL.

Parameters:

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

void 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:

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't do anything with it.
if (DateTimeArray.GetArraySize() == 0)
    return;

sc.GetChartDrawing()

Type: Function

For more information please see the sc.GetChartDrawing() section on the Using Tools From an Advanced Custom Study page.

sc.GetChartName()

Type: Function

long GetChartName(long 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

long GetContainingIndexForDateTimeIndex(long ChartNumber, long DateTimeIndex);

sc.GetContainingIndexForDateTimeIndex() returns the index into the data arrays of the chart specified by ChartNumber that contains the DateTime at the index, on the study's chart, specified by DateTimeIndex. If the DateTime at DateTimeIndex is before any DateTime in the other chart, then the index of the first element is given (0). If the DateTime at DateTimeIndex is after any DateTime in the other chart, then the index of the last element is given (size - 1).

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.

Example

// Get the index in the base data arrays for chart #2 that contains the DateTime at the currently calculating index of the chart that this study is on.

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

sc.GetContainingIndexForSCDateTime()

Type: Function

long GetContainingIndexForSCDateTime(long ChartNumber, SCDateTime DateTime);

sc.GetContainingIndexForSCDateTime() returns the index into the data arrays of the chart specified by ChartNumber that contains DateTime. If DateTime is before any DateTime in the chart specified by ChartNumber, then the index of the first element is given (0). If DateTime is after any DateTime in the chart specified by the ChartNumber, then the index of the last element is given (size - 1).

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.

Example

// Get the index in the base data arrays for chart #2 that contains the specified DateTime.

SCDateTime DateTime = sc.BaseDateTimeIn[sc.Index];
int Chart2Index = sc.GetContainingIndexForSCDateTime(2, DateTime);

sc.GetCorrelationCoefficient()

Type: Function

float GetCorrelationCoefficient(SCFloatArrayRef In1, SCFloatArrayRef In2, int Index, int Length);

float GetCorrelationCoefficient(SCFloatArrayRef In1, SCFloatArrayRef In2, int Length); Auto-looping only.

sc.GetCorrelationCoefficient() calculates the Pearson product-moment correlation coefficient. The result is returned as a single float.

Parameters:

Example


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

sc.GetDispersion()

Type: Function

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

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

sc.GetDispersion() calculates the dispersion.

Parameters:

Example

//Calculates dispersion for sc.BaseDataIn[SC_HIGH] with length 10
//and assigns return value to Disp variable.
float Disp = sc.GetDispersion(sc.BaseDataIn[SC_HIGH], 10, sc.Index);

sc.GetExactMatchForSCDateTime()

Type: Function

GetExactMatchForSCDateTime(long ChartNumber, SCDateTime DateTime);

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

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.

Example

// Get the index in chart #2's data that exactly matches the DateTime given through the first input
SCDateTime DateTime = sc.Input[0].GetDateTime(); // Get the DateTime from the first input
int Chart2Index = sc.GetExactMatchForSCDateTime(2, DateTime);
if(Chart2Index != -1)
{
    //Your Code
}

sc.GetHighest()

Type: Function

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

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

sc.GetHighest() determines the highest value in the In array starting at Index and over the Length array elements. This function does not fill in an output array, instead returns a single result.

Example

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

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

sc.GetIslandReversal()

Type: Function

int GetIslandReversal(SCBaseDataRef BaseDataIn, int Index);

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

sc.GetIslandReversal() calculates the Island Reversal. Function returns one of the following values:
0 - No Gap,
1 - Gap Up,
-1 - Gap Down.

Parameters:

Example

//sc.BaseDataIn - Base Data input arrays.
//sc.Index - Index element to process.
int i = sc.GetIslandReversal(sc.BaseDataIn, sc.Index);

sc.GetLowest()

Type: Function

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

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

sc.GetLowest() determines the lowest value in the In array starting at Index and over the Length array elements. This function does not fill in an output array, instead returns a single result.

Example

//Get the lowest low from the base graph over the last 20 bars
sc.GetLowest(sc.BaseDataIn[SC_LOW], 20);

//Get the lowest value from subgraph 0 over the last 20 bars
sc.GetLowest(sc.Subgraph[0], 20);

sc.GetMainGraphVisibleHighAndLow()

Type: Function

void GetMainGraphVisibleHighAndLow (float& High, float& Low);

sc.GetMainGraphVisibleHighAndLow will get the high and low for the visible part of main price graph in the chart.

Example

float High, Low;
sc.GetMainGraphVisibleHighAndLow(High,Low);

sc.GetNearestMatchForDateTimeIndex()

Type: Function

long GetNearestMatchForDateTimeIndex(long ChartNumber, long 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 (ArraySize - 1).

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.

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

long GetNearestMatchForSCDateTime(long 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 (ArraySize - 1).

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.

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.GetOHLCForDate()

Type: Function

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

sc.GetOHLCForDate() 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. A day is based upon the session time settings in Chart >> Chart Settings for the Chart. The end of the day is what is specified with the day session End Time. The day includes the 24 hours prior to that time.

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

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

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

sc.GetStudyArray()

Type: Function

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

sc.GetStudyArray() works similar to the sc.GetChartArray() function. It gets a study subgraph array. 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. The StudySubgraphNumber is 1-based and refers to a subgraph of the study, where 1 is the first subgraph.

See 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 you call this function it fills in the SubgraphArray parameter. If the function fails to get the requested study array for any reason, SubgraphArray will remain empty (i.e. SubgraphArray.GetArraySize() == 0).

A reason you would want to access studies on a chart rather than internally calculating them and putting the results into Subgraph[].Data[] 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. Currently studies are referenced by an index. Later on we plan to reference them through a unique ID which will not change as the study is moved up and down in the list of studies.

It is recommended that you set the calculation precedence to LOW_PREC_LEVEL, in the code block for setting your defaults and configuration, 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't do anything with it

sc.GetStudyArrayFromChart()

Type: Function

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

sc.GetStudyArrayFromChart() works identically to the sc.GetStudyArray() function, except that it lets you access studies on another chart. It requires a chart number parameter. The ChartNumber parameter is the number that is shown on the top line in the Chart window, after the #. The StudyNumber is 1-based, 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. The StudySubgraphNumber is 1-based and refers to a subgraph of the study, where 1 is the first subgraph.

If the function is unable to get the subgraph array, the array's size will be zero (For example, SubgraphArray.GetArraySize() == 0). For an example on how to use this function, see the scsf_GetStudyArrayFromChartExample() function in the studies.cpp file in the ACS_Source folder inside of the Sierra Chart installation folder.

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't do anything with it

sc.GetStudyArraysFromChart()

Type: Function

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

sc.GetStudyArraysFromChart() is for getting all of the subgraph arrays from a study on another chart.

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.

Parameters:

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.GetStudyArrayUsingID()

Type: Function

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

sc.GetStudyArrayUsingID() gets the specified Subgraph Data array from a study using the study's unique ID. These are studies that are on the same chart that your custom study is applied to. This function works identically to sc.GetStudyArray() except that the unique ID is used instead. This is an improvement over the prior function because 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 Input functions sc.Input[].GetStudyID() and sc.Input[].SetStudyID().

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

It is recommended that you set the calculation precedence to LOW_PREC_LEVEL, in the code block for setting your defaults and configuration, 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.

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.

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.GetStudyName()

Type: Function

char* GetStudyName(int StudyIndex);

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

sc.GetSummation()

Type: Function

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

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

sc.GetSummation() calculates the sum of a series of numbers in an array. The result is returned as float value.

Parameters:

Example

//Calculate the summation of an array
sc.GetSummation(sc.BaseDataIn[SC_LAST],sc.Index,10);

sc.GetTimeAndSales()

Type: Function

void 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 structures. The number of Time and Sales records you receive is based on program settings (Explained below). See the TimeAndSales() 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. Additionally, see the scsf_TimeAndSalesPrice() (Time and Sales Price), scsf_TimeAndSalesVolume() (Time and Sales Volume), and scsf_TimeAndSalesTime() (Time and Sales Time) functions for an example on how to use time and sales.

Level is a member of the s_TimeAndSales structure. For the level constants and meanings, see the Level values for s_TimeAndSales section in the scconstants.h file. If Level is 1 to 5, then all members of s_TimeAndSales are set. The bid and ask are set to the current values at the time of the trade. If Level is 6, all members are set, except for Price and Volume. For the definition of the s_TimeAndSales structure, see the sierrachart.h file in the /ACS_Source folder.

This function, based on program settings (Explained below) , can also include all bid, ask, bid size, and ask size data received from the data feed.

In order for Sierra Chart to store Time and Sales data and for you to be able to access it with this function, select Global Settings >> Data/Trade Service Settings and enable the "Maintain Time and Sales" option. Set the related settings as needed. After changing Time and Sales settings, you need to reconnect to the data feed using the 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. This number is not reset when reconnecting to the data feed. The only time it is reset back to 1, is when the program is restarted. In that case, Time and Sales data is lost. This unique sequence number gives you useful information on which Time and Sales records you have already processed and which you need to process. For example, if the last sequence number available during the prior call to your function was 508, then only records after that you will need to process. You can store the last sequence number processed in sc.PersistVars, in order to know it on the next call into your function.

Example

SCTimeAndSalesArray TSArray;
sc.GetTimeAndSales(TSArray);
if (TSArray.GetArraySize() == 0)
    return; // We didn't get any time and sales data, so there's nothing we can do with it

Alternative Way For Obtaining Time and Sales Data:

Open a 1 tick chart for the symbol you want Time and Sales for. Select File >> 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 and volume arrays and the DateTime array. Every element in these arrays is 1 tick. This may actually be a preferred way of accessing time and sales since there will be abundant amount of history available.

sc.GetTradingDayStartDateTimeOfBar()

Type: Function

SCDateTime GetTradingDayStartDateTimeOfBar(SCDateTime& BarDateTime);

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

Parameters:

sc.GetTrueHigh()

Type: Function

float GetTrueHigh(SCBaseDataRef BaseDataIn, int Index);

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

sc.GetTrueHigh() calculates the true high. 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 high = sc.GetTrueHigh(sc.BaseDataIn, sc.Index);

sc.GetTrueLow()

Type: Function

float GetTrueLow(SCBaseDataRef BaseDataIn, int Index);

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

sc.GetTrueLow() calculates the true low. 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 low = sc.GetTrueLow(sc.BaseDataIn, sc.Index);

sc.GetTrueRange()

Type: Function

float GetTrueRange(SCBaseDataRef BaseDataIn, int Index);

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

sc.GetTrueRange() calculates the true range. The result is returned as a single float value.

Parameters:

Example

float range = sc.GetTrueRange(sc.BaseDataIn, sc.Index);

sc.Highest()

Type: Function

SCFloatArrayRef Highest(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef Highest(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.Highest() determines the highest value over the the Length array elements starting at Index in the In array. The result is written to the element at Index in the Out array.

Example

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

sc.HullMovingAverage()

Type: Function

SCFloatArrayRef HullMovingAverage (SCFloatArrayRef In, SCSubgraphRef Out, int Index, int Length);

SCFloatArrayRef HullMovingAverage (SCFloatArrayRef In, SCSubgraphRef Out, int Length); Auto-looping only.

sc.HullMovingAverage() calculates a Hull Moving Average.

Parameters

Example

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

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: Function

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

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

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

Parameters

Example

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

sc.IsSwingLow()

Type: Function

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

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

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

Parameters

Example

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

sc.Keltner()

Type: Function

4 Subgraph extra arrays used. (Arrays[0], Arrays[1] , Arrays[2] , Arrays[3] )

SCFloatArrayRef Keltner(SCBaseDataRef BaseDataIn, SCFloatArrayRef In, SCSubgrapRef Out, int Index, int KeltnerMALength, unsigned int KeltnerMAType, int TrueRangeMALength, unsigned int TrueRangeMAType, float TopBandMultiplier, float BottomBandMultiplier);

SCFloatArrayRef Keltner(SCBaseDataRef BaseDataIn, SCFloatArrayRef In, SCSubgrapRef Out, int KeltnerMALength, unsigned int KeltnerMAType, int TrueRangeMALength, unsigned int TrueRangeMAType, float TopBandMultiplier, float BottomBandMultiplier); Auto-looping only.

sc.Keltner() calculates the Keltner average, top and bottom bands from the data in BaseDataIn and the In data arrays. The inputs are specified with the KeltnerMALength, KeltnerMAType, TrueRangeMALength, TrueRangeMAType, TopBandMultiplier, BottomBandMultiplier parameters. The results are written to the elements at Index in the Out Subgraph Data and Extra arrays. See example below.

See the Moving Average Types section for the values for KeltnerMAType and TrueRangeMAType.

Example

sc.Keltner(
    sc.BaseDataIn,
    sc.BaseDataIn[SC_LAST],
    sc.Subgraph[0],
    sc.Index,
    10,
    MOVAVGTYPE_SIMPLE,
    10,
    MOVAVGTYPE_WILDERS,
    1.6f,
    1.6f,
); //Access the individual 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: Function

SCFloatArrayRef LinearRegressionIndicator(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef LinearRegressionIndicator(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.LinearRegressionIndicator() calculates the linear regression of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.LineExists()

Type: Function

For more information please see the sc.LineExists() section on the Using Tools From an Advanced Custom Study page.

sc.Lowest()

Type: Function

SCFloatArrayRef Lowest(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef Lowest(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.Lowest() determines the lowest value over the Length array elements starting at Index in the In array. The result is written to the element at Index in the Out array.

Example

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

sc.MACD()

Type: Function

SCFloatArrayRef MACD (SCFloatArrayRef In, SCSubgraphRef Out, int Index, int FastMALength, int SlowMALength, int MACDMALength, int MovAvgType);

SCFloatArrayRef MACD (SCFloatArrayRef In, SCSubgraphRef Out, int FastMALength, int SlowMALength, int MACDMALength, int MovAvgType); Auto-looping only.

sc.MACD() calculates the MACD lines.

Parameters:

Example

sc.MACD(sc.BaseData[SC_LAST], sc.Subgraph[0], sc.Index, 5, 10, 10, MOVAVGTYPE_SIMPLE);
//Access the individual lines
float MACD = sc.Subgraph[0][sc.Index];
float MACDMA = 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] = MACDMA;
sc.Subgraph[2][sc.Index] = MACDDifference;

sc.Momentum()

Type: Function

SCFloatArrayRef Momentum(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);
SCFloatArrayRef Momentum(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.Momentum() calculates the momentum.

Parameters:

Example

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

sc.MovingAverage()

Type: Function

SCFloatArrayRef MovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, unsigned int MovingAverageType, int Index, int Length);

SCFloatArrayRef MovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, unsigned int MovingAverageType, int Length); Auto-looping only.

sc.MovingAverage() calculates a moving average of the type specified by MovingAverageType using the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array. Based on the value of the MovingAverageType parameter, sc.MovingAverage can calculate the following moving average types:

Example

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

sc.NumberOfBarsSinceHighestValue()

Type: Function

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

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

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

Parameters:

Example

//Number of bars between sc.Index and highest value in sc.BaseDataIn[SC_LAST] array. Highest value is calculated over the last 10 bars;
int hBars = sc.NumberOfBarsSinceHighestValue(sc.BaseDataIn[SC_LAST], sc.Index, 10);

sc.NumberOfBarsSinceLowestValue()

Type: Function

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

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

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

Parameters:

Example

//Number of bars between sc.Index and lowest value in sc.BaseDataIn[SC_LAST] array. Lowest value is calculated over the last 10 bars;
int hBars = sc.NumberOfBarsSinceLowestValue(sc.BaseDataIn[SC_LAST], sc.Index, 10);

sc.OnBalanceVolume()

Type: Function

SCFloatArrayRef OnBalanceVolume (SCBaseDataRef In, SCFloatArrayRef Out, int Index);

SCFloatArrayRef OnBalanceVolume (SCBaseDataRef In, SCFloatArrayRef Out); Auto-looping only.

sc.OnBalanceVolume() calculates the on balance volume of the data in the In array for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.OnBalanceVolumeShortTerm()

Type: Function

SCFloatArrayRef OnBalanceVolumeShortTerm(SCBaseDataRef In, SCFloatArrayRef Out, SCFloatArrayRef OBVTemp, int Index, int Length);

SCFloatArrayRef OnBalanceVolumeShortTerm(SCBaseDataRef In, SCFloatArrayRef Out, SCFloatArrayRef OBVTemp, int Length); Auto-looping only.

sc.OnBalanceVolumeShortTerm() calculates the on balance volume of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.Oscillator()

Type: Function

SCFloatArrayRef Oscillator(SCFloatArrayRef In1, SCFloatArrayRef In2, SCFloatArrayRef Out, int Index);

SCFloatArrayRef Oscillator(SCFloatArrayRef In1, SCFloatArrayRef In2, SCFloatArrayRef Out); Auto-looping only.

sc.Oscillator() calculates the oscillator between two input arrays.

Parameters:

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], sc.Index);

sc.Parabolic()

Type: Function

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

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

sc.Parabolic() description.

Parameters:

Example

sc.PlaySound()

Type: Function

int PlaySound(int AlertNumber);

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

int PlaySound(SCString AlertPath, int AlertCount = 1);

int PlaySound(SCString AlertPath, int AlertCount, SCString AlertMessage, long ShowAlertLog = 0)

To play an alert sound when a condition is true, it is recommended you use sc.SetAlert(), as it provides a more controlled logic for providing alerts.

sc.PlaySound() is used to play the specified alert sound number or the specified file. A sound will be played every time this function is called. There is no restriction logic used unlike sc.SetAlert(). The alerts sounds are queued up and played asynchronously. This function returns 1 on success, and 0 on failure.

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 play alert sounds and add alert messages.

Parameters:

Example

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

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

sc.PlaySound(1,"My Alert Message that pop up the Alert log",1);

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

sc.PriceVolumeTrend()

Type: Function

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

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

sc.PriceVolumeTrend() calculates the Price Volume Trend.

Parameters:

Example

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

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.Round()

Type: Function

int Round(float n)

sc.Round() takes a float and rounds it to the nearest int.

Example

int Rounded = sc.Round(1.2);
// Rounded will equal 1

sc.RoundToTickSize()

Type: Function

float RoundToTickSize(float n, float increment)

sc.RoundToTickSize() takes a float and rounds it to the nearest increment.

Example

int Rounded = sc.RoundToTickSize(1.2,0.25);
// Rounded will equal 1.25

sc.RSI()

Type: Function

4 extra arrays internally used (Arrays[0], Arrays[1], Arrays[2], Arrays[3])

SCFloatArrayRef RSI(SCFloatArrayRef In, SCSubgraphRef Out, int Index, unsigned long MovingAverageType, int Length)

SCFloatArrayRef RSI(SCFloatArrayRef In, SCSubgraphRef Out, unsigned long MovingAverageType, int Length) Auto-looping only.

sc.RSI() calculates the Wilder's Relative Strength Index.

Parameters:

Example

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

sc.RandomWalkIndicator()

Type: Function

SCFloatArrayRef RandomWalkIndicator(SCBaseDataRef In, SCSubgraphRef Out, int Index, int Length);

SCFloatArrayRef RandomWalkIndicator(SCBaseDataRef In, SCSubgraphRef Out, int Length); Auto-looping only.

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

Parameters:

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.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 lets you play an alert sound and add a message to the Alert Log when you have a condition that you want to provide a signal for at the specified array Index. The array index is the chart bar index. If you are using auto-looping, the Index parameter is auto set for you and does not need to be specified. The AlertNumber parameter sets the alert sound from 1 - 50 to be played. To configure alert sounds select Global Settings >> General Settings on the Sierra Chart menu. The Message parameter specifies the message you want to be added to the Alerts Log. If it is not specified, a standard message will be used. If you set an alert on an Index that is not at the end of a sc.Subgraph array, it will be ignored. However, if there are multiple bars added during an update, the alerts will be processed for all of them.

If historical data is being downloaded in the chart, then calls to this function are ignored. This is to prevent alert sounds and messages from occurring on historical data.

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

sc.SetAlert(). For an example see scsf_SimpMovAvg() in studies.cpp inside the ACS_Source folder inside of the Sierra Chart installation folder.

Note: When setting the Message parameter, be sure to use version 632 or higher to take advantage of improvements supporting this parameter.

Example

sc.SetAlert(5);

sc.SimpleMovAvg()

Type: Function

0 Subgraph Extra Arrays used.

SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.SimpleMovAvg() calculates the simple moving average of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.SmoothedMovingAverage()

Type: Function

0 Extra arrays used.

SCFloatArrayRef SmoothedMovingAverage (SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef SmoothedMovingAverage (SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.SmoothedMovingAverage() calculates a Smoothed Moving Average.

Parameters

Example

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

sc.StdDeviation()

Type: Function

SCFloatArrayRef StdDeviation(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef StdDeviation(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.StdDeviation() calculate the standard deviation of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.StdError()

Type: Function

SCFloatArrayRef StdError(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef StdError(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.StdError() calculate the standard error of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.Stochastic()

Type: Function

SCFloatArrayRef Stochastic(SCBaseDataRef BaseDataIn, SCSubgraphRef Out, int Index, int FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType);

SCFloatArrayRef Stochastic(SCBaseDataRef BaseDataIn, SCSubgraphRef Out, int FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType); Auto-looping only.

sc.Stochastic() calculates the Fast %K, Fast %D, Slow %D lines.

Parameters:

Example

sc.Stochastic(sc.BaseDataIn, sc.Subgraph[0], sc.Index, 10, 3, 3, MOVAVGTYPE_SIMPLE);
//Access the individual lines
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: Function

SCFloatArrayRef Summation (SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef Summation (SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.Summation calculates the sum of a series of numbers in an array.

Parameters:

Example

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

sc.TEMA()

Type: Function

SCFloatArrayRef TEMA (SCFloatArrayRef In, SCSubgraphRef Out, int Index, int Length);

SCFloatArrayRef TEMA (SCFloatArrayRef In, SCSubgraphRef Out, int Length); Auto-looping only.

sc.TEMA() calculates a triple exponential moving average.

Parameters:

Example

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

sc.TriangularMovingAverage()

Type: Function

SCFloatArrayRef TriangularMovingAverage (SCFloatArrayRef In, SCSubgraphRef Out, int Index, int Length);

SCFloatArrayRef TriangularMovingAverage (SCFloatArrayRef In, SCSubgraphRef Out, int Length); Auto-looping only.

sc.TriangularMovingAverage() calculates a Triangular Moving Average.

Parameters:

Example

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

sc.TRIX()

Type: Function

SCFloatArrayRef TRIX(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef TRIX(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.TRIX() calculates the TRIX.

Parameters:

Example

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

sc.TrueRange()

Type: Function

SCFloatArrayRef TrueRange(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out, int Index);

SCFloatArrayRef TrueRange(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out); Auto-looping only.

sc.TrueRange() calculates the True Range of bars from the data in BaseDataIn. The result is written to the element at Index in the Out array.

Example

sc.TrueRange(sc.BaseDataIn, sc.Subgraph[0], sc.Index);

sc.UltimateOscillator()

Type: Function

4 Subgraph extra arrays used. (Arrays[0], Arrays[1], Arrays[2], Arrays[3])

SCFloatArrayRef UltimateOscillator(SCBaseDataRef In, SCSubgraphRef Out, int Index, int Length1, int Length2, int Length3);

SCFloatArrayRef UltimateOscillator(SCBaseDataRef In, SCSubgraphRef Out, int Length1, int Length2, int Length3); Auto-looping only.

sc.UltimateOscillator() calculates the Ultimate Oscillator.

Parameters:

Example

sc.UltimateOscillator(sc.BaseDataIn, sc.Subgraph[0], 7, 14, 28);

sc.UseTool()

Type: Function

For more information please see the Using Tools with sc.UseTool() section on the Using Tools From an Advanced Custom Study page.

sc.VHF()

Type: Function

SCFloatArrayRef VHF(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef VHF(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.VHF() calculates the Vertical Horizontal Filter.

Parameters:

Example

//sc.BaseDataIn[SC_HIGH] - Input array of HIGH values.
//sc.Subgraph[0] - Output array.
//sc.Index - Index element where result is written to.
//10 - The number of elements or length used in the calculation.
sc.VHF(sc.BaseDataIn[SC_HIGH], sc.Subgraph[0], sc.Index, 10);

sc.VolumeWeightedMovingAverage()

Type: Function

SCFloatArrayRef VolumeWeightedMovingAverage (SCFloatArrayRef InData, SCFloatArrayRef InVolume, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef VolumeWeightedMovingAverage (SCFloatArrayRef InData, SCFloatArrayRef InVolume, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.VolumeWeightedMovingAverage() calculates a Volume Weighted Moving Average.

Parameters:

Example

sc.VolumeWeightedMovingAverage(sc.BaseData[SC_LAST], sc.BaseData[SC_VOLUME], sc.Subgraph[0], sc.Index, 10);

sc.WeightedMovingAverage()

Type: Function

SCFloatArrayRef WeightedMovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef WeightedMovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.WeightedMovingAverage() calculates the weighted moving average of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.WellesSum()

Type: Function

SCFloatArrayRef WellesSum (SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef WellesSum (SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.WellesSum() calculates a Welles Summation from the data in the In array over the length specified by Length. The result is written to the element at Index in the Out array.

Example

sc.WellesSum(sc.Subgraph[1], sc.Subgraph[0], sc.Index, 10);

sc.WildersMovingAverage()

Type: Function

SCFloatArrayRef WildersMovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef WildersMovingAverage(SCFloatArrayRef In, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.WildersMovingAverage() calculates the Wilder's moving average of the data in the In array over the length specified by Length for the element at Index. The result is written to the element at Index in the Out array.

Example

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

sc.WilliamsAD()

Type: Function

SCFloatArrayRef WilliamsAD(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out, int Index);

SCFloatArrayRef WilliamsAD(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out); Auto-looping only.

sc.WilliamsAD() calculates the Williams' Accumulation/Distribution.

Parameters:

Example

//sc.BaseDataIn - Base Data input arrays.
//sc.Subgraph[0] - Output array.
//sc.Index - Index element where result is written to.
sc.WilliamsAD(sc.BaseDataIn, sc.Subgraph[0], sc.Index);

sc.WilliamsR()

Type: Function

SCFloatArrayRef WilliamsR(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out, int Index, int Length);

SCFloatArrayRef WilliamsR(SCBaseDataRef BaseDataIn, SCFloatArrayRef Out, int Length); Auto-looping only.

sc.WilliamsR() calculates the Williams %R.

Parameters:

Example

//sc.BaseDataIn - Input array of HIGH values.
//sc.Subgraph[0] - Output array.
//sc.Index - Index element where result is written to.
//10 - The number of elements or length used in the calculation.
sc.WilliamsR(sc.BaseDataIn, sc.Subgraph[0], sc.Index, 10);

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);
// MinValue will equal 3