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)
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
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
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
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
{
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
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?
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
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?