General Information
· | EFS is an extension of the Javascript 1.5 language. |
· | EFS is an interpreted language. |
· | EFS is a case-sensitive language, so myData and MyData would be treated as two separate variable objects. |
· | EFS scripts can be created with any text editor, although it is recommended that you use the built-in eSignal Formula Editor for your programming work. |
· | EFS scripts are contained in one file (although with the advent of EFS2 it is now possible to call functions stored in an external Function Library). |
· | EFS scripts are intended to be loaded into eSignal Advanced Charts and, as such, they must exist in a subdirectory of the eSignal Formula Directory, which is generally c:\Program Files\eSignal\Formulas |
· | EFS can be used to create indicators that run in the Price Pane or in a separate indicator pane. It can also be used to create function libraries that are, in turn, called by other EFS scripts. |
· | EFS scripts can be delivered as plain text files or they can be encrypted to protect intellectual property. Entitlement features are also available that allow developers to restrict script usage and/or set up subscription-based activations. |
Layout of a Basic EFS Script
An EFS script generally consists of the following parts:
External variables
|
variables that are available to all functions within the EFS script. They are essentially global variables (since they are global in scope as far as the script is concerned) however, in EFS the term 'global variable' is reserved for special variables that are used to share information/data between running scripts.
|
Functions
|
these would consist of the required preMain() and main() functions as well as any user-defined functions created as part of the project.
|
Local variables
|
variables that are local in scope to the function in which they are declared.
|
Comments
|
comments and in-line documentation are an important, but often overlooked, programming practice.
|
Indentation
|
proper indentation is yet another very important, but often overlooked, programming practice.
|
preMain()
|
this is the initialization function for any EFS script and is required. The preMain function is generally used to set the script title, define the display properties of any values that will be plotted by the script, define the script parameter menu, check for authorization and entitlement, and set the display characteristics of the script in general. The preMain function is only called once, when the script is first loaded (or refreshed).
|
main()
|
this is the workhorse function in any EFS script and is required. It is called by the EFS engine as frequently as each new tick (or as infrequently as each new bar). This is where the core logic of the script is defined and this function also returns the value (or values) back to the chart to be plotted.
|
Example Script
The following script is an example from the EFS2 folder that you will find in your eSignal Formula Directory. As you can see, it contains all of the pieces/parts described above.
/*********************************************************
Alexis C. Montenegro © January 2005
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
**********************************************************/
var vATR = null;
var fpArray = new Array();
function preMain() {
var x;
setStudyTitle("ATR");
setCursorLabelName("ATR", 0);
setDefaultBarFgColor(Color.blue, 0);
setPlotType(PLOTTYPE_LINE,0);
setDefaultBarThickness(1,0);
x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x]){
setLowerLimit(1);
setDefault(14);
}
x++;
fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.NUMBER);
with(fpArray[x]){
setDefault("");
}
x++;
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.NUMBER);
with(fpArray[x]){
setDefault("");
}
}
function main(Length,Symbol,Interval) {
if(getBuildNumber()<689)
return;
if(Symbol==null) Symbol=getSymbol();
if(Interval==null) Interval=getInterval();
vSymbol=Symbol+","+Interval;
if (vATR == null) vATR = atr(Length,sym(vSymbol));
/********************************************
Insert your code following this text block
Use vATR.getValue(0) for your code
*********************************************/
return vATR.getValue(0);
}
|