CHAPTER 1
FundamentalsâWhat Is EasyLanguage?
When you code (slang for writing your ideas into a programming language) an analysis technique, you are directing the computer to follow your instructions to the T. A computer program is nothing but a list of instructions. A computer is obedient and speedy, but it is only as smart as its programmer. In addition, the computer requires that its instructions be in an exact format. A programmer must follow certain syntax rules.
EasyLanguage is the medium used by traders to convert a trading idea into a form that a computer can understand. Fortunately for nonprogrammers, EasyLanguage is a high-level language; it looks like the written English language. It is a compiled language; programs are converted to computer code when the programmer deems it necessary. The compiler then checks for syntactical correctness and translates your source code into a program that the computer can understand. If there is a problem, the compiler alerts the programmer and sometimes offers advice on how to fix it. This is different from a translated language, which evaluates every line as it is typed.
All computer languages, including EasyLanguage, have several things in common. They all have:
- Reserved words. Words that the computer language has set aside for a specific purpose. You can use these words only for their predefined purposes. Using these words for any other purpose may cause severe problems. (See the list of reserved words in Appendix B.)
- Remarks. Words or statements that are completely ignored by the compiler. Remarks are placed in code to help the programmer, or other people who may reuse the code, understand what the program is designed to do. EasyLanguage also utilizes skip words. These words are included in a statement to make the programming easier to read. For example, Buy on next bar at myPrice stop is the same as Buy next bar myPrice stop. The words âonâ and âatâ are completely ignored. (See the list of skip words in Appendix B.)
- Variables. User-defined words or letters that are used to store information.
- Data types. Different types of storage; variables are defined by their data types. EasyLanguage has three basic data types: Numeric, Boolean, and String. A variable that is assigned a numeric value, or stored as a number, would be of the Numeric type. A variable that stores a true or false value would be of the Boolean type. Finally, a variable that stores a list of characters would be of the String type.
VARIABLES AND DATA TYPES
Programmers must understand how to use variables and their associated data types before they can program anything productive. Let's take a look at a snippet of code.
mySum = 4 + 5 + 6;
myAvg = MySum/3;
The variables in this code are mySum and myAvg and they are of the Numeric data type; they are storage places for numbers. EasyLanguage is liberal concerning variable names, but there are a few requirements. A variable name cannot
- Start with a number or a period (.)
- Be a number
- Be more than 20 alphanumeric characters long
- Include punctuation other than the period (.) or underscore (_)
| Correct | Incorrect |
| myAvg | 1MyAvg |
| mySum | .sum |
| sum | val+11 |
| val1 | the//sum |
| the.sum | my?sum |
| my_val | 1234 |
Variable naming is up to the style of the individual programmer. EasyLanguage is not case sensitive (you can use uppercase or lowercase letters in the variable names). (Note: This is our preferenceâit may not be everybody's.) Lowercase letters are preferred for names that contain only one syllable. For variable names that have more than one syllable, we begin the name with a lowercase letter and then capitalize the beginning of each subsequent syllable.
sum, avg, total, totalSum, myAvg, avgValue, totalUpSum, totDnAvg
Still referring to the previous snippet of code, mySum is assigned the value of 15 and myAvg is assigned the value of 15/3, or 5. If a variable name is created, it must be declared ahead of time. The declaration statement defines the initial value and data type of the variable. The compiler needs to know how much space to reserve in memory for all variables. The following code is a complete EasyLanguage program. (Note: Most of the code that you will see in this book will be particular to EasyLanguage and will probably not work in any other language.)
Vars: mySum(0),myAvg(0);
mySum = High + Low + Close;
myAvg = mySum/3;
The Vars: (or Variables:) statement tells the computer what variables are being declared and initialized. We declare the variables by simply listing them in the Vars statement, and we initialize them by placing an initial value in parentheses following the variable name. In this case, mySum and myAvg are to be equal to zero. EasyLanguage is smart enough to realize that these variables should be of the Numeric data type, since we initialized them with numbers. Variable names should be self-descriptive and long enough to be meaningful. Which of the following is more self-explanatory?
mySum = High+Low+Close; or k = High + Low + Close;
myAvg = mySum/3; or j = k/3;
BuyPt = Close + myAvg; or l = Close+j;
Variables of Boolean and String types are declared in a similar fashion.
Vars: myCondition(false),myString("abcdefgh"); The variable myCondition was initialized to false. The word âfalseâ is a reserved word that has the value of zero. This word cannot be used for any other purpose. The variable myString was initialized to âabcdefgh.â Sometimes you will need to use a variable for temporary purposes, and it is difficult to declare and initialize all of your variables ahead of time. In the case of a temporary variable (one that holds a value for a short period of time), EasyLanguage has declared and initialized several variables for your use; value0 through value99 have been predefined and initialized to zero and are ready for usage in your programs. The following is a complete EasyLanguage program:
value1 = High + Low + Close;
value2 =...