Needs an advice with (( modify ( ModifyOpenOrder and ModifyPendingOrder) onthe same time ))

 

Dear All

I am trying to make a code which modifying  pending order and open order on the same time, but I am facing an issue
I made it to change the pending order, but it is not changing the open order.

the code is sending an pending orders ( sell limit, buy limit, buy stop or sell stop ) and it is modify it in each  candle until it is opened. (( the same ticket was made for Pending orders, and it is changed to opening orders) and than it sends an pending orders again ..........
when the pending orders is opened, so it has to modify the SL to the new price, but it is not.

it has to modify Pending orders and opening orders on the same time
I mean there is an pending orders get modified each new candle

I need an advice and help

 

Is this a question about MQL5 (or MQL4)?

There are no standard functions or methods called "ModifyOpenOrder" and "ModifyPendingOrder" in MQL5 (or MQL4). If you are referring to code from an Article or CodeBase publication, then please post in that publication's discussion topic.

When asking a question, please provide all relevant information, including screenshots, log output, example code, etc.

 
 Please use the CODE button (Alt-S) when inserting code — https://www.mql5.com/en/articles/24#insert-code
 
Yes it is for MQL5.

This is the code I am using and it is working with Pending Orders only
void ModifyPendingOrder(ulong orderTicket, double newPrice, double stopLossPrice)
{
MqlTradeRequest modifyRequest = {};
MqlTradeResult modifyResult = {};

modifyRequest.action = TRADE_ACTION_MODIFY;
modifyRequest.order = orderTicket;
modifyRequest.price = newPrice;
modifyRequest.sl = stopLossPrice;
modifyRequest.deviation = 10;
modifyRequest.magic = 123456;
modifyRequest.comment = "Modify Pending Order";

if (OrderSend(modifyRequest, modifyResult))
{
Print("modify done ticket: ", orderTicket);
}
else
{
Print("modify gets lost ", GetLastError());
}
}
void ModifyOpenOrder(ulong orderTicket, double EMAPrice, double stopLossPrice)
{
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);

MqlTradeRequest modifyRequest = {};
MqlTradeResult modifyResult = {};

if (OrderSelect(orderTicket)) {
long orderType = OrderGetInteger(ORDER_TYPE);

if (orderType == ORDER_TYPE_BUY)

{
modifyRequest.action = TRADE_ACTION_MODIFY;

modifyRequest.order = orderTicket;
modifyRequest.sl = stopLossPrice;
}
else if (orderType == ORDER_TYPE_SELL) {
modifyRequest.action = TRADE_ACTION_MODIFY;
modifyRequest.order = orderTicket;
modifyRequest.sl = stopLossPrice;
}
if (OrderSend(modifyRequest, modifyResult)) {
Print( "modify done ticket" , orderTicket);
} else {
Print( "modify gets lost ", GetLastError());
}
}
}
for (int i = 0; i < ArraySize(orderTickets); i++)
{
ulong ticket = orderTickets[i];
if (OrderSelect(ticket))
{
ulong orderType = OrderGetInteger(ORDER_TYPE);

double stopLossPrice = 0;
if (orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP)
{
stopLossPrice = buy ATRStoplossFinder;
}
else if (orderType == ORDER_TYPE_SELL_LIMIT || orderType == ORDER_TYPE_SELL_STOP)
{
stopLossPrice = sellATRStoplossFinder;
}

ModifyPendingOrder(ticket, ATRStoplossFinder, stopLossPrice);

ModifyOpenOrder(ticket, ATRStoplossFinder , stopLossPrice);
}
}

}



and it is working with Pending Orders Only, so please advice
 
abuqies #:
Yes it is for MQL5.

This is the code I am using and it is working with Pending Orders only

and it is working with Pending Orders Only, so please advice

On MT5 there is no such thing as an open order. Orders are pending. Deals and Positions are open trades.

 
Ok, so please tell me what to do?!
 
abuqies #: Ok, so please tell me what to do?!

Please read the following and follow it up with the necessary research to properly familiares yourself with how it all works ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.


 
Ok. thanks
 
Fernando Carreiro #:

Please read the following and follow it up with the necessary research to properly familiares yourself with how it all works ...


Dear Fernando
I tried to follow it, but still not working.
could you please help me?!
 
abuqies #: Dear Fernando, I tried to follow it, but still not working. could you please help me?!

The forum is for asking questions and receiving advice on specific issues. It is not for writing the code for you.

I am unavailable for Freelance work, but I am sure you can find other Freelance developers who can rewrite your code for you.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2025.01.15
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Fernando Carreiro #:

The forum is for asking questions and receiving advice on specific issues. It is not for writing the code for you.

I am unavailable for Freelance work, but I am sure you can find other Freelance developers who can rewrite your code for you.

Thanks