Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
EXPERT ADVISOR PROGRAMMING<br />
// Place near the end of the start() function<br />
if(Debug == true) Print(StringConcatenate("Bid:",Bid," Ask:",Ask," MA:",MA,<br />
" BuyTicket:",BuyTicket," SellTicket:",SellTicket));<br />
The above code will log price and indicator information, as well as the contents of the BuyTicket and<br />
SellTicket variables. If there are any questions about how a trade was opened, or why a trade was<br />
not opened, the log at that particular moment will show the status of all relevant trade conditions.<br />
You can turn logging on and off with the Debug external variable.<br />
The debug Print() statement should be placed near the end of the start() function, after all<br />
trading functions. If you are using a timer and/or an execute at bar open feature, place the debug<br />
Print() statement inside the timer block so that it will only run when necessary. Otherwise, the<br />
debug line will print to the log on every tick, which can result in a large log file.<br />
Fixing Compilation Errors<br />
When you compile your expert advisor, the compiler will check for correct syntax, and ensure that all<br />
custom functions and variables have been properly declared. If you've left something out, the<br />
compiler will stop, and any compilation errors will appear in the Errors tab in the Toolbox window.<br />
When confronted with a long list of compilation errors, always start with the first one. Double-click<br />
the error in the list, and the editor will jump directly to the line with the error. Correct the error and<br />
recompile. Sometimes a simple syntax error will result in several unrelated errors, although only the<br />
first one was valid.<br />
Here is a list of common compilation errors and their solutions:<br />
• Variable not defined – You forgot to declare a variable with a data type. If it is a global or<br />
external variable, declare it at the top of the file. If it is a local variable, find the first<br />
occurrence and place the data type declaration in front of it. Otherwise, check the spelling or<br />
the case (upper/lower) of the variable name.<br />
• Variable already defined – You declared the same variable twice. Remove the data type<br />
declaration from all duplicate variable declarations.<br />
• Function is not defined – If the function in question is in an include or library file, be sure<br />
that the #include or #import directive is placed at the top of the file and is correct.<br />
Otherwise, check the spelling or the case of the function name, and be sure that it exists<br />
either in the current file or in the relevant include or library files.<br />
144