Here is some MQL code for sending an order that records execution duration and slippage to use in MetaTrader expert advisors or scripts.
You can modify it or copy and paste bits of it to put into your own code.
Please report back if you find any brokers whose order executions take more than 1s and/or incur frequent slippage of more than 1 pip.
You can modify it or copy and paste bits of it to put into your own code.
Code:
int SendOrder(string symbol, int orderType, double volumeInLot, int openSlipAllowedInPoints, int magicNumber, string orderComment) {
if (orderType == OP_BUY) double requestedPrice = MarketInfo(symbol, MODE_ASK);
else requestedPrice = MarketInfo(symbol, MODE_BID);
int orderStartPointInTime = GetTickCount();
int ticket = OrderSend(symbol, orderType, volumeInLot, requestedPrice, OpenSlipAllowedInPoints, 0, 0, orderComment, magicNumber, 0);
int orderExecutionDurationInMs = GetTickCount() - orderStartPointInTime;
if (ticket == -1) { //execution failed
int errorCode = GetLastError();
Print(StringConcatenate("Error sending order: " + errorCode + " (" + ErrorDescription(errorCode) + "). Execution duration = ", orderExecutionDurationInMs, "ms"));
//"Time (Local)", "Symbol", "Open or close", "Ticket", "Execution duration (ms)", "Slippage (QCU)", "Error code", "Error description"
FileWrite(diskFileHandle, TimeToStr(TimeLocal(), TIME_DATE|TIME_MINUTES|TIME_SECONDS), symbol, "open", ticket, orderExecutionDurationInMs, "", errorCode, ErrorDescription(errorCode));
FileFlush(diskFileHandle);
} else {
if (OrderSelect(ticket, SELECT_BY_TICKET)) {
if (orderType == OP_BUY) double slippageIncurred = OrderOpenPrice() - requestedPrice;
else slippageIncurred = requestedPrice - OrderOpenPrice();
Print(StringConcatenate("Execution duration = ", orderExecutionDurationInMs, "ms,Slippage = ", DoubleToStr(slippageIncurred * 10000, 1), "pips"));
FileWrite(diskFileHandle, TimeToStr(TimeLocal(), TIME_DATE|TIME_MINUTES|TIME_SECONDS), symbol, "open", ticket, orderExecutionDurationInMs, DoubleToStr(slippageIncurred, Digits));
FileFlush(diskFileHandle);
}
}
return (ticket);
}
Please report back if you find any brokers whose order executions take more than 1s and/or incur frequent slippage of more than 1 pip.
Last edited: