In this simple tutorial, we show you how to create an indicator with EasyLanguage for TradeStation and MultiCharts.
Let’s build an indicator in Easylanguage from scratch. As always, the simplest example is a Moving Average, but we will then complicate the code a bit to create something different from the one on the platform.
An indicator can be drawn in the price chart or the window below. There are also other types:
– Paint bar
– Show me
How to Create an Indicator with EasyLanguage
First, we declare the input relative to the speed of the moving average, in this case, we put 20 periods (4 weeks), to declare an input, the reserved word Input is used.
In this case, the input is a numeric value, but it could also be a True / False or a text string.
Then the variables will be declared using the reserved word Variable (or Var, Vars, Variables)
We pass the average calculation; this is the heart of the program. We will use the average function calculating the average based on the closing price (Close), but it can also be used Open, High or Low.
Finally the string of code to draw the average:
Plot1( MA, “MA”);
How to add colors
This is the moving average already present in each platform, so let’s add some other lines of code to change the color and have some additional information.
Insert the color variable:
At this point I want the moving average to turn red when it is descending and green when it is ascending.
To do this, I’ll have to compare the average of the current candle and the previous two:
If MA>MA and MA>MA then
color = Green;
If MA<MA and MA<MA then
color = Red;
I will also have to modify the code part related to the drawing:
Plot1( MA, “MA”,color,0,3 );
The complete code in EasyLanguage:
Input: MA_length(20); vars: MA(0), color(white); MA = average(Close, MA_length); If MA>MA and MA>MA then color = Green; If MA<MA and MA<MA then color = Red; Plot1( MA, “MA”,color,0,3 );