Tuesday, June 17, 2014

Make a Simple Buy Arrow Indicator

This is a simple buy arrow indicator program to help teach a few basic concepts on how to make indicators for the ThinkorSwim platform. Our indicator will place an arrow on the chart when the simple moving average crosses above a weighted moving average. We will be able to adjust the length of the moving averages to test different parameters but we will set it up with 5 and 9 as our default values.   Lets get started! The first thing you need to do is start-up your ThinkorSwim platform and open the chart tab. Now click the Edit Studies button at the top of the chart.




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.

At the top is a Studies Name box type in a name for your study I used SMA_X_WMA . There is default code in the window "Plot Data = Close;" you need to delete this code and write our code in its place.
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[1] <= wavg[1];
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:

crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


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.



8 comments:

  1. Thank you for this info! How can I contact you to ask a question?

    ReplyDelete
  2. Hi Filando, can you please email me at danwg78@gmail.com so I can ask you a quick question?

    ReplyDelete
  3. Hey Filando! Do you do any ToS custom indicator programming? I have one that needs to be tweaked. If you are interested please drop me a line at kibicricket@comcast.net

    ReplyDelete
  4. Hi Dnitrij, you do it by defining you sell criteria

    plot crossingDwn = avg < wavg and avg[1] >= wavg[1];

    and defining how to plot it

    crossingDwn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

    ReplyDelete
  5. Thank You, maybe you know how to make sound alert, when I got arrow down or up?

    ReplyDelete
  6. Hello, I am looking for someone to help me program a thinkorswim indicator. It's a compliation of several existing indicators, but I am not good at this type of thing and would appreciate help. Can you please contact me at autismiscuralbe@gmail.com thank you

    ReplyDelete