In the previous lesson we used different conditions which consisted of comparing different values such as the close and open prices to each other.
When we’re using conditions like close > open , then this works fine. However, when we start to move into more advanced mathematical formulas, having to type the code for each calculation becomes very time consuming.
Now, this is where functions come in handy.
In short, a function in Easylanguage is a separate calculation that you can call in your strategy, and that returns the value of the formula it contains.
That is, the calculation is coded inside another Easylanguage file, which you can access from your strategy.
This is also how we use trading indicators. We use a function that contains the calculation for the indicator, and the only thing we need to do is to call the function by its name, and insert the parameters we want the indicator to use.
If you remember from the lesson on timeexits, we used barssinceentry, which is a function and reserved word, to know how many bars that had passed since we entered the trade.
In other words, barssinceentry contains a calculation that returns the number of bars from the last entry. And by calling barssinceentry in our strategy, we get back this value.
Some functions will have inputs where you’ll have to insert a number or bar value that they will use for the calculation. This is done inside round brackets, where you just specify the value or values you want the function to use.
For example, here you have the maxlist-function which requires that you insert a series of values, of which it will return the highest.
Maxlist(Open, Close, 50, 20);
Soon, you will be introduced to a couple of useful functions and see how they are used in some code. However, first we’ll take a look at “Maxbarsback”, and when you need to use it!