OrderStopLoss function


for example, forex

In this example the OrderStopLoss() function was used. Its purpose is clear from its name, but nevertheless we’d better consider it in detail.

In order not to turn the studying of the OrderStopLoss() function into a boring theoretical description we will try to modify the previous example to get maximum practical use.

Our previous example worked only in the cases when Stop Loss was executed without slippage. We will modify a little bit our code:

   //---- select order/position with ticker 77777
   if ( OrderSelect (77777, SELECT_BY_TICKET) == true) 
     {
       // position is selected successfully 
       if ( ((OrderClosePrice() <= OrderStopLoss()) && (OrderType() == OP_BUY)) || 
            ((OrderClosePrice() >= OrderStopLoss()) && (OrderType() == OP_SELL)) )
          {
             // position closed by Stop Loss
             // ...
          }
       else
          {
             // position closed by Take Profit
             // ...
          }
     }
  else
    Print("OrderSelect() returned error - ",GetLastError());

This example is based on the following:

  • If the position was long (condition OrderType() == OP_BUY true), then Stop Loss will trigger at the order’s price or worse i.e. lower: (OrderClosePrice() <= OrderStopLoss()).
  • If the position was short (condition OrderType() == OP_SELL true), then Stop Loss will trigger at the order’s price or worse i.e. higher: (OrderClosePrice() >= OrderStopLoss()).

Next article: "OrderType function"

+7 (495) 710-76-76
© 1998—2008 «Alpari»

close

Your Personal Area

For alpari.classic enter your account number (a letter and 4 figures) and the code word for the Personal Area.

For alpari.micro account: enter your login (6 figures) and the password for MT.

Open an account!Forgotten your password?