English

## Using multiple pairs in EA to calculate trading parameter

 4 1468714724 2014.04.21 05:29   This is my first time trying to create an EA that uses multiple pairs. I have been having trouble with MetaTrader printing out the correct numbers and I can't figure it out. I have dumbed my code down to find the problem. The variable DiffClose should produce HigherPairClose / LowerPairClose, or the close prices of EURJPY / USDJPY. When I have this commented on the screen DiffClose is equal to something like 1 billion when it should be around 1.38... I am using this EA attached to a EURUSD 1-minute chart on a DEMO account. Also, I tried this on the Strategy Tester and got a zero divide error. My understanding is that Strategy Tester cannot do multiple pair strategies, is this true?```#define MAGIC 978 //--- input parameters input string   MainPair="EURUSD"; input string   LowerPair="USDJPY"; input string   HigherPair="EURJPY"; input double   Lots=0.1; //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ void OnInit()   { //---    if(Bars(_Symbol,_Period) < 60 && IsTradeAllowed() == false)    {       Alert("There are less than 60 bars on the chart, EA terminated!");       return;    }   } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick()   { //---      double MainPairClose = MarketInfo(MainPair,MODE_BID);    if(MainPairClose == 0)    {       Print("MainPairClose = 0");       return;    }    double LowerPairClose = MarketInfo(LowerPair,MODE_BID);    if(LowerPairClose == 0)    {       Print("LowerPairClose = 0");       return;    }    double HigherPairClose = MarketInfo(HigherPair,MODE_BID);    if(HigherPairClose == 0)    {       Print("HigherPairClose == 0");       return;    }    double DiffClose = HigherPairClose / LowerPairClose;         Comment(StringFormat("MainPair: %G\nLowerPair: %G\nHigherPair: %G\nDiffClose: %d",MainPairClose,LowerPairClose,HigherPairClose,DiffClose));       int ticket;    bool closeTicket;    int total = 0;    for(int i = 0; i < OrdersTotal(); i++)    {       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false)          break;       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)          total++;    }    if(total == 0)    {      if(DiffClose > 3)       {          ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,NULL,MAGIC,0,clrRed);          return;       }       if(DiffClose < -3)       {          ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,MAGIC,0,clrBlue);          return;       }    }    if(total >= 1)    {       if(DiffClose <= 2.5 && DiffClose >= -2.5)       {          for(int i = 0; i < OrdersTotal(); i++)          {             if(OrderType() == OP_BUY)             {                if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)                {                   if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)                      closeTicket = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrWhite);                }                else                   break;             }             if(OrderType() == OP_SELL)             {                if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)                {                   if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)                      closeTicket = OrderClose(OrderTicket(),OrderLots(),Ask,3,clrWhite);                }                else                   break;             }          }       }    }    return;   } //+------------------------------------------------------------------+ ```