Sierra Chart ACSIL for Beginners. - futures io
futures io



Sierra Chart ACSIL for Beginners.


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Trembling Hand with 22 posts (133 thanks)
    2. looks_two mosalem2003 with 7 posts (0 thanks)
    3. looks_3 brach with 2 posts (2 thanks)
    4. looks_4 jokertrader with 1 posts (0 thanks)
    1. trending_up 7,382 views
    2. thumb_up 135 thanks given
    3. group 30 followers
    1. forum 33 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Sierra Chart ACSIL for Beginners.

(login for full post details)
  #1 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Hi I'm starting two threads on steps to get started using Sierra Charts Advanced Custom Study/System Interface and Language (ACSIL).

This thread I would like to keep just for examples and steps to producing your own Custom Studies and Trading systems in SC. And another thread for questions about the examples in this thread.

To start I recommend setting up MS Visual Studio to program in. You can write the C++ files in Notepad++ as a minimum and compile as per these directions from Sierra Chart but you will miss out on a lot of the programming tools, error reporting and auto filling that's available with a modern IDE.

So first steps download Visual Studio Community version,
https://visualstudio.microsoft.com/downloads/
(Its a big and bloated download)
You need to check the "Desktop development with C++" tools to include with the download but if not you can add them after install by going,
Tools>Get Tools And Features.. and the select them like in this pic and follow the modify/downloads and install instructions.


Follow me on Twitter Started this thread Reply With Quote
The following 21 users say Thank You to Trembling Hand for this post:

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(107 thanks from 17 posts)
looks_twoSalao's Journalby Salao
(33 thanks from 8 posts)
looks_3Deetee’s DAX Trading Journal (time based)by Deetee
(28 thanks from 12 posts)
looks_4Learning to Profit - A journey in algorithms and optionsby Syntax
(14 thanks from 9 posts)
looks_5Maybe a little bit different journalby Malykubo
(9 thanks from 8 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Would You Sell Your System?
73 thanks
Big Mike in Ecuador
44 thanks
The Crude Dude Oil Trading System
44 thanks
The New Micro Contract - MICRO BITCOIN coming May 2021
25 thanks
futures io site changelog and issues/problem reporting
24 thanks
 
(login for full post details)
  #2 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Ok once MS VS is installed start it and select "Create a new project",


Step 1. Then in the search box type "dll"
Step 2. Select Dynamic-Link Library (DLL). Be careful to select the right one as there a few similar types.
Step 3. Hit "Next"


Next give the Project a name. "SC_ACSIL_Examples". Use the same as me to make it easy to follow the next steps .
And save the project to a folder that makes sense to you. (remember where)
Then hit "Create"


That will create a project with a heap of files and dependencies that you do not need so I delete everything but whats needed. As per the pic below hold down "Ctrl" key and select "framework.h","pch.h","SC_ACSIL_Examples.h","ddlmain.cpp',"pch.cpp","cpp.hint". Making sure NOT to delete the "SC_ACSIL_Examples.cpp" file. Thats the one we program in.


Then go Project>SC_ACSIL_Examples Properties.. then,
Step1. Make sure in the Configurations drop box you have All Configurations selected
Step 2. Put in "C:\SierraChart\Data\" or you corresponding SC Data folder in the output directory
Step 3. Make sure Configuration Type is Dynamic Library (.dll)
click apply


Then Go to
Step 1. C/C++ > General
Step 2. Under "Additional Include Directories"
Step 3 Add "C:\SierraChart\ACS_Source"


Finally go to C/C++ >"Precompiled Headers"
And select "Not Using Precompiled Headers"


Hit Apply and then OK And thats now setup to start programming.

Follow me on Twitter Started this thread Reply With Quote
The following 8 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #3 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


Open the "SC_ACSIL_Examples.cpp" file in in the main window of MSVS. If you are lost go,
View>Solution Explorer>SC_ACSIL_Examples>Source Files> double click on "SC_ACSIL_Examples.cpp"

Make sure you have Release and x64 selected as per the pic. This is very important. This will make a 64 bit dll. If you make a 32 bit dll SC will not reckonise it (as SC is now 64 bit only).


Select all the text in the main window and delete it and past the template code from SC.
https://www.sierrachart.com/index.php?page=doc/HowToBuildAnAdvancedCustomStudyFromSourceCode.html

or use this,
 
Code
//Make sure your custom studies source code file has the following two lines at the top of the file and in this order.

// This must be exactly "sierrachart.h" to ensure you are referencing the correct header file.
#include "sierrachart.h"

// Change the text within the quote marks to what you want to name your group of custom studies. 
SCDLLName("Custom Study DLL") 

//This is the basic framework of a study function.
SCSFExport scsf_FunctionName(SCStudyInterfaceRef sc)
{
    if (sc.SetDefaults)
    {
        //Code in this section
        return;
    }
    // Data processing code	
}
Again make sure you have x64 selected as per step 1
Then at
SCDLLName("Custom Study DLL")
change it to
SCDLLName("SC_ACSIL_Examples")
to keep it the same as my for this example. When you start producing your own you can name it whatever makes sense.

Then another important step change,
SCSFExport scsf_FunctionName(SCStudyInterfaceRef sc) to
SCSFExport scsf_SC_ACSIL_ExamplesV1(SCStudyInterfaceRef sc)
Making sure you don't delete or leave off the scsf. That is the function tag that SC searches all .dll in the data folder to see if there are study functions for it to load. Without that leading scsf SC will not load anything from our dll.


Now time to build

Go Build>Build Solution
If you have done all these steps perfectly in the output window you will see it start doing stuff and then finish with
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== and a .dll file will be saved to your C:\SierraChart\Data\ like this,


If you open Sierra Chart and go Chart >Studies>Add Custom Study
You will/should see our SC_ACSIL_Examples study listed. As it stands it's useless at the moment as it does nothing but we have a start!


Follow me on Twitter Started this thread Reply With Quote
The following 6 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #4 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

So if this is as clear as mud or you have some ideas please post to this thread


To keep this one clean with just examples

Follow me on Twitter Started this thread Reply With Quote
The following 4 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #5 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

I'll come back tomorrow and start the actual programming part but as it stands up to this point if you have followed along correctly you will have a .dll in SC Data folder which is the complided study file with a few other files and a project folder that you created at the start somewhere probably in you Docs with the SC_ACSIL_Examples.cpp file and Microsoft Visual Studio project files. SC doesn't use these project or .cpp files only the .dll one you have built the project.

Follow me on Twitter Started this thread Reply With Quote
The following 7 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #6 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Ok so as it stands we have a framework for building any Sierra Chart study in this code we compile in MSVS.
The very first line of code always is
 
Code
#include "sierrachart.h"
This brings into our study all the Sierra Chart structure as well as the Windows C++ Standard Library that we will be programming with. At the moment we don't really need to worry about that and just move on to the basics of ACSIL.

In the standard ACSIL Template Code there are three sections that different things are done in.

1. You declare any sc.Subgraph[] and sc.Input[].
sc.Subgraph[] are the arrays which will hold your study calculation and display them on your chart.
sc.Input[] are Inputs allowing user-specified inputs or parameters to a study function. Think for example a period setting for a moving average, like '20' for a 20 period or a Yes/No for a "Use even session Data" in your study.

2. Is where you set default setting for your studies Subgraph and Inputs.
These are the setting you see in the "Settings and inputs" & "Subgraphs" tabs when you open the "Study Settings" dialog box.
Like does a Subgraph display as a line or bar, what color is it etc.
Also in this section you set important study defaults like how it deals with data (Auto looping or manual), what Chart region is is set to etc.

3. Is where you do the actual programming to make calculations.


Follow me on Twitter Started this thread Reply With Quote
The following 7 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #7 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Ok lets do some basic programming.

To start we will jump straight into accessing and display some data into the log and plotting a basic Subgraph. When writing studies its very helpful to have values you are accessing and calculation being printed to the log for de-bugging purposes.

First step in our ACSIL template is to declare a Subgraph to work with and a sc.Input

Just below the
 
Code
SCSFExport scsf_SC_ACSIL_ExamplesV1(SCStudyInterfaceRef sc)
{
Add,
 
Code
SCSubgraphRef BarRange = sc.Subgraph[0];
SCInputRef BarRangeMultiplier = sc.Input[0];
Its important in C++ that every line of code is ended in a ";". That tells the compiler that its the end of that line of code so don't forget them.

Then on to the Study defaults. There are a few default settings that have to be set in every study.
Firstly you should set a study name and description and set whether or not the study uses Automatic looping or manual.[/URL] link( Don't worry about the details of that yet we'll come back to it) but just know its easier doing Automatic looping.

For now this is all you need to know,
" When your study function uses automatic looping, then it is automaticaly called once for every bar or column in the chart when the study is initially calculated. If there are 100 bars in the chart, then it will be called 100 times when your study is initially calculated. After that, the study function is called as the latest bar is updated and new bars are added. "
https://www.sierrachart.com/index.php?page=doc/ACS_ArraysAndLooping.html

So In the sc.Setdefaults block we add,

 
Code
sc.GraphName = "SC_ACSIL_ExamplesV1";
sc.StudyDescription = "Simple study to show basic concepts";
sc.AutoLoop = 1;
As you can see there is a leading sc. to many lines of code. This is the ACSIL Interface Members Structure which comes from sierrachart.h that you included in the first line of code.
It's located in C:\SierraChart\ACS_Source folder and that why at the very start in the project properties you set that as an "include directory" so the compiler could find all the sc functions.
if you type sc. anywhere in the SCSFExport function block you will get a auto complete box with all the Sierra Chart ACSIL members and functions.


Above we declared a SCSubgraphRef (Which means Sierra Chart Subgraph Reference) "BarRange" and assigned it to sc.Subgraph[0]
Now we will set some display defaults for that,

 
Code
BarRange.Name = "Bar Range";
BarRange.DrawStyle = DRAWSTYLE_BAR;
BarRange.PrimaryColor = RGB(255, 0, 0);
Every Subgraph that you want to plot in your Study must have at a minimum .Name = "Some Name" otherwise it will not show up in Subgraph windows or on the chart.
Again if you type BarRange. an autofil box will popup and show you all the default setting you can set.

Here is the full list,
https://www.sierrachart.com/index.php?page=doc/ACSIL_Members_scSubgraph.html
For now we will set the Drawstyle to DRAWSTYLE_BAR ( See more here) and the color to Blue. See examples here.


Now set the BarRangeMultiplier input defaults,
Again it needs a .Name so we will put

 
Code
BarRangeMultiplier.Name = "Bar Range Multiplier";
and we need to set a type and default value. This requires some forethought to make sure you are setting the right data type ie, int, float, Boolean, Date etc
You can see what you can set it to here, but we will set it to an Integer and give it a default value of 2

Its important that you have that
 
Code
return;
as the last line in the sc.SetDefaults Block or SC will crash when you try to add it to a chart.

So Now your full code should look like this,



And the complete code so far,
 
Code
//Make sure your custom studies source code file has the following two lines at the top of the file and in this order.
// This must be exactly "sierrachart.h" to ensure you are referencing the correct header file.
#include "sierrachart.h"
SCDLLName("SC_ACSIL_Examples")

//       So lets make a very basic study to walk through each of the above points. We'll make study that displays 2 simple moving averages (nothing too exciting to start)

// Firstly we need two supgraphs to hold our Moving averge calculationsand we need two inputs to control what period
SCSFExport scsf_SC_ACSIL_ExamplesV1(SCStudyInterfaceRef sc)
{
    // Declare All study subgraphs  
    SCSubgraphRef BarRange = sc.Subgraph[0];

    // And study inputs 
    SCInputRef BarRangeMultiplier = sc.Input[0];
    
    if (sc.SetDefaults)
    {
        // Set all display and input defaults here
        sc.GraphName = "SC_ACSIL_ExamplesV1";
        sc.StudyDescription = "Simple study to show basic concepts";
        sc.AutoLoop = 1;

        BarRange.Name = "Bar Range";
        BarRange.DrawStyle = DRAWSTYLE_BAR;
        BarRange.PrimaryColor = RGB(0, 0, 255);

        BarRangeMultiplier.Name = "Bar Range Multiplier";
        BarRangeMultiplier.SetInt(2);

        return;
    }



    // Data processing code	
}

To check that so far you are on track. Make sure SC is closed. Go Build>Build Solution and in the output window of MSVS you sould see,
 
Code
1>2 of 15 functions (13.3%) were compiled, the rest were copied from previous compilation.
1>  0 functions were new in current compilation
1>  0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>SC_ACSIL_Examples.vcxproj -> C:\SierraChart\Data\SCACSILEXAMPLES.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
And then open sierra Chart and on a chart go Studies>Add Custom Study and select SC_ACSIL_ExamplesV1 and add to chart ad see if all is well.

Next step the calculations

Follow me on Twitter Started this thread Reply With Quote
The following 10 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #8 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

To understand how to use chart data you have to understand how Bar data corresponds to arrays and indexing.

An array is a container object that holds a fixed number of values of a single type. Each value can be accessed by an index. The main arrays in SC are sc.BaseData[][] arrays contain the data for the main price graph in the chart. The sc.BaseData[][] arrays are used as input data to your study.

For example Close prices of each bar are stored in sc.BaseData[SC_LAST] or sc.Close[] (two names for the same thing). A few others are,
sc.BaseData[SC_OPEN] or sc.Open[]: The array of opening prices for each bar.
sc.BaseData[SC_HIGH] or sc.High[]: The array of high prices for each bar.
sc.BaseData[SC_LOW] or sc.Low[]: The array of low prices for each bar.
sc.BaseData[SC_VOLUME] or sc.Volume[]
Others are are listed here.

There are two other types of arrays in SC. You have already seen sc.Subgraph which you use to hold you study calculations and display data in. The other type of array available is sc.Subgraph[].Arrays[][] which are extra arrays available for extra study calculations and storing non-display data which we won't be using for now.

All these arrays store data as floats.

The only exception to that is sc.BaseDateTimeIn[] and sc.DateTimeOut[]
They are the starting and ending DateTime for each bar and are stored as SCDateTime data type which is a C++ double.

Now after all of that how do you use them? Well to access a value in an array you use the index (think Bar number). The indexes start at 0 for the first bar, the left most bar in the chart, and increment by 1 for each new bar.

So if you have a chart with 20 bars and want the Close price for the last bar, the twentieth, you would use the Close array index 19,

 
Code
LastBarClose = sc.BaseData[SC_LAST][19]
Rembering that the first bar index is 0 the second bar index is 1 and the third bar index is 2 up to the last bar being Index = (Number of bars - 1)
If you wanted the second last bars volume and had 20 bars you would so,
 
Code
SecondLastVolume = sc.BaseData[SC_VOLUME][18]
Now to make things easier Sierra Chart has an inbuilt function that makes it easier to access the Index of the array with Auto looping which we set in the sc.SetDefaults with this line sc.AutoLoop = 1; It enables us to return the last Index of the chart. Its sc.Index

So the above two lines of code become
 
Code
LastBarClose = sc.BaseData[SC_LAST][sc.Index]
SecondLastVolume = sc.BaseData[SC_VOLUME][sc.Index-1]
Easiest way to visualize it is to imagine each array as a column in a spread sheet. As you can see instead of having to calculate how many bars are in the Chart you just use sc.Index as the last bar Index, sc.Index -1 as second last, sc.Index -2 as third last etc

Follow me on Twitter Started this thread Reply With Quote
The following 6 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #9 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Now to put all this in to action.

To populate our Subgraph with our calculation which we want to do as bar range the code would be,

 
Code
BarRange[sc.Index] = sc.High[sc.Index] - sc.Low[sc.Index];
When your study function uses automatic looping, then it is automatically called once for every bar or column in the chart when the study is initially calculated. If there are 100 bars in the chart, then it will be called 100 times when your study is initially calculated. After that, the study function is called as the latest bar is updated and new bars are added.

So for each bar this code takes the High of that bar - the Low of the Bar and populates that into the correspond Index of the our SubGraph. Then resets sc.Index to the Index of the next Bar and so on till its at the last bar. Whenever a new bar is added sc.Index is incremented 1 bar Index.

So add

BarRange[sc.Index] = sc.High[sc.Index] - sc.Low[sc.Index];

just under our

// Data processing code

Line In our Code and Go Build>Build Solution
Re open Sc and load our study and we should have the following,



Follow me on Twitter Started this thread Reply With Quote
The following 9 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #10 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


To finish off this first example we are going to add some data to the log as a way of showing how to track values in your programming and use our as yet unused BarRangeMultiplier input. Which is very helpful when trying to figure out whats happening and what values to use.

To print anything to the message log in SC you use this function,
https://www.sierrachart.com/index.php?page=doc/ACSIL_Members_Functions.html

 
Code
AddMessageToLog( SCString& Message, int Showlog);
From the link above you can see the that this is a sc. function and it takes the parameters of an SCString as the message you want printed and an int of either 0 or 1 to control how the log will activate.

So whats a SCString? Well back to the SC Documents,
https://www.sierrachart.com/index.php?page=doc/ACSILProgrammingConcepts.html

Quoting 
Some members of the Advanced Custom Study Interface (sc structure passed to your study function) use strings (a series of text characters). In most cases these are implemented as an SCString type.

So we have to declare an empty SCString then use another sc. function to Format that string with what we want to print to the log.

The way we do it is like this,

 
Code
SCString DataString;
DataString.Format("What ever is in these quotes will be appended to or SCString");
Which is fine but useless! We need to add some data from our Study. To do that we use string place holders. Such as %d for an int, %f for a float and %s for another string. In practice if we want to add the Bar index an int, Bar High a float, Bar low a float and Our calculated BarRange a float, it would look like this,

 
Code
DataString.Format("Bar Index: %d, High: %f, Low: %f BarRange: %f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], BarRange[sc.Index]);
As you can see we have a line of text in the " " and various % place holders within that test where we want to put our data.
Then after our text we have the variables which we want to place in that text message. They will be placed in the same order as the % place holders. If you try and put a data type that not in the right type of place holder, for example a Float in an Int place holder, you will get weird numbers showing up and it wont make sense so be sure the data type matches the % type.

We haven't used our BarRangeMultiplier Input yet. we have set a valye to it in the defaults sections with the .SetInt() function and to use any Input you use the .GetInt() function. As you can see in the SC Docs here there are a whole lot of differant .Set() and .Get functions depending again on the data type you are using.

So just as a silly example as to how to use sc.Inputs lets just create another variable and add it to our above string that times our BarRange by our BarRangeMultiplier.

To do that we declare a new variable that will be a float, because we are multiply a float and int which will make a float. Then do the calculation.
 
Code
float DoubleBarRange = BarRange[sc.Index] * BarRangeMultiplier.GetInt();
Then to add that into our existing String we use another sc function .AppendFormat() which will add new text to the end of an excising.

 
Code
DataString.AppendFormat(", BarRangeX2: %.2f", DoubleBarRange);
Then fiinaly use that SCString in the sc.AddMessageToLog()
 
Code
sc.AddMessageToLog(DataString, 0);

Follow me on Twitter Started this thread Reply With Quote
The following 6 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #11 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Here is our complete code with some comments in the programming section to explain each line,

 
Code
//Make sure your custom studies source code file has the following two lines at the top of the file and in this order.
// This must be exactly "sierrachart.h" to ensure you are referencing the correct header file.
#include "sierrachart.h"
SCDLLName("SC_ACSIL_Examples")

//       So lets make a very basic study to walk through each of the above points. We'll make study that displays 2 simple moving averages (nothing too exciting to start)

// Firstly we need two supgraphs to hold our Moving averge calculationsand we need two inputs to control what period
SCSFExport scsf_SC_ACSIL_ExamplesV1(SCStudyInterfaceRef sc)
{
    // Declare All study subgraphs  
    SCSubgraphRef BarRange = sc.Subgraph[0];

    // And study inputs 
    SCInputRef BarRangeMultiplier = sc.Input[0];

    if (sc.SetDefaults)
    {
        // Set all display and input defaults here
        sc.GraphName = "SC_ACSIL_ExamplesV1";
        sc.StudyDescription = "Simple study to show basic concepts";
        sc.AutoLoop = 1;

        BarRange.Name = "Bar Range";
        BarRange.DrawStyle = DRAWSTYLE_BAR;
        BarRange.PrimaryColor = RGB(0, 0, 255);

        BarRangeMultiplier.Name = "Bar Range Multiplier";
        BarRangeMultiplier.SetInt(2);

        return;
    }



    // Data processing code	
  
    // This line calculates our main Study SubGraph
    BarRange[sc.Index] = sc.High[sc.Index] - sc.Low[sc.Index];

    // Declare a new SCString
    SCString DataString;
    // Add that text and variables to our new SCString
    DataString.Format("Bar Index: %d, High: %.2f, Low: %.2f BarRange: %.2f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], BarRange[sc.Index] );
    
    // declare a new variable and multibly or main Study SubGraph by our Input value
    float DoubleBarRange = BarRange[sc.Index] * BarRangeMultiplier.GetInt();

    // Append new text and our DoubleBarRange varible to the end of our DataString
    DataString.AppendFormat(", BarRangeX2: %.2f", DoubleBarRange);

    // Finally print our DataString to Sierra Charts Log
    sc.AddMessageToLog(DataString, 0);
   
}
Once you add the Study to a chart your log will print each something like this,

Quoting 
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 191, High: 27491.00, Low: 27000.00 BarRange: 491.00, BarRangeX2: 982.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 192, High: 27352.00, Low: 26774.00 BarRange: 578.00, BarRangeX2: 1156.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 193, High: 26865.00, Low: 24933.00 BarRange: 1932.00, BarRangeX2: 3864.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 194, High: 25816.00, Low: 24934.00 BarRange: 882.00, BarRangeX2: 1764.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 195, High: 25753.00, Low: 24409.00 BarRange: 1344.00, BarRangeX2: 2688.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 196, High: 26658.00, Low: 25660.00 BarRange: 998.00, BarRangeX2: 1996.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 197, High: 26494.00, Low: 25923.00 BarRange: 571.00, BarRangeX2: 1142.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 198, High: 26148.00, Low: 25617.00 BarRange: 531.00, BarRangeX2: 1062.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 199, High: 26320.00, Low: 25509.00 BarRange: 811.00, BarRangeX2: 1622.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 200, High: 25987.00, Low: 25230.00 BarRange: 757.00, BarRangeX2: 1514.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 201, High: 26294.00, Low: 25514.00 BarRange: 780.00, BarRangeX2: 1560.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 202, High: 26134.00, Low: 25159.00 BarRange: 975.00, BarRangeX2: 1950.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 203, High: 25659.00, Low: 25003.00 BarRange: 656.00, BarRangeX2: 1312.00 | 2020-06-27 17:02:55.597
Chart: F.US.YMU20 Daily #1 | Study: SC_ACSIL_ExamplesV1 | Bar Index: 204, High: 25653.00, Low: 24837.00 BarRange: 816.00, BarRangeX2: 1632.00 | 2020-06-27 17:02:55.597

Noting how we added sc.Index as the first variable in our log and on each bar it increments up by one.
As well you can change the BarRangeMultiplier in the Subgraph "Settings and Inputs" section and note how it changes the value printed to log.

Follow me on Twitter Started this thread Reply With Quote
The following 9 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #12 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

All that looks like a lot of work but actually its pretty simple.

Set up a Visual Studio .dll project and set the parameters for SC (Output directory, Include Directory, Set Not using Headers and delete un-needed files)

Paste the SC ACSIL template from here in the .cpp file.

Declare the Subgraphs you want to plot and the Inputs you'll need to control the Study

Set Defaults for you Study, Subgraphs and Inputs in sc.SetDefaults code block

Then program your calculations to produce the Study you wants.

Follow me on Twitter Started this thread Reply With Quote
The following 6 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #13 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

I'll have another example to build on in a few days, I've been busier than I thought this week. Stay tuned......

Follow me on Twitter Started this thread Reply With Quote
The following 7 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #14 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Ok I'm going to do another rather simple example to expand on a few fundamentals then I'll start taking request.

Firstly when making a new Study we can, from here, start it in two ways. We could start a new VS project like in the first post and make a completely new study or we can just add another SCSFExport scsf_FunctionName(SCStudyInterfaceRef sc) function to our existing project. That way we can avoid having to set all the properties etc and we keep all the Examples ACSIL in one file and sub-menu in SC.

So remember the template for all SC ACSIL Studies.

 
Code
#include "sierrachart.h"

SCDLLName("Custom Study DLL") 


SCSFExport scsf_FunctionName(SCStudyInterfaceRef sc)
{
// Declare SubGraphs and inputs here
    if (sc.SetDefaults)
    {
        //Code in this section
        return;
    }
    // Data processing code	
}
When adding another study to an existing project you only need the code for the SCSFExport function code block. As we have already told the project to include "sierrachart.h" header file with all the SierraChart referances in the first line of our .cpp file and The SCDLLName("Custom Study DLL") is the name that SierraChart uses in Chart>Studies>Add Custom Studies list.

So below the very last curly bracket } of our SC_ACSIL_Examples .cpp paste the above bit of code without the first two lines. And change the study name scsf_FunctionName to scsf_SimpleMaExamples

Now this is very important. It MUST have the scsf_ at the start of the study name or SC when loading all the .dlls will skip it.

In the last Study we only had one SubGraph and one Study input. For this we will have multiple of each. So we need to declare each and give them a name.

Below the first { paste this code,

 
Code
    SCSFExport scsf_SimpleMaExamples(SCStudyInterfaceRef sc)
{
    // Declare All study subgraphs  
    SCSubgraphRef SimpleMA = sc.Subgraph[0];
    SCSubgraphRef SCSimpleMA = sc.Subgraph[1];
    SCSubgraphRef SlowMA = sc.Subgraph[2];

    // And study inputs 
    SCInputRef SimpleMAPeriod = sc.Input[0];
    SCInputRef SCSimpleMAPeriod = sc.Input[1];
    SCInputRef SlowMAPeriod = sc.Input[2];
    SCInputRef Input_MovingAverageType = sc.Input[3];



    // Declare SubGraphs and inputs here
    if (sc.SetDefaults)
    {
        //Code in this section
        return;
    }
    // Data processing code	
}
So we have now initiated and named 3 sc.Subgraph. As you can see that each sc.Subgraph has a differant index starting from 0. This is something to be sure not to get wrong because if you have two sc.Subgraph with the same index they will both hold the same values for the last calculation you do with them even if they have a different name. So always double check that they all have unique indexes. And the same applies to SCInputRef. They also need a unique index. You can have up to 60 Subgraph in one study and 128 SCInputRef.

Follow me on Twitter Started this thread Reply With Quote
The following 7 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #15 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

 
Code
SCSFExport scsf_SimpleMaExamples(SCStudyInterfaceRef sc)
{
    // Declare All study subgraphs  
    SCSubgraphRef SimpleMA = sc.Subgraph[0];
    SCSubgraphRef SCSimpleMA = sc.Subgraph[1];
    SCSubgraphRef SlowMA = sc.Subgraph[2];

    // And study inputs 
    SCInputRef SimpleMAPeriod = sc.Input[0];
    SCInputRef SCSimpleMAPeriod = sc.Input[1];
    SCInputRef SlowMAPeriod = sc.Input[2];
    SCInputRef Input_MovingAverageType = sc.Input[3];



    if (sc.SetDefaults)
    {

        sc.GraphName = "Simple MA Examples";
        sc.AutoLoop = 1;
        sc.GraphRegion = 0;

        SimpleMA.Name = "Simple MA";
        SimpleMA.PrimaryColor = RGB(0, 255, 0);
        SimpleMA.DrawStyle = DRAWSTYLE_DASH;
        SimpleMA.LineWidth = 1;

        SCSimpleMA.Name = "SC Simple MA";
        SCSimpleMA.PrimaryColor = RGB(0, 0, 255);
        SCSimpleMA.DrawStyle = DRAWSTYLE_LINE;
        SCSimpleMA.LineWidth = 1;

        SlowMA.Name = "Slow MA";
        SlowMA.PrimaryColor = RGB(200, 0, 0);
        SlowMA.DrawStyle = DRAWSTYLE_LINE;
        SlowMA.LineWidth = 1;


        SimpleMAPeriod.Name = "Simple MA Period";
        SimpleMAPeriod.SetInt(5);

        SCSimpleMAPeriod.Name = "SC Simple MA Period";
        SCSimpleMAPeriod.SetInt(5);

        SlowMAPeriod.Name = "Slow MA Period";
        SlowMAPeriod.SetInt(20);

        Input_MovingAverageType.Name = "Moving Average Type";
        Input_MovingAverageType.SetMovAvgType(MOVAVGTYPE_SIMPLE);

        return;
    }


    // Data processing code	
}
Ok we have declared our required Subgraphs and Inputs now we have to set the Defaults for the Study and for each of our above Subgraphs and Inputs.

The first three lines of the if (sc.SetDefaults) code block deal with the general Study settings. sc.GraphName is self explanatory. sc.AutoLoop = 1; is the important one as it tells SC that the study uses auto looping. Generally for simple Studies you use Auto looping. as your studies become more complex or require extra control you would look to use manual looping but for now you should use stick with the easier to program auto looping and get a handle on the other parts of ACSIL. Yhen sc.GraphRegion = 0; sets the study default to display on the main chart region.

Now we move on to the individual Subgraphs. For each Subgraph at a minimum in the defaults you have to set a name, sc.Subgraph[0].Name If you don't set a individual name it will not be graphed in your study. You can still use it in the study to hold values and reference in calculations but it will effectively be hidden from the chart display. The other thing to be careful of is that you don't repeat names. As like the Subgraph indexes if they are not unique they will both hold the same values for the last calculation. In the code Docs you will also notice that they use the Subgraph index instead of the declared name value we set when declaring the Subgraphs. I think its much easier to read and follow using the names but just be aware that this,

 
Code
SimpleMA.Name     = "Simple MA";
SCSimpleMA.Name     = "SC Simple MA";
SlowMA.Name        = "Slow MA";
is the same as this,
 
Code
sc.Subgraph[0].Name = "Simple MA";
sc.Subgraph[1].Name = "SC Simple MA";
sc.Subgraph[2].Name = "Slow MA";


After we set each sc.Subgraph[0].Name we have to set the default Color, DRAWSTYLE and line width. There are as always with SC a heap of setting you can control, have a look here.

Then again you have to set a sc.Input[].Name for each Input value and its a good idea to set Default values. All the default Input settings you can contraol are here,
https://www.sierrachart.com/index.php?page=doc/ACSIL_Members_scInputs.html

Follow me on Twitter Started this thread Reply With Quote
The following 7 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #16 (permalink)
 jokertrader 
NYC, NY
 
Experience: Intermediate
Platform: Sierra Qtrader TT
Broker: Amp/CQG/TT, Optimus, ADM
Trading: Mainly CL. Spread researcher currently
 
Posts: 637 since May 2013
Thanks: 538 given, 344 received

This is very helpful. How about how to extract depth data from the depth files - would be good to know


Sent using the futures.io mobile app

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #17 (permalink)
 brach 
Austin
 
Experience: Intermediate
Platform: NT, SC, MT
Trading: NQ, ES, Micros
 
brach's Avatar
 
Posts: 76 since May 2018
Thanks: 148 given, 191 received

Thanks for this thread. I noticed that SC stopped maintaining VS solution and project templates so I was going to have to set that up myself for VS 2019.

Reply With Quote
 
(login for full post details)
  #18 (permalink)
 brach 
Austin
 
Experience: Intermediate
Platform: NT, SC, MT
Trading: NQ, ES, Micros
 
brach's Avatar
 
Posts: 76 since May 2018
Thanks: 148 given, 191 received

I added calls to sc.MovingAverage to populate the subgraphs for the scsf_SimpleMaExamples study.

I also changed that study's SimpleMA subgraph to use DrawStyle of line and LineStyle of dash to get a dashed-line effect.

Thanks again to @Trembling Hand for this tutorial.

 
Code
//Make sure your custom studies source code file has the following two lines at the top of the file and in this order.

// This must be exactly "sierrachart.h" to ensure you are referencing the correct header file.
#include "sierrachart.h"

// Change the text within the quote marks to what you want to name your group of custom studies. 
SCDLLName("SC_ACSIL_Examples")

//This is the basic framework of a study function.
SCSFExport scsf_SC_ACSIL_ExamplesV1(SCStudyInterfaceRef sc)
{
    // declare all study subgraphs and study inputs here

    SCSubgraphRef BarRange = sc.Subgraph[0];
    SCInputRef BarRangeMultiplier = sc.Input[0];

    if (sc.SetDefaults)
    {
        // set all display and input defaults here
        sc.GraphName = "SC_ACSIL_ExamplesV1";
        sc.StudyDescription = "Simple study to show basic concepts";
        sc.AutoLoop = 1;

        BarRange.Name = "Bar Range";
        BarRange.DrawStyle = DRAWSTYLE_BAR;
        BarRange.PrimaryColor = RGB(255, 0, 0);

        BarRangeMultiplier.Name = "Bar Range Multiplier";
        BarRangeMultiplier.SetInt(2);
        
        return;
    }
    // Data processing code	
    BarRange[sc.Index] = sc.High[sc.Index] - sc.Low[sc.Index];

    SCString DataString;
    DataString.Format("Bar Index: %d, High: %f, Low: %f BarRange: %f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], BarRange[sc.Index]);
    
    float DoubleBarRange = BarRange[sc.Index] * BarRangeMultiplier.GetInt();
    DataString.AppendFormat(", BarRangeX2: %.2f", DoubleBarRange);

    sc.AddMessageToLog(DataString, 0);
}

SCSFExport scsf_SimpleMaExamples(SCStudyInterfaceRef sc)
{
    // Declare All study subgraphs  
    SCSubgraphRef SimpleMA = sc.Subgraph[0];
    SCSubgraphRef SCSimpleMA = sc.Subgraph[1];
    SCSubgraphRef SlowMA = sc.Subgraph[2];

    // And study inputs 
    SCInputRef SimpleMAPeriod = sc.Input[0];
    SCInputRef SCSimpleMAPeriod = sc.Input[1];
    SCInputRef SlowMAPeriod = sc.Input[2];
    SCInputRef Input_MovingAverageType = sc.Input[3];

    if (sc.SetDefaults)
    {

        sc.GraphName = "Simple MA Examples";
        sc.AutoLoop = 1;
        sc.GraphRegion = 0;

        SimpleMA.Name = "Simple MA";
        SimpleMA.PrimaryColor = RGB(0, 255, 0);
        SimpleMA.DrawStyle = DRAWSTYLE_LINE;
        SimpleMA.LineStyle = LINESTYLE_DASH;
        SimpleMA.LineWidth = 1;

        SCSimpleMA.Name = "SC Simple MA";
        SCSimpleMA.PrimaryColor = RGB(0, 0, 255);
        SCSimpleMA.DrawStyle = DRAWSTYLE_LINE;
        SCSimpleMA.LineWidth = 1;

        SlowMA.Name = "Slow MA";
        SlowMA.PrimaryColor = RGB(200, 0, 0);
        SlowMA.DrawStyle = DRAWSTYLE_LINE;
        SlowMA.LineWidth = 1;


        SimpleMAPeriod.Name = "Simple MA Period";
        SimpleMAPeriod.SetInt(5);

        SCSimpleMAPeriod.Name = "SC Simple MA Period";
        SCSimpleMAPeriod.SetInt(10);

        SlowMAPeriod.Name = "Slow MA Period";
        SlowMAPeriod.SetInt(20);

        Input_MovingAverageType.Name = "Moving Average Type";
        Input_MovingAverageType.SetMovAvgType(MOVAVGTYPE_SIMPLE);

        return;
    }

    // Data processing code	

    sc.MovingAverage(
        sc.BaseDataIn[SC_LAST],
        SimpleMA,
        Input_MovingAverageType.GetMovAvgType(),
        SimpleMAPeriod.GetInt());

    sc.MovingAverage(
        sc.BaseDataIn[SC_LAST],
        SCSimpleMA,
        Input_MovingAverageType.GetMovAvgType(),
        SCSimpleMAPeriod.GetInt());

    sc.MovingAverage(
        sc.BaseDataIn[SC_LAST],
        SlowMA,
        Input_MovingAverageType.GetMovAvgType(),
        SlowMAPeriod.GetInt());
}

Reply With Quote
The following 2 users say Thank You to brach for this post:
 
(login for full post details)
  #19 (permalink)
Kuuluud
Revali, EE
 
 
Posts: 43 since Aug 2015
Thanks: 1 given, 65 received


jokertrader View Post
This is very helpful. How about how to extract depth data from the depth files - would be good to know


Sent using the futures.io mobile app

+1 for that. That would be really helpful to know

Reply With Quote
 
(login for full post details)
  #20 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

Thanks for the valuable thread, and hope it can continue with trading system turorials.
  1. How to import SC studies to be used in a trading system code ?
  2. Should I import the whole code of that study in the new trading system code to use it?
I assume it is part of the SC library and we have the two lines at the front of the code to import it but it seems this is only working for ACSIL interface members that can be called by using sc.membername

Is there any sample code for importing studies?
The only examples in the ACS source is only for using sc.movingavg which is a member function of ACSIL and not a study ..

If I would like to import SCSFExport scsf_HighLowForTimePeriodExtendedLines(SCStudyInterfaceRef sc how to do this ..

I would appreciate anyone refer to me to a code example for trading systems that import other SC studies... I was doing this so easily in the spreadsheets but not sure how to do it in ACSIL ..

Thanks for the examples in advance...

Reply With Quote
 
(login for full post details)
  #21 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Hi guys been busy on a project so had to let this slide for a while.

mosalem2003 View Post
  1. How to import SC studies to be used in a trading system code ?
  2. Should I import the whole code of that study in the new trading system code to use it?
I assume it is part of the SC library and we have the two lines at the front of the code to import it but it seems this is only working for ACSIL interface members that can be called by using sc.membername

Is there any sample code for importing studies?
The only examples in the ACS source is only for using sc.movingavg which is a member function of ACSIL and not a study ..

If I would like to import SCSFExport scsf_HighLowForTimePeriodExtendedLines(SCStudyInterfaceRef sc how to do this.


I'll put up another example later today/tomorrow to show this but if you cannot wait you use one of these ACSIL functions to reference the array/s in a study on the same chart (scGetStudyArray) and/or different chart(scGetStudyArrayFromChart) and place the array/s you want to use in a SCFloatArray or Subgraph in your new Study.

sc.GetStudyArraysFromChart()

sc.GetStudyArraysFromChartUsingID()

EDIT (sorry about the lack of hyperlink this forum is dropping the end tag off the links??!!)

Follow me on Twitter Started this thread Reply With Quote
The following 3 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #22 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

Thanks a lot for your prompt response Trembling Hand... I will stay tuned for your detailed example and thanks a lot for the thread... Kindly keep it alive here as it is my first day to find it and it has a lot of invaluable information...

Reply With Quote
 
(login for full post details)
  #23 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received

Ok here is a quick and dirty example of using the arrays and input settings in a study to use as triggers for events in another study. This could be used for a trading system or another study. Using the requested scsf_HighLowForTimePeriodExtendedLines study it gets the two H/L arrays for the set time period from that study and puts them in local array SCFloatArray and it also gets the end time input for that study to check if that time has passed.

I've just used simple logic to print to the log but it would be the same to trigger for a trade. Basically it checks if the current bar start time is > or = to the ending time set in the HighLowForTimePeriod. Then checks once per bar if the close one bar ago is higher or lower than the H/L in the first study. If so prints out to the log the result.


 
Code
SCSFExport scsf_Study_Reference(SCStudyInterfaceRef sc)
{

    SCInputRef Input_StudySubgraph1 = sc.Input[0];
    SCInputRef Input_StudySubgraph2 = sc.Input[1];


    // Set configuration variables

    if (sc.SetDefaults)
    {
        sc.GraphName = "Study Reference";

        Input_StudySubgraph1.Name = "Input Study 1";
        Input_StudySubgraph1.SetStudySubgraphValues(0, 0);

        Input_StudySubgraph2.Name = "Input Study 2";
        Input_StudySubgraph2.SetStudySubgraphValues(0, 0);


        sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL;

        sc.AutoLoop = 1;

        return;
    }


    // Get the array for the specified Input Data from the specified studies
    SCFloatArray HighforTimePeriodArray;
    sc.GetStudyArrayUsingID(Input_StudySubgraph1.GetStudyID(), Input_StudySubgraph1.GetSubgraphIndex(), HighforTimePeriodArray);

    SCFloatArray LowforTimePeriodArray;
    sc.GetStudyArrayUsingID(Input_StudySubgraph2.GetStudyID(), Input_StudySubgraph2.GetSubgraphIndex(), LowforTimePeriodArray);

    // Get the end Time for H/L study
    int EndTimeInput;
    sc.GetChartStudyInputInt(sc.ChartNumber, Input_StudySubgraph1.GetStudyID(), 1, EndTimeInput);

    // Get the time of the bar at the current index
    int CurrentBarTime = sc.BaseDateTimeIn[sc.Index].GetTimeInSeconds();


    // Process once per bar
    int& LastBarIndexProcessed = sc.GetPersistentInt(11);
    if (sc.Index == 0)
        LastBarIndexProcessed = -1;
    if (sc.Index == LastBarIndexProcessed)
        return;
    LastBarIndexProcessed = sc.Index;

    // Logic for signal

    // Declare a new SCString
    SCString SignalString;

    if (CurrentBarTime >= EndTimeInput) {

        // Long signal logic
        if (sc.Close[sc.Index - 1] > HighforTimePeriodArray[sc.Index - 1])
        {
            SignalString.Format("Long Signal! Close: %.2f > HighforTimePeriod: %.2f ", sc.Close[sc.Index - 1], HighforTimePeriodArray[sc.Index - 1]);
        }
        // short signal logic
        else if (sc.Close[sc.Index - 1] < LowforTimePeriodArray[sc.Index - 1])
        {
            SignalString.Format("Short Signal!  Close: %.2f < LowforTimePeriod: %.2f", sc.Close[sc.Index - 1], LowforTimePeriodArray[sc.Index - 1]);
        }
        // no trigger logic
        else
        {
            SignalString.Format("No Signal", EndTimeInput, CurrentBarTime);
        }
    }
    // before H/L for time period has ended
    else {
        SignalString.Format("CurrentBarTime %d < EndTime %d",  CurrentBarTime , EndTimeInput);
    }

    // Finally print our SignalString to Sierra Charts Log
    sc.AddMessageToLog(SignalString, 0);

}
Things to note.
Of course for this to work you need the scsf_HighLowForTimePeriodExtendedLines study on a chart and reference it as per the screen shot.
When referencing other studies you should set the sc.CalculationPrecedence to LOW_PREC_LEVEL or VERY_LOW_PREC_LEVEL to ensure that the first study has finished doing its calculations before using the values. Also note the logic that makes this study calculate just ONCE per new bar.

Attached Thumbnails
Click image for larger version

Name:	2020-12-10 13_57_50-Window.png
Views:	75
Size:	52.0 KB
ID:	307208  
Follow me on Twitter Started this thread Reply With Quote
The following 4 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #24 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

No rush at all... Just to let you know , I am patiently looking forward for your follow-up examples regarding importing an on chart-studies data to the trading system... Thanks a lot in advance and have a nice day ...

Reply With Quote
 
(login for full post details)
  #25 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


mosalem2003 View Post
No rush at all... Just to let you know , I am patiently looking forward for your follow-up examples regarding importing an on chart-studies data to the trading system... Thanks a lot in advance and have a nice day ...

Hey? Isn't that what the above example is? Its importing data from one study into another and using it.

Follow me on Twitter Started this thread Reply With Quote
 
(login for full post details)
  #26 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

Thanks a lot for the comprehensive example. sorry, I am new to the forum and for some reason I didn't get a notification update by email. I will study the example, and post questions if any... Once again, thanks a lot for your prompt support and efforts. Highly appreciated indeed!

Reply With Quote
 
(login for full post details)
  #27 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

Very few minor questions as I am new to c++ , thanks for your answer in advance ...

 
Code
 int EndTimeInput;
 sc.GetChartStudyInputInt(sc.ChartNumber, Input_StudySubgraph1.GetStudyID(), 1, EndTimeInput);
Should we change the input index to 2 as End time is In:2 for the HighLowforTmePeriod-Extended study ?

/
 
Code
/ Process once per bar
    int& LastBarIndexProcessed = sc.GetPersistentInt(11);

///Q**: Why there is a "&" appended to int ?
 --- why 11 is the index for GetPersistentInt ? 
does this mean this variable will remain 
unchanged for the program all time of execution ?

    if (sc.Index == 0)
        LastBarIndexProcessed = -1;
//Q** Does this mean when we reach the last bar, you set the integer to -1 
    if (sc.Index == LastBarIndexProcessed)

//Q*** then if we reach "after" the last bar the index will be -1 "
--can this happen-- I assumed the index is from 0 to n - index can be negative? "
,  and then we exit the whole chart bars initial calculations
 and we only work again if there is a new bar ?

        return;
    LastBarIndexProcessed = sc.Index;

 
Code
  sc.AutoLoop = 1;
Should we set it =0 when we finish the development
as I noticed if it is 1 the performance is too slow in general ?

Reply With Quote
 
(login for full post details)
  #28 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


mosalem2003 View Post
Should we change the input index to 2 as End time is In:2 for the HighLowforTmePeriod-Extended study ?

No have a look at the docs for that function and familiarise yourself with what zero indexing is.
"InputIndex: The zero-based index of the Input to get the value for. The Input index values + 1 are displayed in the Inputs list on the Study Settings window for the study. Example: (In:1)."


mosalem2003 View Post
 
Code
  sc.AutoLoop = 1;
Should we set it =0 when we finish the development
as I noticed if it is 1 the performance is too slow in general ?

Again No. Have a look at what auto looping does in the docs. I covered it in post #8 of this thread but have a look in the docs. Its very important that you understand this - without auto looping you have to programmatically control the array indexes.

Follow me on Twitter Started this thread Reply With Quote
The following user says Thank You to Trembling Hand for this post:
 
(login for full post details)
  #29 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

 
Code
 int CurrentBarTime = sc.BaseDateTimeIn[sc.Index].GetTimeInSeconds();

 
Code
                  if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar.
		   {
			Subgraph_BuyEntry[sc.Index-1] = sc.Low[sc.Index-1];
		    SignalString.Format("Buy Limit 1: %.2f & Buy Target1: %.2f & CurrentBarTime: %d", NewOrder.Price1, NewOrder.Price1+ NewOrder.Target1Offset, CurrentBarTime);
			sc.AddMessageToLog(SignalString, 0);
			
		   }
This is a sample of what is printed in the message log:

<< Sell Limit 3 : 3611.00 & Sell Target3: 3606.00 & CurrentBarTime: 50640 | 2020-12-15 18:38:25.489>>

How to print the CurrentBarTime to the Message log in <<Date, HH, MM, SS>> format -- I have coded it as above and it prints the time of the bar in numerical value of seconds which is not readable ?

Reply With Quote
 
(login for full post details)
  #30 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


mosalem2003 View Post
This is a sample of what is printed in the message log:

<< Sell Limit 3 : 3611.00 & Sell Target3: 3606.00 & CurrentBarTime: 50640 | 2020-12-15 18:38:25.489>>

How to print the CurrentBarTime to the Message log in <<Date, HH, MM, SS>> format -- I have coded it as above and it prints the time of the bar in numerical value of seconds which is not readable ?

https://www.sierrachart.com/index.php?page=doc/SCDateTime.html

#SCDateTimeMember_GetDateTimeYMDHMS
 
Code
int Year, Month, Day, Hour, Minute, Second;

SCDateTimeVariable.GetDateTimeYMDHMS(Year, Month, Day, Hour, Minute, Second);

Follow me on Twitter Started this thread Reply With Quote
The following user says Thank You to Trembling Hand for this post:
 
(login for full post details)
  #31 (permalink)
mosalem2003
Toronto
 
 
Posts: 75 since Apr 2019
Thanks: 59 given, 17 received

In the Spreadsheet , there is inputs to enable trading within time range, i.e Trading start time , Trading End time. Is there ACSIL members to set these Inputs --
Should we add them to the set defaults code block only or we will need to use operators at the condition of the trade entry ?

Reply With Quote
 
(login for full post details)
  #32 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


mosalem2003 View Post
In the Spreadsheet , there is inputs to enable trading within time range, i.e Trading start time , Trading End time. Is there ACSIL members to set these Inputs --
Should we add them to the set defaults code block only or we will need to use operators at the condition of the trade entry ?

Please keep this tread for the example I post so the thread remains concise and on topic. If you have an unrelated question to my examples please start another thread or ask in here.


Follow me on Twitter Started this thread Reply With Quote
The following user says Thank You to Trembling Hand for this post:
 
(login for full post details)
  #33 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
 
Posts: 181 since Jun 2011
Thanks: 15 given, 255 received


Trembling Hand View Post
The only exception to that is sc.BaseDateTimeIn[] and sc.DateTimeOut[]
They are the starting and ending DateTime for each bar and are stored as SCDateTime data type which is a C++ double.

Wow! This is an error! I was googling sc.DateTimeOut[] in relation to custom bars and this thread came up at post #8! I was like huh?? That function, sc.DateTimeOut[] , is only for when you are setting the datetime of custom bars so why did I put it in a Beginners thread!!

Its the wrong function.

It should be sc.BaseDataEndDateTime[sc.Index] to access the the ending time of a bar.

See here

Follow me on Twitter Started this thread Reply With Quote
The following 3 users say Thank You to Trembling Hand for this post:
 
(login for full post details)
  #34 (permalink)
 anubis 
Montevideo Uruguay
 
Experience: Beginner
Platform: motivewave
Trading: futures
 
Posts: 27 since Jul 2020
Thanks: 8 given, 16 received

Hey, nice thread!

How far can one go with Sierra customization? Can we do more than indicators? Like a custom DOM panel and stuff like that?

Reply With Quote


futures io Trading Community Platforms and Indicators Sierra Chart > Sierra Chart ACSIL for Beginners.


Last Updated on March 25, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April

Seven Trading Mistakes Solved With Smart Trading Tools w/Brannigan Barrett

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts