NexusFi: Find Your Edge


Home Menu

 





Sierra Chart ACSIL for Beginners.


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Trembling Hand with 29 posts (186 thanks)
    2. looks_two mosalem2003 with 7 posts (0 thanks)
    3. looks_3 drunkcolonel with 4 posts (4 thanks)
    4. looks_4 Thegunshow with 2 posts (0 thanks)
    1. trending_up 33,883 views
    2. thumb_up 192 thanks given
    3. group 55 followers
    1. forum 55 posts
    2. attach_file 5 attachments




 
Search this Thread

Sierra Chart ACSIL for Beginners.

  #11 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 358

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

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #12 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 358

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
  #13 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 358


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
  #14 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 358

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
  #15 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 358

 
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
  #16 (permalink)
 jokertrader 
NYC, NY
 
Experience: Intermediate
Platform: Sierra, TT
Broker: N/A
Trading: Spread Researcher and crypto degen
Posts: 654 since May 2013
Thanks Given: 545
Thanks Received: 360

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


Sent using the NexusFi mobile app

Visit my NexusFi Trade Journal Reply With Quote
  #17 (permalink)
 
brach's Avatar
 brach 
Austin, TX
 
Experience: Intermediate
Platform: NT, SC, MT
Trading: NQ, ES, Micros
Posts: 89 since May 2018
Thanks Given: 187
Thanks Received: 269

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
  #18 (permalink)
 
brach's Avatar
 brach 
Austin, TX
 
Experience: Intermediate
Platform: NT, SC, MT
Trading: NQ, ES, Micros
Posts: 89 since May 2018
Thanks Given: 187
Thanks Received: 269

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
Thanked by:
  #19 (permalink)
Kuuluud
Revali, EE
 
Posts: 47 since Aug 2015
Thanks Given: 1
Thanks Received: 84


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 NexusFi mobile app

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

Reply With Quote
  #20 (permalink)
mosalem2003
Toronto
 
Posts: 102 since Apr 2019
Thanks Given: 106
Thanks Received: 23


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




Last Updated on August 8, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts