Download MetaTrader 5

Some extra code needed for a grid EA (which limits its total orders).

To add comments, please log in or register
David Baird
David Baird  

Attached is the .mq4 codefile for a grid system EA.

Under certain market conditions and with certain settings this EA is net profitable... as long as you keep a constant eye on it and limit its total positions to (for example) 30 by turning it off when the sum of its open positions and pending stop orders reaches 30. Then you have to wait until all the TP and SL points are reached at either the top or the bottom of the grid... take the profit/loss... and then turn the EA back on again to start a new "cycle". Using this methodology the EA returns a net profit... incurring very few losses... which are mostly small.

However, this method defeats the object of auto-trading... one has to watch the EA constantly whilst it is in use... and manually perform the task of limiting the orders total... and then reset the EA after each cycle. I'm virtually tied to my desk when the EA is running! Hardly auto-trading is it?

Left to its own devices the EA can (in certain instances) open up so many positions that it creates a margin call... and wipes my equity (or a fair chunk of it) out. Manually limiting the positions/pending orders prevents this... but I want the EA to "self-limit" itself. Just to be clear... this is not an issue regarding lot size against equity... the grid starts with the minimum lot size my broker will allow... 0.01. The issue is that the grid could (given the right market conditions) open literally hundreds of positions before reaching any "conclusion". It's always the total margin which becomes problematic... not the ensuing profit/loss of the total positions.

Can any bright spark out there assist me by adding a little code to the EA which would enable any user to define a limit for the number of pending orders (or open positions) the EA can commit to?

This would enable the EA to run fully automatically without the risk of cleaning me out... and make me a small net profit return.

I'm happy to define the limit variable inside the codefile itself if necessary... and then compile the .ex4 file... but an input parameter in the EA's "control box" would be a real bonus if that's not too much hassle.

I have tried to do this myself... but I keep getting error messages on debug. I've also tried using a script... but even if that worked I'd still have to load it to the chart again and again manually.

I'm just not at a programming level where I can get this limiting issue resolved inside the EA itself. Can anyone out there assist me by appending some code please?

Many thanks in advance if you can.


To add comments, please log in or register