Editing SIG and SIZ files

Top  Previous  Next


To clear an error message

1Go to the Rules Editor and select the Trade Entry page (press F3, or click on the Trade Entry tab). Make sure the cursor is on the first character of the first line. The status bar at the bottom of the Rules Editor should look like this.

2Press ENTER. The entire line (and all text below it), will move down one row.
3Press UP ARROW, to move the cursor (back up) to the blank line you just created.
4Type: “The 28-day moving average should be a good barometer of the short-term trend.”  <without the quotations>
5Press DOWN ARROW. Mechanica doesn't understand what you've entered, and alerts you by (a) displaying the entire line in red text, and (b) displaying an error message at the bottom right of the editor window:

Tab: 2  Incomplete Statement   Er:97

While the message will automatically clear as you continue to work, if you attempt to run the SIG file (dont do this now), it will generate an error message like the one below:


To enter comments in your program

1Press UP ARROW.
2Type an apostrophe at the beginning of the following sentence: “The 28-day moving average...”, making the apostrophe the first character on the line.

Notice that (a) the error message in the status bar disappears, and (b) the text on this line turns green. Mechanica has now accepted this line of text and identified it as a comment. In programming jargon, this means that the statement has successfully bypassed the syntax check (which is what you want a comment to do).

Now that you understand how to add comments to a program, go ahead and add the comments after lines 2 and 3, shown below:

'The 28-day moving average should be a good barometer...

IF CLOSE[1] > COL2[1] THEN BUYOPEN  'long entry signal

IF CLOSE[1] < COL2[1] THEN SELLOPEN  'short entry signal

ThumbTack white

1.While comments in a program this simple arent really necessary, they add clarity to the tutorial. Adding comments is a good coding practice, and as your programs grow more complex, youll be glad you took the time to do it.
2.Another good use for the apostrophe is to temporarily disable, or “comment out” a line of code that you aren't quite ready to delete. If you need it again, just remove the apostrophe.

To define column values on the Resources Page

In the introduction, we learned that the Resources Page is where you tell Mechanica which data to display in the Grid (discussed in Lesson 3), and which technical indicators and other values your system will use.

1Go to the Resources Page and start a new line, below our previous code.
2Type: COL3 = MIN[LOW,10,0]
3This tells Mechanica to put the 10-day low in column 3.
4Press ENTER to begin the next line of code.
5Type: COL4 = MAX[HIGH,10,0]
6As you can guess, this puts the 10-day high in column 4.
7Press ENTER to make sure that the statement passes syntax check.

With these last two lines, you have just entered the code that Mechanica will reference when checking to see whether or not to exit a trade. The code on your Resources page should look like this:



COL3 = MIN[LOW,10,0]   'long exit price

COL4 = MAX[HIGH,10,0]  'short exit price


Its a good idea to go ahead and enter comments after these two new lines of code (as we did, above). As you can see, its unnecessary to dedicate an entire line to a comment, although you can; Comments can coexist on the same line as Mechanica Basic statements. Just remember to use an apostrophe. Everything to the right of the apostrophe will be interpreted as a comment.

To set exit stops on the Trade in Progress & Exit Page

1As discussed in the intro., the code on this page governs Mechanicas activities while it is in a trade. Besides determining when to exit, it performs such tasks as tracking daily risk calculations.
2Go to the Trade in Progress & Exit page of the Rules Editor. This is where well enter the logic for our exit stops.
3When you type the following line, be sure and use all lower case letters, and omit the spaces between words, exactly as shown:
4Type:   sellstop=col3[1];buystop=col4[1]
5Press ENTER or DOWN ARROW, and watch what happens; As the syntax checker interprets the line you have just typed, it automatically capitalizes and inserts the correct spacing. The line you just typed should now look like this:



You have now entered the logic that tells Mechanica at what prices trades are to be exited.

ThumbTack white

While Mechanica will use these two statements to exit trades, its important to keep in mind that both statements reference the COL3 and COL4 values defined earlier, on the Resources page. (Actually, they reference the previous days value, due to the one day offset, indicated by the “1” in brackets, above.)


To enter multiple commands on a single line

Placing two exit statements on the same line, (as we did with the exit stops above), is not something youre likely to do in practice. It was just a simple example used to introduce the concept.

However, there are times when combining two or more statements on a single line is the best way to get a job done. For instance, you may want to change the value of a memory variable based on the conditional execution of the statement that precedes it. In pseudo-code, you might have a fragment that looks like this:


MEMORY[2] = 0

IF Condition_1 THEN Action ; MEMORY[2] = 1


On the first line in this example, the Memory variable 2 is initialized to zero.
On the second line, Memory variable 2 is assigned a value of one, only when Condition1 is true (and subsequently executes).
More explicitly, if Condition1 is true, then Action is taken (the statement executes). Then and only then is Memory variable 2 set to equal one.
It is important to understand that if Memory variable 2 were placed on its own line following the conditional statement, the outcome would be quite different; In that case, Memory variable 2 would be assigned a value of one every time Mechanica processed the page.

In a moment well omit the semi-colon and place each exit statement on its own line. But for future reference, keep in mind that you can put more than one Mechanica Basic statement on a line; just remember to use a semi-colon between them.


To finish setting exit stops

1If you havent already done so, go ahead and delete the semi-colon that separates the two statements, and place each exit statement on its own line, like this:




2Again, its a good idea to add the appropriate comments, as we did earlier:

SELLSTOP = COL3[1]  ' price at which long trades are exited

BUYSTOP = COL4[1] ' price at which short trades are covered



3From the File menu, choose Save, Signal Rules to save your work, or click the appropriate icon on the Signal toolbar:

We now have a functional system complete with entries, exits, and commented code. But before running it, lets review the Mechanica Basic keywords which do the actual buying and selling, and discuss where and how they are used.

ThumbTack white

By this time you should be fairly comfortable navigating Mechanica and manipulating text in the Rules Editor. So from here on, the instructions will become less explicit, with fewer imbedded graphics for common operations that have already been covered.