EA to modify multi currency pairs orders

 

Hello,

I would like to develop an EA in order to call orderModify() for each open trade, but unfortunately it works only for the currency pair of the chart where the EA is attached.

Is there a way to call orderModify() for several currency pairs?


Regards

Jérôme

 
jlafon:

Hello,

I would like to develop an EA in order to call orderModify() for each open trade, but unfortunately it works only for the currency pair of the chart where the EA is attached.

Is there a way to call orderModify() for several currency pairs?


Regards

Jérôme

OrderModify() works with the ticket number, so just select and use the ticket number for the order that you wish to modify. 

 
jlafon: but unfortunately it works only for the currency pair of the chart where the EA is attached.
Wrong, it modifies a ticket. Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.
 

Here is the code, inserted inside the OnTimer() function:

void OnTimer()
  {
  double currentSL, newSL, totalProfit, SLCGap, nbPIPsToUse;
    bool res, SLCput; 
    int total = OrdersTotal();

    RefreshRates();
    
    //GAIN
    for(int pos=0;pos<total;pos++)
        {
           if(OrderSelect(pos,SELECT_BY_POS)==false) {
              Print("Order not found");
              continue;
           }
           currentSL = OrderStopLoss();
           nbPIPsToUse = 10;
           if(OrderType() == OP_BUY){//on prend le Bid comme référence
               newSL = Bid - Point * nbPIPsToUse;
               if(!currentSL || newSL > currentSL){
                  res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(newSL,Digits),OrderTakeProfit(),0);
                  Print("SLC BUY--> ID=", OrderTicket(), " - ", OrderSymbol(), " -- OPENPRICE=", OrderOpenPrice()," -- BID=", Bid, " -- GAIN=", OrderProfit(), " -- PIP VALUE=", NormalizeDouble(MarketInfo(OrderSymbol(),MODE_TICKVALUE)*10*OrderLots(),2), " -- NB PIPS=", NormalizeDouble(nbPIPsToUse, 3), " -- OLD SL= ", OrderStopLoss(), " -- NEW SL=", NormalizeDouble(newSL,Digits));   
                  SLCput = true;              
               }
            }
           else{//EN SELL on prend le Ask comme référence
               newSL =  Ask + Point * nbPIPsToUse;
               if(!currentSL || newSL < currentSL){
                  res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(newSL,Digits),OrderTakeProfit(),0);
                  Print("SLC SELL--> ID=", OrderTicket(), " -- PAIRE=", OrderSymbol(), " -- PRIX DEPART=", OrderOpenPrice(), " -- ASK=", Ask, " -- GAIN=", OrderProfit(), " -- PIP VALUE=", NormalizeDouble(MarketInfo(OrderSymbol(),MODE_TICKVALUE)*10*OrderLots(),2), " -- NB PIPS=", NormalizeDouble(nbPIPsToUse, 3), " -- OLD SL= ", OrderStopLoss(), " -- NEW SL=", NormalizeDouble(newSL,Digits));   
                  SLCput = true;
               }    
            }
            if( SLCput && !res)
                Print("Error in OrderModify. Error code=",GetLastError());
            SLCput = false;
        }
   
  }

I get the error code 130 for each symbol except the chart attached to the EA.
I have to do something else in order to modify symbols that are not the one of the current chart.

Anyone has an idea?

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
Before we start developing, let's get acquainted with some features of the OOP, which will be used in this article.  Of course, we will use structures and classes. These are the basics of object oriented languages. A structure is a construction that allows containing a set of variables and functions of different types (except void). A class as...
Reason: