# Stop Level for StopLoss

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

Staff member
This depends on what kind of order you are submitting. For pending orders, #1 is true. For market orders, #2 is true.

This depends on what kind of order you are submitting. For pending orders, #1 is true. For market orders, #2 is true.
And for Trailing Market order StopLoss?

#### Enivid

Staff member
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.

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--)
{
{
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:

#### NatureGirl

jus set Ur stop loss a bit away from the entry price

Replies
1
Views
307
Replies
11
Views
5K
Replies
0
Views
537
Replies
9
Views
4K
Replies
5
Views
716