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
OrderModify() works with the ticket number, so just select and use the ticket number for the order that you wish to modify.
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?
- www.mql5.com
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