How to Build an Advanced Custom Study from Source Code


Introduction

The instructions on this page explain how to create the necessary executable file, DLL (dynamic link library) file, from study source code or trading system study source code, so that you are able to use the study in Sierra Chart. Below are various sources for source code that you can compile into a DLL executable file for use in Sierra Chart.

  • You may have been given source code from someone, possibly from a developer who developed a custom study or trading system for you for Sierra Chart.
  • You may want to use the source code for various studies and trading system studies posted on the Sierra Chart Support Board. The source code be could be inside of a CPP source code file, or the source code could be posted outside of a CPP file. Instructions for working with either of these forms of source code is documented here.
  • You may want to create your own customized version of studies from Sierra Chart built-in studies. These are studies found in Analysis >> Studies >> Studies Available. The study functions for the built-in studies can be found in the studies#.CPP files in the /ACS_Source folder in the folder Sierra Chart is installed to on your system.

    There are several of these files. Each one of them contains many of the built-in studies.

    To locate the source code for a particular Sierra Chart built-in study, refer to Searching for Source Code for Sierra Chart Built-In Studies.

Step-By-Step Instructions

  1. Generally a developer of an Advanced Custom Study or studies for Sierra Chart will provide you a file that has a .DLL extension. If you have that file, then you do not need to follow the instructions on this page and instead refer to the How To Use an Advanced Custom Study section. However, if you were provided with the actual source code in a .CPP file or outside of a file, then the instructions on this page explain how to build a Custom Studies DLL file to actually use the study or studies.
  2. If you have a full CPP file that has a #include <Sierrachart.h> and the SCDLLName lines at the top of the file (refer Example Source Code File to see what this looks like), then you will need to save the source code to the proper folder as explained in this step so that it can be compiled. If you have the text of the source code and these two lines are at the top, but it is not contained in a file, then you will need to save the source code to the proper folder as explained in this step so that it can be compiled. In all other cases skip to step 3.

    Save the complete CPP file that you have to the ACS_Source folder which is located in the Sierra Chart program folder on your computer system. If you only have the text of the source code and not the file, then you will first need to save it to a text file that has a CPP extension, using a text editor such as Notepad. In this case, also save it to the /ACS_source folder in the Sierra Chart program folder.

    It is essential that when using the Sierra Chart provided custom study compiler that the very top line of the source code file contains the line #include "sierrachart.h". The text within the quotation marks needs to exactly be "sierrachart.h". Otherwise, you may get compiler errors or be using an incorrect header file.

    At this point skip to the build step.

  3. If you do not see the #include and/or SCDLLName lines at the top of the source code file or source code text, then you have have an independent study function. Or, if you want to modify and use a study function in one of the studies#.CPP files in the /ACS_Source folder in the folder where Sierra Chart is installed to, and build a Custom Studies DLL file from that source code, then you also will be working with an independent study function. Note: The studies#.CPP files contain source code for most of the Sierra Chart studies.
  4. Select Analysis >> New/Open Advanced Custom Study File on the menu.
  5. In the Filename box, enter a name without spaces for the source code file that will contain your study function and press the Open button.
  6. The Notepad++ Editor will open with a new file displayed with your specified name.
  7. The empty skeleton study function that is at the top of this file should be selected and deleted. Paste the source code that you have copied from elsewhere at the end of the file. Select File >> Save on the menu to save the file.
  8. If the source code you have copied has the #include "sierrachart.h" and/or SCDLLName lines at the top (see Example Source Code File below), then you need to overwrite the full contents of the file in the editor instead of pasting to the end of it. However, if the source code you have copied does not have #include "sierrachart.h" and/or SCDLLName at the top, then these lines must not be overwritten in the existing file (see Example Source Code File below).

    Example Source Code File

    //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	
    }
                        
  9. Build Step: Go back to Sierra Chart and select Analysis >> Build Advanced Custom Studies DLL on the Sierra Chart menu.

  10. Press the Select File... button. Select the file that you want to build a Custom Studies DLL file from, and press Open. This will be the file that you saved or created in the steps above.
  11. Press the Build Custom Studies DLL button. The resulting DLL will be generated in your Sierra Chart Data Files Folder. If there are any errors they will be displayed in the Output frame on this window.
  12. If you receive an Access is Denied error (refer to image), then close all Chartbooks and restart Sierra Chart. Do not open any Chartbooks and make certain no Chartbooks are automatically opened. You may need to remove your Chartbooks from the Global Settings >> General Settings >> Files to Open on Startup list. Go back to the Build Step again and try again.

  13. To use the study or studies in the Custom Studies DLL file that you have just built, select Analysis >> Studies >> Add Custom Study from the menu. For complete instructions, refer to the How To Use an Advanced Custom Study section.
  14. If you wish to modify the source code you are building a Custom Studies DLL from, then refer to the Sierra Chart Advanced Custom Study Interface and Language page for the complete reference on this subject.

Obtaining Code From Support Board

On the Sierra Chart Support Board you will be able to find code in 2 forms:

1. The source code is in an attached .CPP file. In this case, follow step number 2 in the Step-By-Step Instructions section.

2. The source code is directly in the post itself. In this case just select the code, right-click over it and select Copy on the displayed menu. Refer to the image below. In this case, follow step number 2 or 3 in the Step-By-Step Instructions section.

Copy Text

Searching for Source Code for Sierra Chart Built-In Studies

Follow these step-by-step instructions below to locate the source code for a particular Sierra Chart built-in study. These are the studies which are found in the Analysis >> Studies >> Studies Available list.

  1. Download and install the jEdit text editor.
  2. Run the jEdit program.
  3. Select Search >> Search in Directory in the jEdit program.
  4. Set the Filter to *.cpp.
  5. The study functions for the built-in studies are located in the studies#.CPP files in the /ACS_Source folder in the folder Sierra Chart is installed to on your system. This is usually C:\SierraChart\ACS_Source.
  6. Set the Directory to C:\SierraChart\ACS_Source or the folder where the source code files are located in on your system.
  7. Enable the Ignore Case option.
  8. Set the Search for text to the name of the study function you want to search for. This is the name as you find it in Analysis >> Studies >> Studies Available.
  9. Press the Find button.
  10. The search results will be displayed in a separate window. Once you go to the actual source code in a file from the search window, you then need to take a copy of the entire source code function which begins with scsf_ that contains the text you searched for.
  11. To modify and compile this code into a custom studies DLL file, refer to Step-By-Step Instructions.
  12. There is also the SCStudyFunctions.CPP file in the /ACS_Source folder in the folder Sierra Chart is installed to on your system. This file contains the source code for most of the intermediate study calculation functions, like sc.SimpleMovAvg(), which are used by the study functions you find in the studies#.CPP files.

    It is not possible to build a custom studies DLL from these intermediate functions completely on their own, but you can take a copy of the source code of these intermediate study calculation functions, put them in your own source code file, make any necessary changes that you require, and call those functions from your primary study function which begins with scsf_*.

*Last modified Thursday, 15th September, 2016.