Things Coders' Guru Never Taught Me - page 3

 

How to Speed up your Metrader Program, Part 2

My EA's have up to six main categories of code:

1. Code that finds the direction to try to trade in. An entry condition might also determine the direction, but if not you need this section. You have to figure out which indicator or condition that you already want to use will give you this information.

This can be tricky because you might have an indicator that runs from 0 to 100, and the rule is above 20 you go Long, and below 80, you go short. Well, ANY value from 20.1 to 79.9 (approximately) can then be taken for Long AND Short, so you have to code more carefully to get just one or the other, or use a different indicator or condition to determine the direction.

2. Entry filters or conditions. You are now looking for Long OR Short signals, per the result of the section above. Not looking at both Long and Short here also speeds up your EA.

3. Exit rules or conditions.

Then each of the above gets split into

A) values that are from previous bars (candles), and

B) values from the current bar.

The categories end up 1A, 1B, 2A, 2B, 3A, 3B. I don't end up with only six sections because a good EA has a lot more going on, but each piece of the working core can be classified per the above.

By only calculating all the 'A' type values when a new bar starts (see posts 3 and 18), on the first tick only, you save a LOT of computer resources, especially CPU work, which greatly speeds up your program. And there are usually a lot more values taken from past bars than the current bar, so it can make a tremendous speed difference.

4. I often modify indicators I want to use that were coded to recalculate much or all of the chart on every tick. The "perfect" re-painters usually do this. That can slow an EA to a crawl, which is obvious in the Strategy Tester.

Big Be

Reason: