About Reserved Words
In EasyLanguage, just like any other language, words have meanings and are combined into statements using some type of grammatical structure. Punctuation marks are used to signify the end of each statement and to separate phrases within each statement. The basic vocabulary of EasyLanguage consists of a set of reserved words, each having a specific purpose, such as to compare and evaluate expressions, to specify display or trading actions, and to reference values.
Price Data
The ability to evaluate price data is one of the most important elements of EasyLanguage. As a result, a number of reserved words exist in EasyLanguage that refer to the price data available from each bar. The words typically match the common trading term for the same value, such as Open, High, Low, Close, or Volume. The following table lists some of the most frequently used price data values:
Data Word |
Abbreviation |
Description |
Open |
O |
First available price for the bar |
High |
H |
Highest price within the bar |
Low |
L |
Lowest price within the bar |
Close |
C |
Last available price for the bar |
Date |
D |
Date of the last trade within a bar |
Time |
T |
Time of the last trade within a bar (in 24 hour format) |
Volume |
V |
Total volume of trades within the bar |
OpenInt |
I |
(Open Interest) Total number of open contracts |
For example, the reserved data word Close refers to the closing price of the bar currently being evaluated by the EasyLanguage procedure. Remember that your EasyLanguage procedure is applied to each bar on the chart, from left to right, and that the ’current bar’ is always the bar on which your procedure is running. If your procedure is running on the 7th bar of the daily chart, the High reserved word contains the high price for the 7th day of trading on the symbol being charted.
Since trading decisions are rarely made on just one bar’s worth of price information, EasyLanguage makes it easy to get price data from any bar older than the current bar by simply adding the phrase ’of N bars ago’ after the appropriate reserved word.
For example, the EasyLanguage expression ’Low of 1 bar ago’ refers to the low price of the previous bar (relative to the bar currently being evaluated by EasyLanguage). In a similar example, if your EasyLanguage procedure is running on the 12th bar of your chart, the expression ’Volume of 3 bars ago’ refers to the charted symbol’s volume from the 9th bar, or 3 bars back from the current bar. The alternate method for referring to data from a previous bar is to use square brackets ’[N]’ after the reserved word – such as, Open[2] to refer to the opening price from 2 bars ago.
In order to remain efficient when analyzing charts containing hundreds or thousands of bars, EasyLanguage contains a special setting called MaxBarsBack that is used to identify how many previous bars of price data an EasyLanguage procedure can reference.
For example, if you write an EasyLanguage procedure that uses a 14-bar moving average, your procedure needs to have at least 14 bars of data to perform its calculations. By setting MaxBarsBack to 14, in this case, your procedure would wait until 14 bars have passed (from left to right) to be sure that enough data is available to calculate the 14-bar moving average for the current bar. EasyLanguage would do the same for each current bar throughout the rest of the chart.
The rule is that MaxBarsBack must be equal to or greater than the largest value needed to perform the analysis. For example, if you are calculating an index based on 60 days of price data, then you’ll require that MaxBarsBack be set to 60 or greater.
To make it easy on both the developer and end-user, most EasyLanguage analysis techniques automatically calculate the MaxBarsBack value. This is done by selecting the Auto-detect option under the heading ’Maximum number of bars study will reference’ on the General tab of the Format [Analysis Technique] dialog box. In the Auto-detect mode, EasyLanguage evaluates all of the data references in your procedure and automatically sets the optimal value for MaxBarsBack. For more information, search the TradeStation Help for the phrase Maximum number of bars.
Statements
Those EasyLanguage reserved words that perform comparisons, carry out associated actions, and control other program operations are called statements.
These include statements such as Plot, If-Then structures, and variable declaration statements. Just like a sentence represents a complete thought in the English language, an EasyLanguage statement represents a complete instruction that results in some program action.
For example, the following statements are used to declare a variable and conditionally execute two additional statements that calculate and plot a 10-bar average of the Close:
Var: MovAvg(0);
if (CurrentBar > 10) then begin
MovAvg = Average(Close,10);
Plot1(MovAvg);
end;
The following is a list of frequently used EasyLanguage statements.
Statement |
Action |
plot1-99 |
Plots a line, marker, or text on a chart or grid |
if-then |
Executes one or more statements when an if condition is true |
else |
Executes one or more statements following else when the preceding condition is not true |
begin |
Specifies the beginning of a block of statements to be conditional executed |
end |
Specifies the end of a block of statements |
for-then |
Executes one or more statements within a loop using a counter variable |
while |
Executes one or more statements within a loop while a condition is true |
variable |
Declares one or more user defined variables to an initial value |
input |
Declares one or more input values of a specified type and with a default value |
array |
Declares one or more array variables to contain a specified number of cells with a default value |
|
Sends output to the print log |
commentary |
Sends output to a commentary window |
breakpoint |
Suspends execution of EasyLanguage and displays the debugger |
Skip words
To make EasyLanguage read more like English, another group of reserved words called skip words are provided. These optional words, such as the, at, on, and from, can be included in a statement or expression.
For example, the following:
if Close > High[1] then Buy next bar at market;
could also be written using skip words to make it appear more readable:
if the Close > the High of 1 bar ago then
Buy on the next bar at the market;
Be aware that, while making your EasyLanguage instructions easy to read, skip words perform no action within the actual program. In other words, they are ignored when the procedure is run. Whether you use skip words at all is a matter of personal preference. The following is a list of skip words:
a |
by |
of |
the |
an |
does |
on |
was |
at |
from |
place |
|
based |
is |
than |
|