EFS Basics

ICE Data Services -

EFS Basics
Previous  Top  Next

General Information

· EFS is an extension of the Javascript 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 and, as such, they must be located within the "Formulas" folder or any of its sub-folders.  
· 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.
these would consist of the 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 and in-line documentation are an important, but often overlooked, programming practice.
proper indentation is yet another very important, but often overlooked, programming practice.
this is an initialization function. It is not required however it is commonly used to perform the initialization of an EFS script such as - for example - 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). Some EFS functions are only available in preMain().
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.
this is the last executed function in any EFS script and is optional. It is called by the EFS engine once the script instance is deleted, reloaded or the document that is running the script is closed. Usually it is used to free some external resources like DLL or File.

Example Script

The following script is an example that contains all of the pieces/parts described above.

var vATR = null; 
var fpArray = new Array();
function preMain() {
var x;
   fpArray[x] = 
new FunctionParameter("Length", FunctionParameter.NUMBER);
   fpArray[x] = 
new FunctionParameter("Symbol", FunctionParameter.STRING);
   fpArray[x] = 
new FunctionParameter("Interval", FunctionParameter.STRING);
function main(Length,Symbol,Interval) {
if(Symbol=="") Symbol=getSymbol();
if(Interval=="") Interval=getInterval();
if (vATR == null) vATR = atr(Length,sym(vSymbol));
  return vATR.getValue(0);

function postMain() {
  debugPrintln( "This script has finished execution" );