trading multiple currency pair within the same EA

 

help please. I'm trying to write a EA that can trade multiple currency pair. below is the code:

OrderSend("EURUSD",OP_BUY,0.1,Ask,3,Ask-50*Point,Ask+50*Point,"",1234567,0,Blue);
OrderSend("GBPUSD",OP_BUY,0.1,Ask,3,Ask-50*Point,Ask+50*Point,"",1234568,0,Blue);
OrderSend("USDJPY",OP_BUY,0.1,Ask,3,Ask-50*Point,Ask+50*Point,"",1234569,0,Blue);

but it only trade 1 currency pair. if i choose EURUSD then it only trade EURUSD, if i choose GBPUSD then it only trade GBPUSD.

how to program it? thank

 
use MarketInfo() to get correct Ask for corresponding symbol.
 

Is it like this?

OrderSend("EURUSD",OP_BUY,0.1,MarketInfo("EURUSD",MODE_ASK),3,MarketInfo("EURUSD",MODE_ASK)-50*Point,MarketInfo("EURUSD",MODE_ASK)+50*Point,"",1234567,0,Blue);
OrderSend("GBPUSD",OP_BUY,0.1,MarketInfo("GBPUSD",MODE_ASK),3,MarketInfo("GBPUSD",MODE_ASK)-50*Point,MarketInfo("GBPUSD",MODE_ASK)+50*Point,"",1234567,0,Blue);
OrderSend("USDJPY",OP_BUY,0.1,MarketInfo("USDJPY",MODE_ASK),3,MarketInfo("USDJPY",MODE_ASK)-50*Point,MarketInfo("USDJPY",MODE_ASK)+50*Point,"",1234567,0,Blue);

but still cannot. if I choose GBPUSD as symbol, EURUSD & USDJPY have no trade.

how to make all of the currency pair able to execute an order no matter what symbol I choose?

 
Perhaps you'll see why if you add some debugging:

Print("GBPUSD Ask ", MarketInfo("GBPUSD",MODE_ASK));


Or just look at the EA log that no one can see but you. Why to let us guessing?
 

sorry for my unclear question. how to see the EA log? below is my full program & the journal from the strategy tester. is any problem with the OrderSend function or any else?

2007.08.23 20:59:18 2007.01.04 17:00 testtest EURUSD,H1: OrderSend error 4106
2007.08.23 20:59:18 2007.01.04 17:00 testtest EURUSD,H1: unknown symbol name GBPUSD for OrderSend function
2007.08.23 20:59:18 2007.01.04 00:00 testtest EURUSD,H1: OrderSend error 4106
2007.08.23 20:59:18 2007.01.04 00:00 testtest EURUSD,H1: unknown symbol name USDJPY for OrderSend function

 
#define MAGICMAeu  12345678
#define MAGICMAgu  12345679
#define MAGICMAuj  12345680
 
int directioneu=0;
int directiongu=0;
int directionuj=0;
 
void eurusd()
{
   double StocMain;
   double StocSignal;
   StocMain=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   StocSignal=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
 
   if(directioneu==0)
   {
      if(StocMain>StocSignal)
      {
         OrderSend("EURUSD",OP_BUY,0.1,MarketInfo("EURUSD",MODE_ASK),3,MarketInfo("EURUSD",MODE_ASK)-50*Point,MarketInfo("EURUSD",MODE_ASK)+50*Point,"",MAGICMAeu,0,Blue);
         directioneu=1;
      }
   }
   else if(directioneu==1)
   {
      if(StocMain<StocSignal)
      {
         OrderSend("EURUSD",OP_SELL,0.1,MarketInfo("EURUSD",MODE_BID),3,MarketInfo("EURUSD",MODE_BID)+50*Point,MarketInfo("EURUSD",MODE_BID)-50*Point,"",MAGICMAeu,0,Red);
         directioneu=0;
      }
   }
}
 
void gbpusd()
{
   double StocMain;
   double StocSignal;
   StocMain=iMACD("GBPUSD",0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   StocSignal=iMACD("GBPUSD",0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
 
   if(directiongu==0)
   {
      if(StocMain>StocSignal)
      {
         OrderSend("GBPUSD",OP_BUY,0.1,MarketInfo("GBPUSD",MODE_ASK),3,MarketInfo("GBPUSD",MODE_ASK)-50*Point,MarketInfo("GBPUSD",MODE_ASK)+50*Point,"",MAGICMAgu,0,Blue);
         directiongu=1;
      }
   }
   else if(directiongu==1)
   {
      if(StocMain<StocSignal)
      {
         OrderSend("GBPUSD",OP_SELL,0.1,MarketInfo("GBPUSD",MODE_BID),3,MarketInfo("GBPUSD",MODE_BID)+50*Point,MarketInfo("GBPUSD",MODE_BID)-50*Point,"",MAGICMAgu,0,Red);
         directiongu=0;
      }
   }
}
 
void usdjpy()
{
   double StocMain;
   double StocSignal;
   StocMain=iMACD("USDJPY",0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   StocSignal=iMACD("USDJPY",0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
 
   if(directionuj==0)
   {
      if(StocMain>StocSignal)
      {
         OrderSend("USDJPY",OP_BUY,0.1,MarketInfo("USDJPY",MODE_ASK),3,MarketInfo("USDJPY",MODE_ASK)-50*Point,MarketInfo("USDJPY",MODE_ASK)+50*Point,"",MAGICMAuj,0,Blue);
         directionuj=1;
      }
   }
   else if(directionuj==1)
   {
      if(StocMain<StocSignal)
      {
         OrderSend("USDJPY",OP_SELL,0.1,MarketInfo("USDJPY",MODE_BID),3,MarketInfo("USDJPY",MODE_BID)+50*Point,MarketInfo("USDJPY",MODE_BID)-50*Point,"",MAGICMAuj,0,Red);
         directionuj=0;
      }
   }
}
 
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{
   if(Volume[0]>1) return;
 
   eurusd();
   gbpusd();
   usdjpy();
   
   return(0);
}
//+------------------------------------------------------------------+
 
The tester doesn't support multicurrency trading
 
oic. thank, how if on realtime chart?
 
Irtron:
The tester doesn't support multicurrency trading

But does the tester support trading one ONE currency, using trading signals based off of the price of another currency?


I have not been able to succesfully do this yet, any thoughts?

 

no, test mode only support ONE currency, not using any other currency, sometime even faile when using other timeframe of this currency. (in fact, you can program, but no effect or receiving error information.)

but in real mode, most time no problem.

 

Alan

> I'm trying to write a EA that can trade multiple currency pair

Curious as to... why?!

It's tough enough writing one for one pair & timeframe...
Development & optimisation are complicated greatly be having n pairs...
Testing without limiting to one-pair-at-a-time wont show full results..
Currency correlation is maybe OK as a concept for macro accounts with a position trade plan & deep pockets

Just wondering...

-BB-

 
BarrowBoy:

Alan

> I'm trying to write a EA that can trade multiple currency pair

Curious as to... why?!

It's tough enough writing one for one pair & timeframe...
Development & optimisation are complicated greatly be having n pairs...
Testing without limiting to one-pair-at-a-time wont show full results..
Currency correlation is maybe OK as a concept for macro accounts with a position trade plan & deep pockets

Just wondering...

-BB-

One of the best trading strategies involve trading multiple pairs. So it is very much worthwhile to investigate how to replicate this on MT4. What we can always do is program a separate version of our EA to trade only on one currency at a time, then mix the trade reports at the end. A dirty hack, but it has potential, especially in the world of statistcal arbitrage.