Looking for crossed signals
Techniques like the one we just employed are quite useful for analyzing and troubleshooting systems, and Mechanica Basic makes it easy to do. For instance, if you want to be alerted to the presence of crossed signals (which would invoke a wrong side condition if an entry was signaled), without having to scroll through a signal chart to find them, you could add these two lines of code to the bottom of the Resources page:
SYSTEM = 1
COL1 = CLOSE
COL2 = SMA[CLOSE,28]
COL3 = MIN[LOW,10,0]
COL4 = MAX[HIGH,10,0]
IF COL3 > COL2 THEN BEEP ; COL5 = 1
IF COL4 < COL2 THEN BEEP ; COL5 = -1
The first of the two statements (above) tells Mechanica:
n IF the long exit signal is above the 28-day SMA
n THEN make my PC beep;
n Every day this condition is true, assign Column 5 a value of +1 (so that it will be easy to spot in the Grid.)
The bottom statement accomplishes the same thing for the short side, but instead places the value of –1 in Column 5, when the condition to the left of the semicolon is true (and the statement subsequently executes).
• | Go ahead and add these two debug statements to the bottom of your Lesson2.sig file, as shown above. |
Run the system, with exits and debug code
1 | Save your work; from the File menu, choose Save, Signal Rules. |
2 | From the Data menu, choose Symbol Manager. |
3 | Make sure that the Pinnacle_Futures Data Page is selected (it should still be tagged from the previous lesson). |
4 | Under the Tag Symbols tab, tag the second British Pound symbol (BP_B_REV), if it is not still tagged. |
5 | Close the Symbol Manager. |
6 | From the Signals menu, choose Run Signal Rules to run the system (or click the Run arrow on the Signal toolbar). |
The signals in our simple system cross frequently, so you should hear a lot of beeping!
We’ll delve into the Signal Results Grid (in the Results Window) in the next section. But for now, feel free to scroll up and down the Grid page in the Signal Results window, looking at the values in Column 5 to see where these two little lines of debug code alert you to the presence of crossed signals—and potential wrong side conditions—in your system.
|
As a prelude to the example below, please note that in Mechanica Basic, “C” is shorthand for CLOSE (closing price), and “O” is short for OPEN (opening price). The same goes for HIGH (“H”) and LOW (“L”).
|
Troubleshooting code for wrong side conditions
Just to clarify, the presence of crossed signals alone is not enough to invoke a wrong side status message; in order for that to occur, an entry must be indicated.
As we noted earlier in this section, Mechanica will issue a formal wrong side status message only when an entry is signaled on a day when (a) the exit for a long trade is above the long entry price, or (b) the exit for a short trade is below the short entry price.
It’s easy to detect wrong side conditions in your systems. With Mechanica Basic, it only takes a couple lines of code. Here’s how you’d do it:
SYSTEM = 1
COL1 = CLOSE
COL2 = SMA[CLOSE,28]
COL3 = MIN[LOW,10,0]
COL4 = MAX[HIGH,10,0]
IF LONG = 0 AND CLOSE[1] > COL2[1] AND COL3[1] >= OPEN THEN COL5 = 1
IF SHORT = 0 AND CLOSE[1] < COL2[1] AND COL4[1] <= OPEN THEN COL5 = -1
The first of these two statements tell Mechanica:
n | IF the system is not in a long trade (LONG = 0) |
n | AND the entry condition for a long trade (C[1] > COL2[1]) ...was satisfied yesterday, signaling a long entry on today's open (BUYOPEN) |
n | AND the long exit signal (COL3[1]) is greater than today’s open (the designated entry price) |
n | THEN assign Column 5 a value of 1 |
The statement at the bottom of the Resources page accomplishes the same thing for the short side, but instead places the value of –1 in Column 5 when the condition to the left of the semicolon is true (and the statement subsequently executes).
The example above was designed to help familiarize you with the Mechanica Basic and its capabilities. You’ll find that such debug routines are easy to write, and immensely useful when you’re troubleshooting new systems. As we’ve seen, it’s not necessary to scroll through an armful of signal charts looking for crossed signals (for instance), when a few lines of code will do the trick.
Handling wrong side conditions in practice
With regard to the handling of wrong side errors in your systems, Mechanica detects them automatically and disallows entry. When an entry is disallowed because of a wrong side condition, an error message is displayed in the Position Status field in the Results Window:
This is a good point to segue into the next lesson. Now that we’ve reviewed entries and exits in detail, and done some basic troubleshooting with Mechanica Basic, it’s time to look at a new system, and discuss the presentation of data in the Grid.
We’ve done a lot in these first two lessons, and you’ll soon find that developing your own systems is not much more difficult than the material already covered.
|