In this short tutorial, I will show you how to create a new TradeStation and Multicharts function.
Functions are essential to speed up the coding processes and make the main code much cleaner and easier to modify.
For example, if we want to use a moving average of 200 as a trend filter, we will have to report all these lines in the strategy code every time:
if Close > EMA_TREND then begin
TREND_UP = True;
TREND_DOWN = false;
if Close < EMA_TREND then begin
TREND_UP = false;
TREND_DOWN = true;
All these lines can be replaced with a simple __FSS__TREND_UP (200) function which will look like this in the code:
if __FSS__TREND_UP= true then
so a single line of code, instead of 13 lines, is a nice saving of time when you are experimenting with strategies, and you want to try a filter on the fly.
HOW TO CREATE A NEW FUNCTION
Open the Easylanguage editor, in the File menu choose Function.
Once the name of the function has been chosen, the drop-down menu should be opened to select the type of function.
We generally, use boolean functions because we like to have only true or false output. Frequently when we need more output parameters, we choose double or integer.
Back to the example of the trend function where we set “true” or “false2 on trend_up variable. We suppose that we want to know even when the instrument is flat.
In this case, we will have to use a numeric function that refers to:
1 – when the trend is up
0 – when the market is flat
-1 – when the trend is down
HERE THE CODE IN EASYLANGUAGE:
EMA_TREND = Average(Close,200);
if Close > EMA_TREND then
signal = True;
if Close < EMA_TREND then
signal = false;