Support

        Equilla Quick Start

Equilla Operators

An important part of the scripts is the calculation of values. Often only basic arithmetic is necessary for these calculations, but sometimes the tasks are more complex. Equilla places many operators for calculating and comparing values at your disposal.

Calculations

Basic Arithmetics

For calculating values, the four basic arithmetic operations are available. These are used most often. 

Variables: 
    myFirstVar, mySecondVar, myThirdVar;

//Adding two values 
myFirstVar = mySecondVar + myThirdVar;

//Subtracting two values
myFirstVar = mySecondVar - myThirdVar;

//Multiplying two values
myFirstVar = mySecondVar * myThirdVar;

/* When dividing two values, care has to be taken that no division by zero occurs (which may happen if price series are faulty and include a zero). In this case, Tradesignal instantly reports an error and stops the calculation. After a simple example for a division, two examples are given that are designed to prevent a division by zero. */

//Simple Division
myFirstVar = mySecondVar / myThirdVar;

//Query if Divisor = NULL 
If myThirdVar <> 0 Then
    myFirstVar = mySecondVar / myThirdVar

//If myThirdVar is zero, the result of the 
//preceding trading period is used.
//The alternative block starting with 'Else'
//may be left out
Else
    myFirstVar = myFirstVar [ 1 ];

//The Equilla function ''Divide' is available for this task
//The two operands have to be passed in brackets
myFirstVar = Divide( mySecondVar , myThirdVar );


Mathematical Functions for Complex Calculations

With some effort, every calculation can be performed. However, you can reduce the programming load by using functions already provided for special tasks. You can find a list of all functions by clicking the Function button in the toolbox. To see the code, double-click the function or select Edit from the context menu. 

In the following, excerpts of some important functions and their use are given. 

//No subchart
Meta:
    Subchartfalse );

//Declare period for calculation and variables
Inputs: 
    Period( 10 );

Variables: 
    myFirstVar, mySecondVar, myThirdVar;


/* This way you can find the highest value in a series. Please note: Parameter 1: The used data has to be given as a continuous series, either a price series or a value that is calculated or existent at each bar. Parameter 2: The calculation span gives the number of values from the past that are used in the calculation. In the example, period is set to '10'. */

//Example 1: finding the highest close
myFirstVar = HHVClose, Period );

//Example 2: finding the highest price span
mySecondVar = High - Low;
myFirstVar = HHV( mySecondVar, Period );
/* There is a similar function you can use for finding the lowest price in a series. Besides the different function name, all statements from above apply. */

//Example 1: finding the lowest close price
myFirstVar = LLVClose, Period );

//Example 2: finding the lowest price span
mySecondVar = High - Low;
myFirstVar = LLV( mySecondVar, Period );
/* When working with data, you often do not know during the programming which values are less or greater than others. However, it is often important to pursue calculations with the greater or lesser of two values. For this task, the two functions MaxItems and MinItems are available. In both cases, two or more comma-separated values have to be passed in brackets. The functions then give the greatest or smallest value from a list of values. */

//Calculating the height of a candlestick body 
//without knowing if the close is below or above the open 

myFirstVar = MaxItemsOpen, Close ) - MinItemsOpen, Close );

//Extracting the decimal places of a value 
If isLastBar Then
    Begin
        myFirstVar = Frac5.5 );
        Print( myFirstVar ); //0,5 is output 
    End;

//Finding the biggest integer that is smaller than the given value
If isLastBar Then
    Begin
        myFirstVar = Floor5.5 );
        Print( myFirstVar ); //5 is output
    End;

//Finding the smallest integer that is greater than the given value
If isLastBar Then
    Begin
        myFirstVar = Ceiling5.5 );
        Print( myFirstVar ); //6 is output
    End;

//Calculating the cosine of a value
If isLastBar Then
    Begin
        myFirstVar = Cos5.5 );
        Print( myFirstVar ); //0,7086697742913 is output
    End;

 

Comparisons

When calculating an indicator, it is often necessary to compare values and then execute certain functions. For value comparison, several operators are available.

Simple comparisons between two values

//No subchart
Meta:
    Subchartfalse );


//Declare variables
Variables: 
    myFirstVar, mySecondVar, myThirdVar;

//Query if two values are identical
If isLastBar Then
    Begin
        If myFirstVar = mySecondVar Then
            Print"Hello World" ); //Data is output if values are identical
    End;

//Query if two values are unequal
If isLastBar Then
    Begin
        If myFirstVar <> mySecondVar Then
            Print"Hello World" ); // Data is output if values are unequal
    End;

//Query if the first value is greater or equal to the second
If isLastBar Then
    Begin
        If myFirstVar >= mySecondVar Then
            Print"Hello World" ); // Data is output if the value is 
                        // greater or equal to the 
                        // second value
    End;

//Query if the first value is smaller or equal to the second
If isLastBar Then
    Begin
        If myFirstVar <= mySecondVar Then
            Print"Hello World" ); // Data is output if the value is 
                        // smaller or equal to the 
                        // second value
    End;

 

Comparisons between several values through combination

//No subchart
Meta:
    Subchartfalse );

//Declare variables
Variables: 
    myFirstVar, mySecondVar, myThirdVar;

//Combining two comparisons with the AND operator
If isLastBar Then
    Begin
        If ( myFirstVar = mySecondVar ) AND ( myFirstVar = myThirdVar ) Then
            Print"Hello World" ); //Data is output if both comparisons are true
    End;

//Combining two comparisons with the OR operator
If isLastBar Then
    Begin
        If ( myFirstVar = mySecondVar ) OR ( myFirstVar = myThirdVar ) Then
            Print"Hello World" ); //Data is output if one comparison or both 
                        //are true
    End;

//Combining two comparisons with the XOR operator
If isLastBar Then
    Begin
        If ( myFirstVar = mySecondVar ) XOR ( myFirstVar = myThirdVar ) Then
            Print"Hello World" ); //Data is output if one comparison is true 
                        //but not both
    End;



Finding crossing time series

One of the most important problems in indicators and strategies is the search for intersections between prices and averages, indicators and alert lines etc. Tradesignal offers several functions for this task. 

//No subchart
Meta:
    Subchartfalse );

//Set periods for calculation
Inputs: 
    PeriodFast( 10 , 1 ),
    PeriodSlow( 20 , 1 );

//Declare variables
Variables: 
    fastAvg, slowAvg;

//Calculating a short average of close prices
fastAvg = AverageClose, PeriodFast );
//Calculating a longer average of close prices
slowAvg = AverageClose, PeriodSlow );

If isLastbar then
    Begin
        //Query if the faster average crosses over slower
        If fastAvg Crosses Over slowAvg Then
            Alert"Average moves upwards" );
        //Query if the faster average crosses under slower
        If fastAvg Crosses Under slowAvg Then
            Alert"Average moves downwards" );
    End;

 

BACK TO OVERVIEW      Equilla Loops