25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tips and Tricks<br />

We set the value of ConsecutiveCount to either WinCount or LossCount, depending on the<br />

MartingaleType setting. We'll compare that to our MaxMartingale setting. If our consecutive order<br />

count is greater than MaxMartingale, we will resize it to be equal to MaxMartingale. (You could<br />

also resize it to the default lot size if you prefer.) The lot size will remain at this size until a win or loss<br />

breaks our consecutive order streak.<br />

The lot size is determined <strong>by</strong> multiplying our BaseLotSize <strong>by</strong> the LotMultiplier, which is<br />

exponentially increased <strong>by</strong> ConsecutiveCount. The MathPow() function raises a number to the<br />

specified power. The first argument is the base, and the second argument is the exponent. For<br />

example, if our starting lot size is 0.1, the lot multiplier is 2, and we have four consecutive orders, the<br />

equation is 0.1 * 2 4 = 1.6.<br />

By adjusting the LotMultiplier and using both Martingale and anti-Martingale strategies, this will<br />

give you enough options to experiment with using exponential lot sizing. You can easily modify the<br />

code above to use other variations. For example, you could scale lot sizes in reverse, from largest to<br />

smallest. Or you could use an external counter in place of ConsecutiveCount.<br />

Debugging Your <strong>Expert</strong> <strong>Advisor</strong><br />

Unlike most programming IDEs, MetaEditor doesn't support breakpoints or any other kind of modern<br />

debugging techniques. You'll need to use Print() statements and logs to debug your expert<br />

advisors.<br />

You've already been introduced to the Print() function. In summary, any string argument passed to<br />

the function will be printed to the log. By printing the contents of variables and functions to the log,<br />

you can examine the output of your code and fix any errors.<br />

You'll want to use the Strategy Tester to run a trading simulation and examine the log output. The<br />

Strategy Tester log is displayed under the Journal tab in the Strategy Tester window. There is a limit<br />

to the amount of information that is listed in the Journal tab, so you may want to view the actual log.<br />

The Strategy Tester logs are stored in the \tester\logs folder. Right click anywhere in the Journal<br />

window and select Open from the pop-up menu. A Windows Explorer window will open, displaying<br />

the contents of the log folder. The file names are in the format yyyymmdd.log, where yyyy is the<br />

four digit year, mm is the two digit month, and dd is the two digit date. You can view the logs in<br />

Notepad or any text editor.<br />

Let's illustrate an example of how you can use the log to locate a programming problem. The code<br />

below has an error in it, and it is not performing as we expected. To be able to diagnose the problem,<br />

141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!