Tuesday, August 7, 2018

How To Create A New Indicator With Tradestation Code


"Though the TradeStation trading package comes with a wide variety of trading indicators known as analysis techniques, many who use TradeStation develop the desire to add or customize their own indicators using TradeStation code. This article will demonstrate how to create a simple indicator that displays the current trading volume and also changes the visual indication of that volume to green when price closes up.

The simplest method to create a new indicator is to find an existing indicator that partially addresses the requirements and then modify it further. For this example, the Volume indicator that comes with TradeStation provides an acceptable foundation.
To begin working with TradeStation code, first open the Volume indicator with the EasyLanguage editor. EasyLanguage is the programming language that TradeStation uses. Begin by right-clicking on any chart, and then select Insert Analysis Technique from the pop-up menu. From the dialog box that appears, select the Indicator tab, and then scroll down to find the Volume indicator in the list. Click once on the Volume indicator row to highlight it, and then click the Edit EasyLanguage button below the list box. The EasyLanguage editor will open with the code for the Volume indicator ready for editing.

EasyLanguage code is divided into three sections. The first block defines the Inputs. These inputs can only be changed by formatting an indicator after it has been added to a TradeStation chart. Following the Inputs are the Variables. These initialize when the indicator first launches during a session, and their values are modified using code. After these two blocks is the actual code that executes. This is what needs modified for our example.
First find the following line of code:
Plot1( VolumeValue, ""Volume"" ) ;
Lines of code that begin with Plot1, Plot2, etc., draw graphic elements such as bars and lines on a chart. In the case of the Volume indicator, this line of code plots the value of the current volume for the bar, VolumeValue. This value is also given the name ""Volume"" which allows a user to identify and change the style of the plot in the Format Analysis Technique dialog box. However, a user can only change the default colors, widths, and styles of the plots. To complete our example, code must be changed.
Place the cursor after the line above and press Enter on the keyboard to create a new line. Now type in the following line of code:
If Close > Open then SetPlotColor(1, Green);
Don't forget to include the semicolon at the end of the line, or the code will not verify.
The line just added is a conditional statement that says, in layman's terms, if the closing price (Close) of the current bar is greater than the opening price (Open) of the current bar then change the plot color (SetPlotColor) of the Plot1 element to Green (1,Green).
Now press the F3 key or click the Verify button to compile the code. Congratulations. The Volume indicator now plots as green when price closes above the open, and you have created your first TradeStation indicator."