Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Here is our complete code with some comments in the programming section to explain each line,
Once you add the Study to a chart your log will print each something like this,
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.
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.
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.
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,
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.
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,
is the same as this,
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.
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.
Thanks for the valuable thread, and hope it can continue with trading system turorials.
How to import SC studies to be used in a trading system code ?
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 ..