You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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
I have found that if I can incorporate the core of an indicator into an EA it will run faster then doing an iCustom call.
At least part of the reason for this is within the EA I can limit the indicator to how many bars back it actually needs to look.
Also parts of an indicator's code is dedicated to how it displays on the chart, which doesn't necessarily need to be incorporated into the EA.
There's probably a certain amount of overhead that is avoided by not calling an indicator.
iCustom calls are less work, but speed is important, especially for serious backtesting. And speed in trading -- fractions of a second can count!
I invite comment by knowledgeable programmers.
My last post above relates to my earlier post in which I mentioned wanting to be able to use the current bar before it closes. Why? A big move may be half or more over during the first bar of the move. Waiting for the bar to close can deprive you of many pips. This led to developing the six sections above.