Slippage and stop losses

 

For the purpose of reducing the exposure to slippage, is there any difference between using regular stop losses embedded in open orders or using OrderClose() function at the relevant price level?

Which method would you advise?

Thanks.

 
Batuhan:

For the purpose of reducing the exposure to slippage, is there any difference between using regular stop losses embedded in open orders or using OrderClose() function at the relevant price level?

Which method would you advise?

Thanks.

I would go with regular SL, since it's set on the broker's server not on client terminal. Using so called virtual SL on client you have extra time needed to catch the event & send OrderClose() to broker. Not to mention that you are exposed to higher risk due to additional potential points of failure like hardware or software error of your computer and network problems.  

 
I see ... thank you so much.
 

So, I think that, in professionally written codes, coders never use market orders always use pending orders. Can we make such a generalization?

 
Batuhan:

So, I think that, in professionally written codes, coders never use market orders always use pending orders. Can we make such a generalization?

No, we can't. If you want to enter the market based on factors other than fixed price level you need to use market order.

 

I hope I don't bore you with my newbie questions, thanks a lot.


One more about slippage,

The document says that: "At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price."

Is there any function of slippage when sending market orders?

It seems to me that there is not.

 
Batuhan:

I hope I don't bore you with my newbie questions, thanks a lot.


One more about slippage,

The document says that: "At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price."

Is there any function of slippage when sending market orders?

It seems to me that there is not.

https://docs.mql4.com/trading/ordersend

OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function. At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a...
 

For understanding better, I needed to get some information about execution types.

Mostly clear, I think.


Just would like to ask one more about pending orders:

My broker uses market execution for market orders.

When the pending orders (as well as stops and take profits) are triggered, does the broker use the market execution as well?

 
Batuhan:

For the purpose of reducing the exposure to slippage, is there any difference between using regular stop losses embedded in open orders or using OrderClose() function at the relevant price level?

Which method would you advise?

Thanks.

Use both and you get the best of both worlds. Using direct OrderClose you ensure the order is closed just in case your broker does not honor the SL. Using the regular SL grants you safety in case you get disconnected from the server and you cannot close the order yourself.
 
I'd recommend a virtual and a hard stop-loss. The virtual SL would allow for a soft and timely exit without much slippage. But if the market is choppy, volatile or a spike occurs then you would need a hard SL to protect your position. In this case every millisecond counts.
 

How about using a function like the following at every tick for closing opened orders at their stop losses?

A newbie, needs confirmation from experienced coders.

Thanks.


void Close_Order()
{
 for(int i = 1; i <= OrdersTotal(); i++)
   {
    OrderSelect(i, SELECT_BY_POS);
    if(OrderType() == OP_SELL || OrderType() == OP_BUY)
      {
       OrderClose(OrderTicket(), OrderLots(), OrderStopLoss(), 0);
      }
   }
}
Reason: