Previous Next


Moves all StopLoss of the open positions 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.MoveStopLoss(
   double  stopLoss,      // New desired value of the StopLoss
   string  symbol = NULL  // Symbol



[in]  New desired value of the StopLoss.


[in]  The symbol on which the changes are to be made.

Return Value

Returns the number of moved StopLoss.


The function call can take place without further examination.


//--- 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


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 positions to Low of the last candle
      trade.MoveStopLoss( bar.Low(1) );

See also

GTrade.MoveStopLossWithComment, GTrade.OpenStopLoss, GTrade.OpenStopLossWithComment