Is it possible to run multiple currency pairs in the same account at the same time?

 

I tried bringing up multiple charts in the same platform but since OrderSelect() does not use a MagicNumber, when it is true for one pair, it is true for all pairs, so I tried the following:

      for(int i = 0; i<2; i++)

         switch (i)

         {

            case 0:

            {

               ChartClose(0);

               ChartOpen("EURUSD", 240);

               MAGICMA = GetMagicNumber();   // MagicNumber based on symbol and period

               if(CalculateCurrentOrders(Symbol()) == 0) CheckForOpen();

               else CheckForClose();

               break;

            }

            case 1:

            {

               ChartClose(0);

               ChartOpen("CADJPY", 240);

               MAGICMA = GetMagicNumber();   // MagicNumber based on symbol and period

               if(CalculateCurrentOrders(Symbol()) == 0) CheckForOpen();

               else CheckForClose();

               break;

            }

         }

 
jgreimer: ince OrderSelect() does not use a MagicNumber,
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
 
jgreimer:

I tried bringing up multiple charts in the same platform but since OrderSelect() does not use a MagicNumber, when it is true for one pair, it is true for all pairs, so I tried the following:

You can certainly manage multiple pairs on one account, you just need to identify the trades from the trades list. 

If you're running the EA on different charts, for example, you would loop through the trades list to find trades with the chart symbol and your EAs magic number - this example assumes no pending orders etc...

for(int i=OrdersTotal()-1;i>=0;i--)
 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  if(OrderSymbol()==_Symbol&&OrderMagicNumber()==mymagicnumber){
    // do something
}

But if you're looking at several pairs and periods, it would make sense to run the EA on one chart only, and then programatically look up the other pairs....but that's probably another subject.....

 

andrew:

 - this example assumes no pending orders etc...

Why would you assume that there are no pending orders?

You would just add a check

if(OrderType()==OP_BUY)
  {
  }

etc.

Reason: