Order closed by non existing price

 

Symbol USDZAR, Sell position.

At 2021.05.25 21:16:38 EA closed the position when price was 13.80100, however position was closed at 13.93489. Any explanation?


 
Narek Kamalyan: Symbol USDZAR, Sell position. At 2021.05.25 21:16:38 EA closed the position when price was 13.80100, however position was closed at 13.93489. Any explanation?

You can see that the price gapped quite a bit there (high volatility) and if you look at the tick volume you will see that was very low liquidity at that time.

The result was very wide spreads at the time. Since the chart only shows bid prices and not the ask prices you can't see the spread on it, but that is where it would have been causing the position to close.


EDIT: The above Spread graph is taken from the Spread value stored with MT5 bar data. It is not the maximum spread but more of a "average" spread during the bar but its implementation differs from broker to broker. So it only serves as an indication of how spread widened during that period but not an indication of exactly by how much.
 

Also remember that Sell Positions close at the ask price, not the bid price.

  • Buy: opens at Ask, closes at Bid
  • Sell: opens at Bid, closes at Ask
 
Fernando Carreiro:

Also remember that Sell Positions close at the ask price, not the bid price.

Thank you Fernando. 

My EA uses virtual TP and SL and closing positions only by Bid price.Enters according to Buy-Ask, Sell-Bid, but exits only by Bid. In this I should compare my virtual TP with Ask price, not bid. So widening of the spread will not close the position. 

 
What happened, EA was looking at Bid price and once Bid price hit TP, it closed by Ask, causing negative profit. 
 
Narek Kamalyan:

Thank you Fernando. 

My EA uses virtual TP and SL and closing positions only by Bid price.Enters according to Buy-Ask, Sell-Bid, but exits only by Bid. In this I should compare my virtual TP with Ask price, not bid. So widening of the spread will not close the position. 

You can not close all orders using only Bid price

See @Fernando Carreiro 's post

 

Narek KamalyanMy EA uses virtual TP and SL and closing positions only by Bid price.Enters according to Buy-Ask, Sell-Bid, but exits only by Bid. In this I should compare my virtual TP with Ask price, not bid. So widening of the spread will not close the position. 

What happened, EA was looking at Bid price and once Bid price hit TP, it closed by Ask, causing negative profit. 

You cannot simply ignore the Ask price and only look at the Bid price. You have to monitor both. Your virtual stop may be based on the bid price, but you will have to add extra logic to also evaluate the Ask price at which the position will close at. Either you wait until the spread narrows again before closing or you take the loss.

In my own EAs, I always monitor the spread and I only open or close a position when the spread has dropped below a certain maximum amount. I will then reevaluate the conditions to see if is still valid for the enter or the exit prices that I set, as price may have changed considerably during the wait.

 
Fernando Carreiro:

You cannot simply ignore the Ask price and only look at the Bid price. You have to monitor both. Your virtual stop may be based on the bid price, but you will have to add extra logic to also evaluate the Ask price at which the position will close at. Either you wait until the spread narrows again before closing or you take the loss.

Thats great idea. Actually I am using spread filter to open, now I realized that I should use the filter also for close. Thanks. 

 
Fernando Carreiro:

You can see that the price gapped quite a bit there (high volatility) and if you look at the tick volume you will see that was very low liquidity at that time.

Bar Spread indi from your screenshot is availeble in codebase?

 
Narek Kamalyan: Bar Spread indi from your screenshot is availeble in codebase?

No, its my own Indicator! There might be something similar in the CodeBase, but I never looked and just coded my own!