NexusFi: Find Your Edge


Home Menu

 





How to code Sierra Chart Study


Discussion in Trading Journals

Updated
      Top Posters
    1. looks_one tulanch with 6 posts (16 thanks)
    2. looks_two Grantx with 5 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 mkata with 1 posts (2 thanks)
    1. trending_up 4,115 views
    2. thumb_up 18 thanks given
    3. group 9 followers
    1. forum 12 posts
    2. attach_file 3 attachments




 
Search this Thread

How to code Sierra Chart Study

  #1 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386

Here are some of my notes on creating a study for Sierra Charts. A study is what Ninja Trader calls an indicator.

Sierra Charts (SC) studies are written in C++. Ninja Trader calls their API "Ninja script" and Sierra Charts calls theirs "Advanced Custom Study Interface " known as ACSI . The programming guide for ACSI is found here https://www.sierrachart.com/index.php?page=doc/ACSILProgrammingConcepts.html

SC documentation is extensive, which at first I found cumbersome and difficult to understand.

Here are some helpful tips to understand to help you get going

1.) Understand where the SC source code is located on your computer so you can access their provided example code

2.) Understand how to compile the study understand remotely

3.) Understand how to access a custom study you create

4.) Understand how to create a basic study and access bar data (the hello world for a Sierra Chart study)

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
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
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386


On my computer the source code provided by Sierra Charts is stored in

C:\SierraChart\ACS_Source


The source code files end in .CPP


The files that start with the word "Studies" are just a few of the examples provided such as Studies.cpp, Studies2.cpp, Studies3.cpp etc...etc...etc...

These example have a number of individual studies within the same file, but you can create a single file with a single study.

These files are sometimes referenced in their documentation

Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386

If your doing simple studies, compiling is very easy. I did install the MSC compiler, but I do not think it's required.

In the main Sierra Charts window, select the "Analysis" menu and then select the "Build Custom Studies DLL"


This action displays the "Build Advanced Customer Studies DLL" dialog with menu options "File" and "Build"


Select the "File" menu and then "Select File"

This lets you pick the file you want to work with

Once you have a selected file, next select the "Build" menu and then select "Remote Build". This action will compile the selected file remotely on the Sierra Charts server and return to you the complied DLL.



NOTE: to see your changes to your re-complied code, select Chart->Studies->Apply

Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386

There are a number of ways to access studies from a chart. The easiest way is to right click on the chart and then select the "Studies" menu item

The displayed dialog shows the studies for your chart. The list displayed are the default studies. Towards the bottom left hand corner you will see the "Add Custom Study" button.

Once you compile a study you will be able to find it listed in this custom study list

Started this thread Reply With Quote
Thanked by:
  #6 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386


Here is how to get the basic template for a new .CPP file

At the top of of the "Study.cpp" file you will see


#include "sierrachart.h"

and

SCDLLName("Sierra Chart Custom Studies and Examples")



At the end of the "Study.cpp" file you will see the code






/*============================================================================
Add function description here.
----------------------------------------------------------------------------*/
SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
// Set the configuration and defaults

sc.GraphName = "New Study";

sc.StudyDescription = "Insert description here.";

sc.AutoLoop = 1;


return;
}


// Do data processing


}








Create a new file and copy this code into the file, for example call it mystudy.cpp






#include "sierrachart.h"
SCDLLName("Sierra Chart Custom Studies and Examples")

// //////////////////////////////////////////
// global persistent variables can go here
// //////////////////////////////////////////

SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "New Study";
sc.StudyDescription = "Insert description here.";
sc.AutoLoop = 1;
return;
}

// Do data processing


}


1.) if sc.SetDefaults is true, it means its the first time study is called and this only occurs one time
2.) change scsf_TemplateFunction to something like scsf_myexample
3.) change sc.GraphName to a name of your choice such as sc.GraphName = "myexample";
4.) change sc.StudyDesciption to a description of your choice such as sc.StudyDescription = "myexample description details";
5.) sc.AutoLoop=1 makes it easy to do a study. Sierra chart will automatically loop for you.






Here is a simple study that puts an X box 1 tick above the high of the bar

#include "sierrachart.h"
SCDLLName("Custom Study DLL")

// global variables
int last_line_number=0;
int txtsize = 10;
int LastBarIndexProcessed;

SCSFExport scsf_tlu_1(SCStudyInterfaceRef sc)
{

// section of study done on study invocation, first time called
if (sc.SetDefaults)
{
sc.GraphName = "TLU 1";
sc.StudyDescription = "Description of TLU study";
sc.AutoLoop = 1;
// During development set this flag to 1, so the DLL can be modified. When development is done, set it to 0 to improve performance.
sc.FreeDLL = 1;

LastBarIndexProcessed = sc.Index;

return;
}


// ////////////////////
// Do data processing
// ////////////////////



// //////////////////////////////////////////////////////////////////
// do nothing if the bar index is the same as the previous bar index
// //////////////////////////////////////////////////////////////////
if(sc.Index == LastBarIndexProcessed)
{
return;
}

// //////////////////////////////
// do this when bar index changes
// //////////////////////////////
else
{

// /////////////////////////
// create a draw tool object
// /////////////////////////
s_UseTool Tool;

Tool.ChartNumber = sc.ChartNumber; // which chart to add draw item too
Tool.DrawingType = DRAWING_TEXT; // create a Text item

Tool.LineNumber = last_line_number; // the unique id for this draw item
++last_line_number; // increment the global id for the tool object

// x location for this bar - note the location is bar based, even if seconds change, always converts to the bar's x location
// can not figure out how to move off x location of bar
Tool.BeginDateTime = sc.BaseDateTimeIn[LastBarIndexProcessed]; //converts to a time, drawing on the last bar

// y location (price)
// look up sc.BaseDataIn array, it's how you access a bar's data such as SC_HIGH, SC_LOW, etc....
Tool.BeginValue = sc.BaseDataIn[SC_HIGH][LastBarIndexProcessed] + sc.TickSize; // sc.TickSize is distance in price between ticks of chart

Tool.Color = RGB(0,0,0); // text color
Tool.FontBackColor = RGB(255, 0,0); // background color red

// the text for the text object
Tool.Text = "X";

// text size
Tool.FontSize = txtsize;

Tool.AddMethod = UTAM_ADD_OR_ADJUST; // how the item is added to the chart, a performance tweek for sierra

// invoke the tool (draw it)
sc.UseTool(Tool);

// open up the message log dialog, use this for debugging
sc.AddMessageToLog("end of study ",0);
}

// keep track of the curent bar index
LastBarIndexProcessed = sc.Index;

} // end of study













NOTE: to see your changes to your re-complied code, select Chart->Studies->Apply

Started this thread Reply With Quote
  #7 (permalink)
 Grantx 
Reading UK
Legendary no drama Llama
 
Experience: None
Posts: 1,787 since Oct 2016
Thanks Given: 2,826
Thanks Received: 5,058

Thank you. This is awesome! Really appreciate you going out of your way to do this.

Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 Grantx 
Reading UK
Legendary no drama Llama
 
Experience: None
Posts: 1,787 since Oct 2016
Thanks Given: 2,826
Thanks Received: 5,058

Can anyone help me out here? I am trying to set the starting point of a line to a specific date and time.
If I set my DateTime object to a date, how do I get Tool.BeginDateTime to accept it as a date?

 
Code
SCDateTime DateTime(2019, 06, 07, 10, 39, 0); //Here I just set it to a random date and time
Tool.DrawingType = DRAWING_LINE;
Tool.BeginDateTime = DateTime.GetDateAsSCDateTime; //This obviosuly doesnt work. How to set this?
Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];
Tool.BeginValue = sc.Low[DrawingIndex-20];
Tool.EndValue = sc.Low[DrawingIndex-20];

Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 386


Grantx View Post
Can anyone help me out here? I am trying to set the starting point of a line to a specific date and time.
If I set my DateTime object to a date, how do I get Tool.BeginDateTime to accept it as a date?

 
Code
SCDateTime DateTime(2019, 06, 07, 10, 39, 0); //Here I just set it to a random date and time
Tool.DrawingType = DRAWING_LINE;
Tool.BeginDateTime = DateTime.GetDateAsSCDateTime; //This obviosuly doesnt work. How to set this?
Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];
Tool.BeginValue = sc.Low[DrawingIndex-20];
Tool.EndValue = sc.Low[DrawingIndex-20];


I found I could only get it to "snap" to a bar date...I could not put it at a specific time/date I logically created. It always used to the bars date/time

Started this thread Reply With Quote
  #10 (permalink)
 Grantx 
Reading UK
Legendary no drama Llama
 
Experience: None
Posts: 1,787 since Oct 2016
Thanks Given: 2,826
Thanks Received: 5,058



tulanch View Post
I found I could only get it to "snap" to a bar date...I could not put it at a specific time/date I logically created. It always used to the bars date/time

Lets say you are on a minute chart, surely you must be able to start a line from 9:46AM that same day?
Or alternatively, do I need to loop through all the bars until a certain DateTime is reached and then work with that bar number? How would you do it?

Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 14, 2019


© 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