This tutorial is straightforward and is only useful for those approaching for the first time at Multicharts and Tradestation.

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

## Let’s begin!

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.

Input: MA_length(20);

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)

vars: MA(0);

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.

MA=average(Close,MA_length);

Finally the string of code to draw the average:

Plot1( MA, “MA”);

## Now we can 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:

color(white);

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 ); Here is the complete code:

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 );