Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   Limiting EA to 2 open orders per pair (https://www.forexfactory.com/showthread.php?t=454096)

maybe8 Oct 24, 2013 12:27pm | Post# 1

Limiting EA to 2 open orders per pair
 
Hi there,

The headline describes where I'm looking for: I have an EA running on different currency pairs with individual MagicNumber. For example, I run it on 3 different currencies and have "total" as OrdersTotal defined (e.g. 6).
So, I get max. 6 total open running, "worst case": all 6 are from the same pair.

Current situation:
extern int orders = 6;
int total=OrdersTotal();
if(total<orders)
.... routine starts and works well.

Now I want to adjust to have MaxTrades per currency pair (e.g. 2) limited as well. So, I will have the total (6) and max. per pair (2).
What do I need to add?
(I asked the simillar question in a different thread where I got really since support but it was not solved and I change the requirements here - therefore the new thread - just in case someone would ask).

Thank you in advance.

RaptorUK Oct 24, 2013 6:22pm | Post# 2

Hi there, The headline describes where I'm looking for: I have an EA running on different currency pairs with individual MagicNumber. For example, I run it on 3 different currencies and have \"total\" as OrdersTotal defined (e.g. 6). So, I get max. 6 total open running, \"worst case\": all 6 are from the same pair. Current situation: extern int orders = 6; int total=OrdersTotal(); if(total<orders) .... routine starts and works well. Now I want to adjust to have MaxTrades per currency pair (e.g. 2) limited as well. So, I will have the total (6) and...
Loop through the open orders, count the open orders that match the Symbol() that the EA is running on by checking the OrderSymbol() and the OrderMagicNumber() if you use it . . . then you will know how many are already open for the EA, if it's greater than 1 don't open another Order.

maybe8 Oct 25, 2013 4:32am | Post# 3

Yes, thanks RaptorUK, that's sounds absolute reasonable. When having the number from OrderSymbol() available it will be compared against "MaxTrades" (which is is max. open orders per pair) and against the "total" open orders, right?
I don't use OrderMagicNumber() - I only have an MagicNumber assigned to each pair (does this makes sense?).

Only my codeing is at the first beginners stage and I kindly need to ask someone if /he can write this sub-routine?

RaptorUK Oct 25, 2013 10:47am | Post# 4

Yes, thanks RaptorUK, that's sounds absolute reasonable. When having the number from OrderSymbol() available it will be compared against \"MaxTrades\" (which is is max. open orders per pair) and against the \"total\" open orders, right? I don't use OrderMagicNumber() - I only have an MagicNumber assigned to each pair (does this makes sense?). Only my codeing is at the first beginners stage and I kindly need to ask someone if /he can write this sub-routine?
You will learn by doing . . . but if you want it coded for you go here: MT4 & MT5 coding

Hydralord Oct 12, 2016 10:39am | Post# 5

{quote} Loop through the open orders, count the open orders that match the Symbol() that the EA is running on by checking the OrderSymbol() and the OrderMagicNumber() if you use it . . . then you will know how many are already open for the EA, if it's greater than 1 don't open another Order.
How do i loop through the orders. Would you mind offering an inserted code. Because sincerely speaking i have been trying to work it out to no end

hanzov Oct 14, 2016 9:58am | Post# 6

something like

int opened_orders =0;
String symbol = "......."; // put here tour symbol
for(int i = 0; i<OrdersTotal() ; i++)
{

if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == symbol)
{
opened_orders++;
}
}

if ( opened_orders < MaxTradesPerPair) {
// do case...
}

dimmerpixel Oct 14, 2016 10:31am | Post# 7

you have succeeded by getting RaptorUK out of his nest in MQL coding forum (RaptorUK, i learn alot from your answers there, salute )
but first try google, you will get answers more than what you just asking, because if you doing that, i believe you dont even have to ask that simple question here

sorry for my english


© Forex Factory