EA hedge - open new position for a lot of symbols - multicurrency.

 

Hi, I write hedge EA using multicurrency.

I need to SendOrder new positions in both directions if some position for some currency was closed.

For one currency I used:

int Orders;

if(Orders > OrdersTotal()) {
  SendOrder(pair,OP_BUY,LotSize);
  SendOrder(pair,OP_SELL,LotSize);
}

Orders=OrdersTotal();


For multicurrency I have a lot of orders for different symbols so checking OrderTotal() dosn't work.

In my new EA I have an array of watched symbols and I would like to hedge for this currencies:

bool    onlyWatchedSymbols = true;

int     total_pairs=SymbolsTotal(onlyWatchedSymbols);
string  pairs[];

ArrayResize(pairs,total_pairs);

for(int i = 0; i < total_pairs; i++)
{
        pairs[i]=SymbolName(i, onlyWatchedSymbols);
}

How can I easily check if for some symbol position was closed?

Thanks in advance!

 

I suggest you to use the event handler OnTradeTransaction().

Study the example there carefully!

Documentation on MQL5: Event Handling / OnTradeTransaction
Documentation on MQL5: Event Handling / OnTradeTransaction
  • www.mql5.com
[in] MqlTradeResult type variable containing an execution result of a trade request that led to a transaction. It contains the values for TRADE_TRANSACTION_REQUEST type transaction only. When handling transactions of TRADE_TRANSACTION_REQUEST type, it is necessary to analyze the second and third parameters of the OnTradeTransaction() function –...
 
Carl Schreiber:

I suggest you to use the event handler OnTradeTransaction().

Study the example there carefully!

Thanks for reply.

I think I could use two dimension array:

string pair[][2]

pair[0][0] = "EURUSD"   // for symbols
pair[0][1] = 4          // for amount of positions

 The problem is, that I need to mix string and int in array or put and get values in some way.

Any ideas?

 
Qkey:

Thanks for reply.

I think I could use two dimension array:

 The problem is, that I need to mix string and int in array or put and get values in some way.

Any ideas?

I foud solution. I will use second int array :)
Reason: