EA Grinds to a halt :(

 

I wrote an EA that trades on trendlines. It does this by reading price values from actual trendline objects. These objects are drawn to the chart automatically by an indicator I also wrote. The trendline indicator, uses metaquotes' "ZigZag" indicator to identify swing highs/lows and uses those values in its algorithm.

Now stay with me here.. the EA that places the actual trades, which I wrote as well, is what I termed a "Trading Engine" meaning that it is not an 'expert' or 'bot' ..software designed to carry out one set of instructions.. rather its more like an old school video game console which executes instructions given by the cartridges you insert; the 'cartridges' here being entry/exit (and a few other) criteria that define various trading strategies... ideally ANY trading strategy conceivable. Thus, a trader with little programming experience (or a lazy one) needs only to fill in as little as 4 lines of code in a simple template to write a new 'cartridge' for the given strategy they'd like to test or trade and have the 'console', or Trading Engine do all the work. This "Strategy Criteria Template" is written as an indicator.

So here's how it all works: The "Strategy Criteria Template" indicator (which in this case outlines a trendline trading strategy), uses iCustom() to import my trendlines drawing indicator which, in turn, uses iCustom() as part of it's algorithm to read past swing highs/lows given by the ZigZag indicator. Once the Trading Engine EA is directed to use that particular strategy via user input, it first sends user-defined input parameters (which are specific to the particular strategy being implemented) to "Strategy Criteria Template" then uses iCustom() to get a enter/exit response (as well as a few other bits of relevant info).

I know it sounds a bit complex but it works great with all of the strategies I have tried, even the more complex ones like grid trading. However, when try using this trendline strategy, in testing, it seems to be working well at first but then the ticks come slower, and slower, and slower, until it's barely faster then real-time, and when I attach it to a chart, I get a "frowny face". I checked to see if maybe theres a bug that causes a massive amount of objects to be drawn but thats not the case. The journal doesnt show any errors either. I cant imagine that my 2.8GHz Core 2 Duo with 4 Gigs of RAM cant handle a few simple programs interacting as I've outlined above. Any thoughts on why this particular trading strategy seems to cause my system to grind to a halt?

Thanks!

 

did you try right clicking the chart and choose objects list to see how many objects there are ?

 
SDC:

did you try right clicking the chart and choose objects list to see how many objects there are ?


Yes, I have. It's just as it should be.
 

My guess is that, for each tick, your EA is calculating from oldest bar each time - as another bar is added, so it goes back & recalcs everything from the beginning. As more bars are added, so it takes longer to recalc all the bars on each tick, and so everything slows down.

In practice, you should only need recalc the last (most recent) 2 bars.

 
brewmanz:

My guess is that, for each tick, your EA is calculating from oldest bar each time - as another bar is added, so it goes back & recalcs everything from the beginning. As more bars are added, so it takes longer to recalc all the bars on each tick, and so everything slows down.

In practice, you should only need recalc the last (most recent) 2 bars.

Good point. Im going to check for this. Thanks!

Reason: