Previous Next

GTrade.MoveStopLossWithComment()

Moves all StopLoss of open positions with a certain comment on a certain symbol.

The StopLoss is only moved if:

   1. the given value differs from the existing value of the StopLoss

   2. the StopLoss moves in the direction of profit, not in the opposite direction

int  GTrade.MoveStopLossWithComment(
   double  stopLoss,      // New desired value of the StopLoss
   string  comment,       // Required comment to move
   string  symbol = NULL  // Symbol
   );

Parameters

stopLoss

[in]  New desired value of the StopLoss.

comment

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

symbol

[in]  The symbol on which to change.

Return value

Returns the number of moved StopLoss.


Note

The function call can take place without further verification.


Example:

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

//--- Create a pointer to an empty class object
GTrade *trade;
GBar *bar;


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

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

   return(INIT_SUCCEEDED);
}

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


void OnTick ()
{
   //--- If the last candle closes above the high of the penultimate candle
   if ( bar.Close(1) >= bar.High(2) )
   {
      //--- Move StopLoss of all open "Auto Trade" positions to Low of the last candle
      trade.MoveStopLossWithComment( bar.Low(1), "Auto Trade" );
   }
}


See also

GTrade.MoveStopLoss, GTrade.OpenStopLoss, GTrade.OpenStopLossWithComment