"mGRID" + "CloseAlllTradesCurrent"

 

Hello all,

I'm sure some of you will have heard of the mGRID trading system (coded by FOREXFlash): 100% Win Math Grid Ea @ Forex Factory. To those of you that haven't, mGRID is a grid EA that also doubled positions to always ensure profit as long as there is enough equity on the account (martingale).

I believe that this EA can be used to hedge against trending markets when combined with other EAs, but the problem is that it doesn't close all buy/sell orders after reaching TP/SL and therefore it doesn't continue trading. Notice that if you manually close the standing orders, the EA will automatically open new ones and continue trading.

If someone were to combine the two attached EAs, or find another way to solve this problem, I think this trading system can be profitable to all of us.

Thanks,

Axel

 

Noticed this section in the mGRID code that looks like it's written to remove all orders:

bool EndSession()

{

int cpt, total = OrdersTotal();

for(cpt=0;cpt<total;cpt++)

{

OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderType() > 1)

{

OrderDelete(OrderTicket());

}

else if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)

{

OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);

}

else if (OrderSymbol() == Symbol() && OrderType() == OP_SELL)

{

OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);

}}

if (!ContinueTrading)

{

Enter = false;

}

return(true);

}

Anyone see why it might not work? Running it on an ECN broker, if it matters.

Cheers

 
BlackCoq:
Noticed this section in the mGRID code that looks like it's written to remove all orders:

Anyone see why it might not work? Running it on an ECN broker, if it matters.

Cheers

Try replacing that function with this one :

bool EndSession()

{

for(int cpt=OrdersTotal()-1; cpt>=0; cpt--)

{

OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() != Symbol()) continue;

if (OrderType() > 1) { OrderDelete(OrderTicket()); continue; }

if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red); continue; }

if (OrderType() == OP_SELL) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); continue; }

}

if (!ContinueTrading)

{

Enter = false;

}

return(true);

}

The way it is written in the original now it can not delete or close multiple orders (the above function should solve that)

 
mladen:
Try replacing that function with this one :

I've tried it a few times and it still doesn't seem to be removing orders after TP/SL.

Thank you anyway!

 
BlackCoq:
I've tried it a few times and it still doesn't seem to be removing orders after TP/SL. Thank you anyway!

If it is called it will close all orders (unlike the original function in the EA)

I did not check the rest of the EA logic. Check the EA logic since that function WILL close all the orders if it is called

 
mladen:
If it is called it will close all orders (unlike the original function in the EA) I did not check the rest of the EA logic. Check the EA logic since that function WILL close all the orders if it is called

I see. My knowledge of MQ4 is extremely bad (will make an effort at learning it properly this summer after exams). I am well aware that this isn't supposed to be a learning centre, but could you perhaps remove the "ContinueTrading needs to be true" requirement if it is there the problem lies with the logic?

 

As I see. there are some changes compared to the original (even though even in the original that function can not close all the orders). What was exactly changed in the code and why? Almost sure that the error comes from those changes

 

Do you mean changes from mGRID to mGRID 7.0? Only visual changes, as far as I know (shows number of open positions/orders on the left hand side). Should I attempt to add your code to the original one instead?

 
BlackCoq:
Do you mean changes from mGRID to mGRID 7.0? Only visual changes, as far as I know (shows number of open positions/orders on the left hand side). Should I attempt to add your code to the original one instead?

You should replace that code in any case

Here is why :

Imagine that you have 3 orders. The old code starts checking orders from first to last. For the sake of explanation lets say that those are orders 1,2 and 3. At the beginning it checks the first order in the list (order 1) and deletes it and now it has orders 2 and 3 in the remaining list (remember that order 1 is deleted or closed and it is not a part of a list of opened orders any more). And it continues from second order in the list which would be order 3 (not 2) since the order 3 is the second order in the remaining list, And that way the order 2 will remain opened after the whole thing. That is the logical error in that function that will make it omit some orders when it has to close or delete all orders

Replace the code of that function and at least you will not have to think about that part

 
mladen:
You should replace that code in any case

Here is why :

Imagine that you have 3 orders. The old code starts checking orders from first to last. For the sake of explanation lets say that those are orders 1,2 and 3. At the beginning it checks the first order in the list (order 1) and deletes it and now it has orders 2 and 3 in the remaining list (remember that order 1 is deleted or closed and it is not a part of a list of opened orders any more). And it continues from second order in the list which would be order 3 (not 2) since the order 3 is the second order in the remaining list, And that way the order 2 will remain opened after the whole thing. That is the logical error in that function that will make it omit some orders when it has to close or delete all orders

Replace the code of that function and at least you will not have to think about that part

Sorry that I haven't been able to reply for a few days - been travelling. Thanks for the help, I understand what you mean and at least that problem is fixed now. The order never seems to get executed though, probably because of a logic fault in the EA as you said. If you have any time to spare me and my friend would greatly appreciate it if you could take a quick look at the rest of the EA and see if you can find an obvious mistake. Meanwhile I am learning as quickly as possible!

Many thanks.

 
Axel Franzen:

Hello all,

I'm sure some of you will have heard of the mGRID trading system (coded by FOREXFlash): 100% Win Math Grid Ea @ Forex Factory. To those of you that haven't, mGRID is a grid EA that also doubled positions to always ensure profit as long as there is enough equity on the account (martingale).

I believe that this EA can be used to hedge against trending markets when combined with other EAs, but the problem is that it doesn't close all buy/sell orders after reaching TP/SL and therefore it doesn't continue trading. Notice that if you manually close the standing orders, the EA will automatically open new ones and continue trading.

If someone were to combine the two attached EAs, or find another way to solve this problem, I think this trading system can be profitable to all of us.

Thanks,

Axel

what is the minimum equity I should have in my account to run mgrid ea?
Reason: