Download MetaTrader 5

How can I allow an EA on one currency to communicate with the EA on another?

To add comments, please log in or register
Luciano Ola
1011
Luciano Ola  

I was considering sending out orders across currencies that would act as some sort of message but I also realised that this would not be possible with some brokers.

Is there another way to do this? Would I have to use some sort of dll?

James Hodges
4222
James Hodges  

You are going to have to clarify... do you merely want to make a ea that is on the eurusd place an order on the usdchf? Or are you talking about two ea's running .. one on the eurusd and one on the usdchf? Or even on another broker? In the OrderSend() function you choose which currency pair that you are placing the order in.

OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);

Symbol() just makes it place an order in the currency that the ea is running on.. you could instead say.... "EURUSD" for instance... or "USDCHF" including the quotes because it is a string. If your broker uses a suffix of prefix such as "EURUSDpro" pro "FxEURUSD" you have to make sure and include them in the name...

PipPip...Jimdandy

Luciano Ola
1011
Luciano Ola  
Jimdandy:

You are going to have to clarify... do you merely want to make a ea that is on the eurusd place an order on the usdchf? Or are you talking about two ea's running .. one on the eurusd and one on the usdchf? Or even on another broker? In the OrderSend() function you choose which currency pair that you are placing the order in.

OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);

Symbol() just makes it place an order in the currency that the ea is running on.. you could instead say.... "EURUSD" for instance... or "USDCHF" including the quotes because it is a string. If your broker uses a suffix of prefix such as "EURUSDpro" pro "FxEURUSD" you have to make sure and include them in the name...

PipPip...Jimdandy


I will load the EA on to different currencies and the EAs will communicate with one another (nothing elaborate), I was considering the use of ordersend() but this would not be possible with brokers that do not allow hedging.

I could use order modification instead.

Daniel Petrovai
440
Daniel Petrovai  
MetaNt:

I was considering sending out orders across currencies that would act as some sort of message but I also realised that this would not be possible with some brokers.

Is there another way to do this? Would I have to use some sort of dll?


That is in fact possible with most brokers. If you're looking to hedge on a different currency when another EA has opened a position, all you have to do is this :

Get the second EA to check open orders on the monitored symbol with a for loop - if not sure how to do it, ask.

Once the first EA has placed the order, it will show up in OrdersTotal() function.

Then, the second EA will go trough all open orders - with OrderSelect - and find the one with the correct symbol and magic number.

Once the order is found, it will trigger the second EA to place the order on the second symbol.

Does that make any sense ?

If not sure how to make any of that happen, ask.

As an alternative, you can have the same EA open orders on different symbols but it is a bit more difficult to monitor orders on different symbols with one EA.

A bit more difficult, not impossible.

Hope it helps

Luciano Ola
1011
Luciano Ola  
thrdel:


That is in fact possible with most brokers. If you're looking to hedge on a different currency when another EA has opened a position, all you have to do is this :

Get the second EA to check open orders on the monitored symbol with a for loop - if not sure how to do it, ask.

Once the first EA has placed the order, it will show up in OrdersTotal() function.

Then, the second EA will go trough all open orders - with OrderSelect - and find the one with the correct symbol and magic number.

Once the order is found, it will trigger the second EA to place the order on the second symbol.

Does that make any sense ?

If not sure how to make any of that happen, ask.

As an alternative, you can have the same EA open orders on different symbols but it is a bit more difficult to monitor orders on different symbols with one EA.

A bit more difficult, not impossible.

Hope it helps

Thank you I understand what you have written and would be able to carry this out. The EA is not a hedging EA, there is a hedging version of it however, I made a non hedging version to accommodate US brokers and other brokers which are prohibited from using hedging. In my scenario an event occurs in the EA of one currency and the EAS of the other currencies are meant to know that this event has occurred and thus change their behaviour. I was not sure that I could monitor orders on a symbol other than the symbol the EA is trading on (but I suppose that is why you can choose the symbol for order loops) . What about getting the orderticket ()? I could get the order ticket and then perform some simple math on it the result of which would be some like 1 or 2, then the other symbols could check for this result for every order on the other symbols.
Luciano Ola
1011
Luciano Ola  
MetaNt:
Thank you I understand what you have written and would be able to carry this out. The EA is not a hedging EA, there is a hedging version of it however, I made a non hedging version to accommodate US brokers and other brokers which are prohibited from using hedging. In my scenario an event occurs in the EA of one currency and the EAS of the other currencies are meant to know that this event has occurred and thus change their behaviour. I was not sure that I could monitor orders on a symbol other than the symbol the EA is trading on (but I suppose that is why you can choose the symbol for order loops) .What about getting the orderticket ()? I could get the order ticket and then perform some simple math on it the result of which would be some like 1 or 2, then the other symbols could check for this result for every order on the other symbols.
Actually I may have a simpler solution. I'll code it in.
Daniel Petrovai
440
Daniel Petrovai  
MetaNt:
Thank you I understand what you have written and would be able to carry this out. The EA is not a hedging EA, there is a hedging version of it however, I made a non hedging version to accommodate US brokers and other brokers which are prohibited from using hedging. In my scenario an event occurs in the EA of one currency and the EAS of the other currencies are meant to know that this event has occurred and thus change their behaviour. I was not sure that I could monitor orders on a symbol other than the symbol the EA is trading on (but I suppose that is why you can choose the symbol for order loops) . What about getting the orderticket ()? I could get the order ticket and then perform some simple math on it the result of which would be some like 1 or 2, then the other symbols could check for this result for every order on the other symbols.


Once you select the order with OrderSelect and filter the results with OrderSymbol()= yourSymbol and OrderMagicNumber()= yourMagicNumber, then you can get

int myTicket= OrderTicket(), OrderType(), OrderOpenTime, etc.

Here is a sample, selecting from history, but you can change that to MODE_TRADES and OrdersHistoryTotal to OrdersTotal().

  int i=0,hstTotal=OrdersHistoryTotal();
   recentClosedOrderTime=0;
   recentClosedTicket=-1;
   for(i=0;i<hstTotal;i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) // if order select fails , print to let me know and take it from the top
        {
         Print("Orders select failed in History_Calling with error : "+(string)GetLastError());
         break;
        }
      if(OrderType()==OP_BUY || OrderType()==OP_SELL)
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
           {
            if(OrderCloseTime()>recentClosedOrderTime)
              {
               recentClosedOrderTime=OrderCloseTime();                               //each time it finds a greater closing time 
               recentClosedTicket=OrderTicket();
               recentClosedOrderType=OrderType();                                   //overwrites the counter and the ticket number. 
              }
           }
        }
      else continue;
     }

So once selected order fits your criteria, you can get all the info available about it.

Hope it helps

Luciano Ola
1011
Luciano Ola  
thrdel:


Once you select the order with OrderSelect and filter the results with OrderSymbol()= yourSymbol and OrderMagicNumber()= yourMagicNumber, then you can get

int myTicket= OrderTicket(), OrderType(), OrderOpenTime, etc.

Here is a sample, selecting from history, but you can change that to MODE_TRADES and OrdersHistoryTotal to OrdersTotal().

So once selected order fits your criteria, you can get all the info available about it.

Hope it helps


Yes it does help, I had actually decided to use historical orders after reading your earlier post and pondering for a while when I couldn't sleep.
Carl Schreiber
7357
Carl Schreiber  
MetaNt:

I was considering sending out orders across currencies that would act as some sort of message but I also realised that this would not be possible with some brokers.

Is there another way to do this? Would I have to use some sort of dll?


communication between EA on different charts:

1) global variables (easiest, use var.-name and stored value for inf.)

This allows comm. even between different terminals, no dll:

2) named pipes (faster)

3) files (read-write-friction?)

gooly

Luciano Ola
1011
Luciano Ola  
 bool FragileSymbol()
{   
 bool Fragile=false;
 bool FragilePositive=false; 
 double CurrentLots;
 double HistLots;
 string LastSymbol;
 if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES)){CurrentLots=OrderLots();LastSymbol=OrderSymbol();}
 if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)){if(OrderSymbol()==LastSymbol && OrderLots()>0 && CurrentLots/OrderLots()>=100000 && OrderSymbol()!=Symbol())Fragile=true;} 
 if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)){if(OrderSymbol()==LastSymbol && (OrderProfit() + OrderSwap() + OrderCommission())>0){FragilePositive=true;HistLots=OrderLots();}}
 if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES)){if(FragilePositive && OrderLots()<HistLots)Fragile=false;FragilePositive=false;}
 return (Fragile);
}

Please note the value 100000 has been arbitrarily chosen.

Will it work?? Who knows I can't do multi-currency back-testing on mql4, I'll have to change these lines slightly for mql5 and make my mql5 version of the EA a multi-currency one, which I have no idea how to do at the moment.

if(!FragileSymbol() && Period()>=PERIOD_D1)
{ 
"Trading Parameters for opening trades"
}
Luciano Ola
1011
Luciano Ola  
gooly:


communication between EA on different charts:

1) global variables (easiest, use var.-name and stored value for inf.)

This allows comm. even between different terminals, no dll:

2) named pipes (faster)

3) files (read-write-friction?)

gooly


I've never tried or considered this method before, what are all these terms? I apologise for the my dearth of knowledge.
123
To add comments, please log in or register