The Studies window will open. Now click the New... button at the bottom left corner of the window. This will open the space we need to write our program.
The first line is # SMA_X_WMA this is a comment and is not used by the computer it is only there to help the programmer or people trying to understand the code.
The next two lines provide input to the program. This allows the user to make changes to the length of the moving averages. Type:
input SMA_Length = 5;
input WMA_Length = 9;
These two line define variables SMA_Length and WMA_Length and assign a default value for each. Note do not forget the ; at the end and I used the _ since spaces are not allowed in variable names.
Next we Define two more variables avg and wavg Type:
Def avg = Average(Close, SMA_length);
Def wavg = wma(close, WMA_length);
The first line defines the simple moving average of the close for the length provided by the SMA_Length variable. and the second line defines the weighted moving average of the close over the length provided by the WMA_Length variable.
Now we need to plot our arrows on the chart. We do this by Typing:
plot crossing = avg > wavg and avg <= wavg;
This code provides the logic used for our indicator it is saying if the simple moving average crosses above the weighted moving average and that it was previously below then it will draw crossing on the chart. The last bit of code will define what gets plotted on the chart. Type:
Now you can Click the OK button the lower right of the window this takes use back to the Studies window.
now you can select any changes to the parameters that you want to change. Next click Apply and then OK to see your indicator on the chart.