Obtaining the actual open price of a sell stop order.

 

Hi.

I have written an EA which places buy and sell stop orders at certain places. After an order is filled, if price moves in my favour, I want to move my stop loss to break even.

To get the order open price I use the following code (for a short position):

HistoryOrderGetDouble(sellStopTicket[ORDER_TICKET],ORDER_PRICE_OPEN,open);

I then use the value that gets stored in open to move the stop loss to break even with the following code (using the function provided in the CTrade class):

trade.PositionModify(_Symbol,open,0);

Yesterday, my sell stop was hit. It was set at 1.30538. The deal, created by my order was actually opened at 1.30530, an 0.8 pip difference.

When I moved my SL to break even, it was moved to 1.30538. Price then moved back up, and I was stopped out at an 0.8 pip loss.

What I want to know is, was this difference between the order and deal opening price down to slippage, or down to spread. I know that the

typical spread for the pair is 0.8 pips. What is the best way to obtain the actual opening price of a stop order, so a stop loss can be placed in the correct place.

Thanks. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
kingkevbo:

Hi.

...

Thanks. 

Hello,

The difference of 0.8 was probably due to slippage. The problem is your are using the price of your sell stop to set your SL, and not the actual open price. You have to use HistorDealGetDouble or PositionGetDouble.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
angevoyageur:

Hello,

The difference of 0.8 was probably due to slippage. The problem is your are using the price of your sell stop to set your SL, and not the actual open price. You have to use HistorDealGetDouble or PositionGetDouble.

Thanks for your reply. PositionGetDouble is going to be the easiest way I think. Didn't think of that. It simplifies the code a lot too. Thanks.
Reason: