Basic Troubleshooting

Top  Previous  Next

 

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]    'barometer of trend

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

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

 

'detects long exit signal above 28-day SMA

IF COL3 > COL2 THEN BEEP ; COL5 = 1 

'detects short exit signal below 28-day SMA

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

1Save your work; from the File menu, choose Save, Signal Rules.
2From the Data menu, choose Symbol Manager.
3Make sure that the Pinnacle_Futures Data Page is selected (it should still be tagged from the previous lesson).
4Under the Tag Symbols tab, tag the second British Pound symbol (BP_B_REV), if it is not still tagged.
5Close the Symbol Manager.
6From 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!

Well 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 signalsand potential wrong side conditionsin your system.        

ThumbTack white

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.

Its easy to detect wrong side conditions in your systems. With Mechanica Basic, it only takes a couple lines of code. Heres how youd do it:

SYSTEM = 1

COL1 = CLOSE

COL2 = SMA[CLOSE,28]    'barometer of trend

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

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

'detects wrong side condition for long entry

IF LONG = 0 AND CLOSE[1] > COL2[1] AND COL3[1] >= OPEN THEN COL5 = 1

'detects wrong side condition for long entry

IF SHORT = 0 AND CLOSE[1] < COL2[1] AND COL4[1] <= OPEN THEN COL5 = -1

 

The first of these two statements tell Mechanica:

nIF the system is not in a long trade (LONG = 0)
nAND the entry condition for a long trade (C[1] > COL2[1]) ...was satisfied yesterday, signaling a long entry on today's open (BUYOPEN)
nAND the long exit signal (COL3[1]) is greater than todays open (the designated entry price)
nTHEN 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. Youll find that such debug routines are easy to write, and immensely useful when youre troubleshooting new systems. As weve seen, its 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 weve reviewed entries and exits in detail, and done some basic troubleshooting with Mechanica Basic, its time to look at a new system, and discuss the presentation of data in the Grid.

Weve done a lot in these first two lessons, and youll soon find that developing your own systems is not much more difficult than the material already covered.