Troubleshooting

Since a script is a simple text file, you can type anything in it, even complete nonsense. But also scripts that look fine can, and often will, behave differently than the programmer intended. In the simplest case, the compiler shows you an error message. In less trivial cases, the error message happens when the script is running. The worst cases are code that gives no error message, but just does not do what it should, or even crashes or freezes. Any programmer encounters all those issues all the time. Depending on what happens, the problem can be trivial to fix, or hard.

Write good code

The first step to avoid errors and bugs is good programming style - a style that allows easy reading and understanding the code. Fortunately, strategy scripts are normally not very long, use not many variables, and have a linear structure. Some suggestions for avoiding bugs already when writing the script:

Error messages

Error messages when compiling the script indicate simple syntax errors. Something is mistyped, or a bracket or semicolon is missing, or an object got the same name as a pre-defined function or variable (their names can be found in the include\functions.h and include\variables.h files). The script file and line in question is printed in the error message. This makes those errors easy to identify and fix, even for a beginner.

More subtle errors cannot be detected by the compiler, but produce a message at runtime. Under error messages you'll find a list of all such errors and warnings, and their likely reasons. Messages related to opening and closing positions are listed under trading; known issues with brokers are described on the related page (FXCM, IB, Oanda, MT4, etc). The answers to many typical issues of script development can be found in the FAQ list.

If you see a runtime error message (like "Error 123: ....") in the message window, but have no clue at which part of your code the problem happens, the quickest way to find it is placing _POS() statements before suspicious places. The parameter is then displayed at the end of the error mesage. For instance, _POS(10) will add a (10) at the end of all subsequent error messages, and _POS("TEST") will add (TEST). You can remove the statements when the error is fixed.

It gets more difficult when no error messages are displayed, but the script just behaves wrong. Below you can find the usual methods for solving those problems. Beginners to programming are often not able to find the reason of the problem quickly. For getting external help, you have two options. Either subscribe a support ticket on the Download Page and ask us for help. We do not fix your script, but we'll show you the bug and help you to fix it yourself. Alternatively, post a question in the User Forum and ask other users for help. In both cases you'll need to upload your script so that we or they can look into it.

But normally you should learn to find and fix bugs in your code by yourself. Here are the usual steps when you encounter issues with your script:

Bugs

If your script behaves badly - for instance, it trades too often, or not often enough, or at the wrong time - you must debug it. Debugging strategy scripts is a special case of program debugging since you're normally interested in the behaviour of a variable or signal from bar to bar. You have to look into parts of the script that you suspect of wrong behavior. There are several methods to observe the behavior of variables, either from code line to code line, or from bar to bar, or during the whole test run:

Crashes

They look more serious, but are normally easier to fix than bugs that just cause wrong behavior. You can encounter three types of crashes:

Crashes are easy to fix when they happen regularly or always at the same bar or script position. They are only hard to find when they happen irregularly and their reason is not immediately obvious. Zorro has a mechanism for detecting hard-to-find problems - the diagnostics mode. Here's a step by step instruction of how to use it:

If you can't find the crash reason with the help of the diagnostics mode, or if you run into other trouble that you can't solve on your own, please report on the Zorro forum and post the content of the diag.txt file. This will allow other people to help you determining and fixing the problem.

See also:

watch, STEPWISE, error messages
► latest version online,