How to convert send order from mql4 to mql5
How to convert send order from mql4 to mql5
Loading saved threads...
Carnality · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Carnality
Original post: https://stackoverflow.com/questions/57813061
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Below is the method I'm using to place an order after three minutes if it doesn't go through. I've converted the larger part of it from mql4 to mql5. It's just the commented part that I'm not sure how I'll change to mql5 since in mql5 send orders return bool's and not int's. I would be glad if I could get help with fixing this remaining part.
void MakeOrders()
{
static datetime lastTime = 0;
datetime currTime = iTime(Symbol(),PERIOD_M3,0);
if (currTime>lastTime)
{
for (int i=ObjectsTotal(0, 0, -1)-1; i>=0; i--)
{
string name = ObjectName(0, i, 0, -1);
if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)=="")
{
double entryPrice=ObjectGetDouble(0,name,OBJPROP_PRICE,1)-3*_Point;
double stopLoss=ObjectGetDouble(0,name,OBJPROP_PRICE,2);
double slDist=fabs(entryPrice-stopLoss);
double dTakeProfit=entryPrice-2*slDist;
MqlTradeRequest request={0};
MqlTradeResult result={0};
//--- parameters of request
request.action =TRADE_ACTION_DEAL; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =lotSize; // volume of 0.1 lot
request.type =ORDER_TYPE_BUY_LIMIT; // order type
request.price = entryPrice; // price for opening
//request.deviation=5; // allowed deviation from the price
request.magic =magicnumber; // MagicNumber of the order
request.tp = dTakeProfit;
request.sl = stopLoss;
//--- send the request
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError());
/*
int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);
if (ticketSell>0)
{
ObjectSetText(name,string(ticketSell));
i = ObjectsTotal()-1; // rather than continuing the 'for' loop, we must restart because arrows (ie new objects) were created.
}
*/
}
}
lastTime = currTime;
}
}
Quote
Report
Morimil · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Morimil
Original post: https://stackoverflow.com/a/63511968
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
if(result.retcode==10009 || result.order>0)
ObjectSetText(name,string(result.order));
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Carnality Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/57813061 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Below is the method I'm using to place an order after three minutes if it doesn't go through. I've converted the larger part of it from mql4 to mql5. It's just the commented part that I'm not sure how I'll change to mql5 since in mql5 send orders return bool's and not int's. I would be glad if I could get help with fixing this remaining part. void MakeOrders() { static datetime lastTime = 0; datetime currTime = iTime(Symbol(),PERIOD_M3,0); if (currTime>lastTime) { for (int i=ObjectsTotal(0, 0, -1)-1; i>=0; i--) { string name = ObjectName(0, i, 0, -1); if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)=="") { double entryPrice=ObjectGetDouble(0,name,OBJPROP_PRICE,1)-3*_Point; double stopLoss=ObjectGetDouble(0,name,OBJPROP_PRICE,2); double slDist=fabs(entryPrice-stopLoss); double dTakeProfit=entryPrice-2*slDist; MqlTradeRequest request={0}; MqlTradeResult result={0}; //--- parameters of request request.action =TRADE_ACTION_DEAL; // type of trade operation request.symbol =Symbol(); // symbol request.volume =lotSize; // volume of 0.1 lot request.type =ORDER_TYPE_BUY_LIMIT; // order type request.price = entryPrice; // price for opening //request.deviation=5; // allowed deviation from the price request.magic =magicnumber; // MagicNumber of the order request.tp = dTakeProfit; request.sl = stopLoss; //--- send the request if(!OrderSend(request,result)) PrintFormat("OrderSend error %d",GetLastError()); /* int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red); if (ticketSell>0) { ObjectSetText(name,string(ticketSell)); i = ObjectsTotal()-1; // rather than continuing the 'for' loop, we must restart because arrows (ie new objects) were created. } */ } } lastTime = currTime; } }
Checking account access…