In this basic tutorial, you’ll learn how to build a TradeStation and MultiCharts indicator with EasyLanguage.
Let’s make our own indicator in Easylanguage from the ground up. The most basic example is a Moving Average, but we’ll add complexity to the code in order to produce something distinct from what’s already available on the platform.
You can place an indicator in the price chart or the window below. There are other types available, including:
– Paint bar
– Show me
How to Create an Indicator with EasyLanguage
In the code, we used a moving average speed of 20 periods (4 weeks). The word Input is used to identify an input.
Then the variables will be defined using the reserved word Variable (or Var, Vars, Variables).
The program passes our average calculation; this is where the program’s engine comes in. We’ll utilize the average function to calculate the average based on the closing price (Close), but it may also be used for Open, High, or Low.
Finally, the string of code to draw the average:
Plot1( MA, “MA”);
How to add colors
The moving average is already there in each platform, so let’s add some extra lines of code to modify the color and provide more data.
Insert the color variable:
The moving average should turn red when the price is declining and green when it is increasing at this point. I’ll have to compare the current candle’s average with the previous two in order to do this:
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 );