I am sending an order that is executed and shown in MT5.
MqlTradeResult tradeResult = trade.sendBuyMarket(2.);
double price = OrderGetDouble(ORDER_PRICE_OPEN);
MqlTradeResult shows 0.0 for price and so does OrderGetDouble(ORDER_PRICE_OPEN):
Is it due to the brokers settings that the order open price is not send back or am I doing something wrong?
You are doing something wrong.
I tried it again using some example code from the MT5 Help (F1):
//--- declare and initialize the trade request and result of trade request
//--- parameters of request
request.action =TRADE_ACTION_DEAL; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =0.2; // volume of 0.2 lot
request.type =ORDER_TYPE_SELL; // order type
request.price =SymbolInfoDouble(Symbol(),SYMBOL_BID); // price for opening
request.deviation=5; // allowed deviation from the price
request.magic =123; // MagicNumber of the order
//--- send the request
PrintFormat("OrderSend error %d",GetLastError()); // if unable to send the request, output the error code
//--- information about the operation
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
With the same result:
That is on a demo account at Admiral Markets.
So I tried on another demo account at Active Trades and there it works:
Changing the account made the difference here, not changing the code. Hope this might help if someone is facing the same issue.IF there can be something changed in the code so it works with any broker I would be happy to be assisted.
IF there can be something changed in the code so it works with any broker I would be happy to be assisted.
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006
#define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
TICKET_TYPE Ticket = OrderSend(_Symbol, OP_SELL, 0.2, Bid, 5, 0, 0, NULL, 123);
if (OrderSelect(Ticket, SELECT_BY_TICKET))
This is MT5-code.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.