Stop Level for StopLoss

shanmugapradeep

Active Trader
Dec 18, 2020
112
4
34
38
Hello,

Which one of the following statements is correct regarding the calculation of stop loss?

1. Stop Loss should be a distance from the Order Open Price/Order Entry Price by Stop Level.

Or

2. Stop Loss should be a distance from the Bid/Ask Price by Stop Level?

Or

3. Stop Loss should be a distance from the Bid/Ask price as well as the Order Open Price?

Thank you.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,622
1,367
144
Odesa
www.earnforex.com
And for Trailing Market order StopLoss?
You mean when you are using OrderModify to update an existing market order? It's the distance from the current Bid/Ask that counts. Think about it, if it were the Open Price that counted, you wouldn't be able to set the SL to breakeven.
 

shanmugapradeep

Active Trader
Dec 18, 2020
112
4
34
38
You mean when you are using OrderModify to update an existing market order?
Yes, correct.

I am trying something like this

MQL4:
void TrailingStopLoss(int TrailingStopLoss_magic)
  {
   int StopLevel_TrailingGap = Trailing_Gap < gStopLevel_OnTick ? gStopLevel_OnTick + 5 : Trailing_Gap;
   int StopLevel_TrailingTP = gStopLevel_OnTick > 0 ? gStopLevel_OnTick + 5 : 10;
// Loop through all open orders
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         double TrailingStopLoss_entryPrice = OrderOpenPrice();
         // Check if the order is a buy order with magic number 1
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == TrailingStopLoss_magic && OrderType() == OP_BUY)
           {
            if(Bid - (TrailingStopLoss_entryPrice + StopLevel_TrailingTP * gPips) > gPips * StopLevel_TrailingGap)
              {
               if(OrderStopLoss() < Bid - gPips * StopLevel_TrailingGap || OrderStopLoss() == 0)
                 {
                  ResetLastError();
                  RefreshRates();
                  gModify = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - gPips * StopLevel_TrailingGap, OrderTakeProfit(), 0, clrNONE);
                  if((_LastError != ERR_NO_ERROR && _LastError != ERR_NO_MQLERROR) || !gModify)
                     Print(__FUNCTION__ + " => Buy Order Error Code : " + GetLastError());
                 }
              }
           }
 
         // Check if the order is a sell order with magic number 2
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == TrailingStopLoss_magic && OrderType() == OP_SELL)
           {
            if((TrailingStopLoss_entryPrice - StopLevel_TrailingTP * gPips) - Ask > gPips * StopLevel_TrailingGap)
              {
               if(OrderStopLoss() > Ask + gPips * StopLevel_TrailingGap || OrderStopLoss() == 0)
                 {
                  ResetLastError();
                  RefreshRates();
                  gModify = OrderModify(OrderTicket(), OrderOpenPrice(), Ask + gPips * StopLevel_TrailingGap, OrderTakeProfit(), 0, clrNONE);
                  if((_LastError != ERR_NO_ERROR && _LastError != ERR_NO_MQLERROR) || !gModify)
                     Print(__FUNCTION__ + " => Sell Order Error Code : " + GetLastError());
                 }
              }
           }
        }
     }
  }
 
Last edited: