{
MqlTradeRequest Request;
MqlTradeResult Results;
ZeroMemory(Request);
ZeroMemory(Results);
Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
Request.action=TRADE_ACTION_DEAL;
Request.type=ORDER_TYPE_SELL;
Request.symbol=symbol;
Request.volume=volume;
Request.deviation=deviation;
Request.comment=comment;
Request.type_filling=filling;
bool res=false;
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
}
I recently raised the issue of re-opening orders. I thought I had solved the problem because everything was working very well for a week. But today I have encountered a similar problem only with opening.
A very large number of orders opened on Finam, and 9 on Otkritie... although in all cases only one order should have opened.
Here is a code snippet from the EA
{
Coment="Open Sell "+string(OpenOrders+1);
ret=OpenSellPosition(_Symbol,volume,Coment,Sleeppage,Filling);
}
if(ret)
{
OpenOrders++;
PriceLastOpen=price;
}
bool OpenSellPosition(string symbol, double volume, string comment="", ulong deviation=10, ENUM_ORDER_TYPE_FILLING filling=ORDER_FILLING_FOK)
{
MqlTradeRequest Request;
MqlTradeResult Results;
ZeroMemory(Request);
ZeroMemory(Results);
Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
Request.action=TRADE_ACTION_DEAL;
Request.type=ORDER_TYPE_SELL;
Request.symbol=symbol;
Request.volume=volume;
Request.deviation=deviation;
Request.comment=comment;
Request.type_filling=filling;
bool res=false;
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
}
i.e. we can see from the code that if the operation is successful, the variableOpenOrders increases, which initially equals 0
If it is higher than 0, there should be no further opening of the order, but the entire pile of orders is opened with the comment Order1.
I check if there is a positive response in the function opening the order and if the order ticket has been received, but for some reason this function returns false, even though the order is actually set.
Can you explain what is wrong and how to fix this problem?
Bad forex legacy.
You should checkResults.order.
If the order is placed, it does not mean that the deal has already been done.
Bad forex legacy.
We have to check it out.order.
If an order is placed, it does not mean that a trade has already been executed.
I assume that the information about the deal has not yet arrived. Here (highlighted in red) you are relying on luck. And she is a capricious lady :-))
{
MqlTradeRequest Request;
MqlTradeResult Results;
ZeroMemory(Request);
ZeroMemory(Results);
Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
Request.action=TRADE_ACTION_DEAL;
Request.type=ORDER_TYPE_SELL;
Request.symbol=symbol;
Request.volume=volume;
Request.deviation=deviation;
Request.comment=comment;
Request.type_filling=filling;
bool res=false;
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
}
I assume that the information about the deal has not yet arrived. Here (highlighted in red) you are relying on luck. And she is a capricious lady :-))
{
MqlTradeRequest Request;
MqlTradeResult Results;
ZeroMemory(Request);
ZeroMemory(Results);
Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
Request.action=TRADE_ACTION_DEAL;
Request.type=ORDER_TYPE_SELL;
Request.symbol=symbol;
Request.volume=volume;
Request.deviation=deviation;
Request.comment=comment;
Request.type_filling=filling;
bool res=false;
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
}
You need to log all trades. For example, like this:
first in the "header" we connect the CTrade trade class
CTrade m_trade; // trading object
and here is an example of Buy operation:
{
if(m_trade.ResultDeal()==0)
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
else
Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
}
else
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
so you can get two errors: first level - operation didn't pass basic check and second level - check of trade's ticket.
Then, if there is a problem, you can use the logs to figure it out.
Added: the above is true for the SYNC mode of operation.
Now the gurus here will teach you too ))
Объясните что не так, как решить данную проблему?
With your experience, it's unseemly to ask such questions here.
You need to log all trades. For example, like this:
first in the "header" we connect the CTrade trade class
CTrade m_trade; // trading object
and here is an example of Buy operation:
{
if(m_trade.ResultDeal()==0)
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
else
Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
}
else
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
so you can get two errors: first level - operation didn't pass basic check and second level - check of trade's ticket.
Then, if there is a problem, you can use the logs to figure it out.
Added: this is true for the SYNC mode of operation.
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
You need to log all trades. For example, like this:
first in the "header" we connect the CTrade trade class
CTrade m_trade; // trading object
and here is an example of Buy operation:
{
if(m_trade.ResultDeal()==0)
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
else
Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
}
else
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription());
so you can get two errors: first level - operation didn't pass basic check and second level - check of trade's ticket.
Then, if there is a problem, you can use the logs to figure it out.
Added: this is true for the SYNC mode of operation.
That's exactly what I've done.
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I recently raised a topic on reopening orders. Thought I had solved the problem, as everything was working very smoothly for a week. But today I have encountered a similar problem only when opening.
A lot of orders opened on Finam, and 9 on Otkritie...although only one order should have opened in all cases.
Here is a code snippet from the EA
{
Coment="Open Sell "+string(OpenOrders+1);
ret=OpenSellPosition(_Symbol,volume,Coment,Sleeppage,Filling);
}
if(ret)
{
OpenOrders++;
PriceLastOpen=price;
}
bool OpenSellPosition(string symbol, double volume, string comment="", ulong deviation=10, ENUM_ORDER_TYPE_FILLING filling=ORDER_FILLING_FOK)
{
MqlTradeRequest Request;
MqlTradeResult Results;
ZeroMemory(Request);
ZeroMemory(Results);
Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
Request.action=TRADE_ACTION_DEAL;
Request.type=ORDER_TYPE_SELL;
Request.symbol=symbol;
Request.volume=volume;
Request.deviation=deviation;
Request.comment=comment;
Request.type_filling=filling;
bool res=false;
res=OrderSend(Request,Results);
if(res)
{
if(Results.deal>0) return(true);
else return(false);
}
return(false);
}
i.e. we can see from the code that if the operation is successful, the variableOpenOrders increases, which initially equals 0
If it is higher than 0, there should be no further opening of the order, but the entire pile of orders is opened with the comment Order1.
I check if there is a positive response in the function opening the order and if the order ticket has been received, but for some reason this function returns false, even though the order is actually set.
Explain what is wrong, how to solve this problem?