Skip to content

Commit

Permalink
trade: introduce partial close of market orders (#25)
Browse files Browse the repository at this point in the history
This patch adds capability to partially close market order by overloading
close() and closeCurrent() in OrderManager class.
  • Loading branch information
yerden authored and dingmaotu committed Mar 17, 2018
1 parent a1d6c64 commit b5ae534
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Trade/OrderManager.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public:

//--- Order closing
bool closeCurrent();
bool closeCurrent(double lots);
bool close(int ticket);
bool close(int ticket,double lots);
bool closeBy(int ticket,int other)
{
bool res=OrderCloseBy(ticket,other,m_closeColor);
Expand Down Expand Up @@ -284,3 +286,34 @@ bool OrderManager::close(int ticket)
return closeCurrent();
}
//+------------------------------------------------------------------+
//| Partially close current selected market order |
//+------------------------------------------------------------------+
bool OrderManager::closeCurrent(double lots)
{
if(Order::IsPending())
{
Alert(">>> Use close() on pending order #",Order::Ticket());
return false;
}
if(!OrderClose(Order::Ticket(),lots,Order::E(),m_slippage,m_closeColor))
{
int err=Mql::getLastError();
m_lastError=err;
Alert(">>> Error OrderClose #",Order::Ticket(),": ",Mql::getErrorMessage(err));
return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Partially close the market order with specified ticket |
//+------------------------------------------------------------------+
bool OrderManager::close(int ticket,double lots)
{
if(!Order::Select(ticket))
{
Alert(">>> Error closing order with invalid ticket #",Order::Ticket(),": ",Mql::getErrorMessage(Mql::getLastError()));
return false;
}
return closeCurrent(lots);
}
//+------------------------------------------------------------------+

0 comments on commit b5ae534

Please sign in to comment.