Introduction. General Script/Program Structure

The user indicator editor allows you to create your own indicators as well as write and execute a variety of automated trading strategies. Our scripting language is based on PASCAL although there are some structural differences and proprietary functions and procedures. Each user indicator or trading strategy is a script consisting of a number of procedures. Some procedures are required and some are optional . Saved script files have a *.act extension.

The script has following general structure:

 

 

const

 IndicatorName = 'Indicator’s Name’;

 Layout = Separated or Embedded;

{Layout determines indicator placement within the chart. Embedded will be placed in the main chart window, while Separated will be placed in a separate/dedicated section of the chart and will have its own vertical scale}

 {This is also the place where you create Constants that will be used in the script.}

 

var

{Here you declare your variables.}

 

procedure CreateSettings;

begin

 

{This is an optional procedure. It is used to create indicator settings (such as color or time period) that will be available for adjustment in the indicator setup dialog box. You can modify these settings when you are adding your indicator to the chart.

 

end;

--------------------------------------------------

procedure ApplySettings;

begin

 

{This is an optional procedure. As the name implies, it applies the settings that were entered by the user. This procedure also sets values for selected variables.}

 

end;

--------------------------------------------------

procedure Init;

begin

 

 {This is a required procedure. It is executed every time the indicator is added to a chart. This procedure contains important setting (such as chart type and color). }

 

end;

--------------------------------------------------

procedure Add(const Index: Integer);

begin

{ This is a required procedure. It calculates indicator values and draws the indicator in a chart window. }

 

end;

--------------------------------------------------

procedure Recalculate;

begin

 

 { This is a required procedure. It recalculates indicator values every time there is a change in variables/parameters, or when new chart data is received. }

 

end;

--------------------------------------------------

procedure Draw;

begin

 

{This is an optional procedure. It is used to create indicator boundaries (top and bottom), draw additional lines, etc.}

 

end;

 

1.2 Order of procedures

The Indicator script is divided into a number of procedures.  Let’s consider when they are used and their sequential order.

1) The first is an optional procedure called CreateSettings. It creates indicator settings that can be configured during indicator creation in the indicator set-up dialog box.

2) The second procedure is ApplySettings (required if the Create Settings procedure is used). As the name implies, it applies indicator settings that were inputted by user at the time indicator was added to a chart.

3) The Init procedure is used to initialize the indicator, create all objects, and make a dedicated indicator frame (when necessary).

4) Next is the Recalculate procedure. It recalculates the indicator’s values for all candles. As a rule, the value calculation formula for individual candles is contained in the Add procedure.  The Recalculate procedure applies the Add procedure for each candle on the chart. The Recalculate procedure is called when the indicator is initially added to the chart, after indicator settings are changed, or after the chart is refreshed.

5) The Add procedure contains the indicator’s value calculation formula for individual candles. This procedure is called either from the Recalculate procedure or when a new candle is added on the chart.