Previous Next

GTrade.CloseWithComment()

Closes all open trades on a specific symbol that contain a specific comment.

int  GTrade.CloseWithComment(
   string  comment,       // Required comment to close
   string  symbol = NULL  // Symbol
   );

Parameter

comment

[in]  The comment that the open position must contain to be closed.

symbol

[in]  The symbol whose trades are to be closed.

Return value

Returns the number of closed trades.


Note

The comment passed must match exactly the comment in the position.


Example:

//--- Include the Glib classes
#include <Glib.mqh>

//--- Creation of a pointer to an empty class object
GTrade *trade;


int OnInit ()
{
   //--- Assign the class to the empty class object
   trade = gTrade();

   //--- Initialize the class data
   trade.Init();

   return(INIT_SUCCEEDED);
}

void OnDeinit (const int reason)
{
   //--- Release memory on exit
   delete trade;
}


void OnTick ()
{
   //--- Get the current hour of the day
   MqlDateTime dateTimeStruct;
   TimeCurrent(dateTimeStruct);
   int hour = dateTimeStruct.hour;

   //--- Close all open "Auto Trades" at 10pm
   if ( hour >= 22 )
   {
      trade.CloseWithComment("Auto Trade");
   }
}


See also

GTrade.CloseAllOnSymbol, GTrade.Open