Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trade: improve error handling #26

Merged
merged 1 commit into from
Mar 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Trade/OrderManager.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,13 @@ bool OrderManager::modify(int ticket,int stoploss,int takeprofit)
bool modifyStoploss=stoploss>0;
bool modifyTakeprofit=takeprofit>0;
if(!(modifyStoploss || modifyTakeprofit)) return false;
if(!Order::Select(ticket)) return false;

if(!Order::Select(ticket))
{
int err=Mql::getLastError();
m_lastError=err;
Alert(">>> Error modifying order with invalid ticket #",ticket,": ",Mql::getErrorMessage(err));
return false;
}
double sl=modifyStoploss ? Order::PPO(-stoploss) : Order::StopLoss();
double tp=modifyTakeprofit ? Order::PPO(takeprofit) : Order::TakeProfit();
return modify(ticket,sl,tp);
Expand Down Expand Up @@ -280,7 +285,9 @@ bool OrderManager::close(int ticket)
{
if(!Order::Select(ticket))
{
Alert(">>> Error closing order with invalid ticket #",Order::Ticket(),": ",Mql::getErrorMessage(Mql::getLastError()));
int err=Mql::getLastError();
m_lastError=err;
Alert(">>> Error closing order with invalid ticket #",ticket,": ",Mql::getErrorMessage(err));
return false;
}
return closeCurrent();
Expand All @@ -293,6 +300,7 @@ bool OrderManager::closeCurrent(double lots)
if(Order::IsPending())
{
Alert(">>> Use close() on pending order #",Order::Ticket());
m_lastError=ERR_NO_RESULT; // signal the failure
return false;
}
if(!OrderClose(Order::Ticket(),lots,Order::E(),m_slippage,m_closeColor))
Expand All @@ -311,7 +319,9 @@ bool OrderManager::close(int ticket,double lots)
{
if(!Order::Select(ticket))
{
Alert(">>> Error closing order with invalid ticket #",Order::Ticket(),": ",Mql::getErrorMessage(Mql::getLastError()));
int err=Mql::getLastError();
m_lastError=err;
Alert(">>> Error closing order with invalid ticket #",ticket,": ",Mql::getErrorMessage(err));
return false;
}
return closeCurrent(lots);
Expand Down