Slippage and stop losses - page 2

To add comments, please log in or register
Keith Watford
Moderator
16236
Keith Watford  
Batuhan:

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);
      }
   }
}

Always count down when closing orders.

What is the point of your function?

If the price has hit the stop loss, it will already be closed.

If it hasn't, then you will be trying to close at an invalid price.

Batuhan
134
Batuhan  
Keith Watford:

Always count down when closing orders.

What is the point of your function?

If the price has hit the stop loss, it will already be closed.

If it hasn't, then you will be trying to close at an invalid price.


Ok ... see, got, thanks a lot.

You do agree with some posters here saying that both of them (SL and OrderClose function) should be used for the same order?

Keith Watford
Moderator
16236
Keith Watford  
Batuhan:


Ok ... see, got, thanks a lot.

You do agree with some posters here saying that both of them (SL and OrderClose function) should be used for the same order?

I agree that when it is intended that a trade be closed by the EA at a certain level, there should also be an emergency SL in place.

Batuhan
134
Batuhan  

Thanks Keith,

Thanks to all here shared their experiences.

Batuhan
134
Batuhan  

For example, let's say I have a long EURUSD position and its stop loss is at 1.1350.

In OnTick(), the most common way to use OrderClose() looks like the following, isn't it?

if(Bid <= 1.1350) OrderClose("Ticket", "Lots", Bid, 0);
12
To add comments, please log in or register