wrong closing prices problem ?

 

how to fix this wrong closing prices problem ?

i has many of that in my account random closing prices not the take profit price target ?
what to do ?

Extract profit down to the last pip
Extract profit down to the last pip
  • 2019.08.05
  • www.mql5.com
The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
Files:
fulldata.png  47 kb
wrong.png  5 kb
 
mohamed elsharkawey:

i has many of that in my account random closing prices not the take profit price target ?
what to do ?

1. search about bid ask and compare trade history again

2. check your ea. check if price being normalized in Digits

 
Rajesh Kumar Nait #:

1. search about bid ask and compare trade history again

2. check your ea. check if price being normalized in Digits

look for that 
Files:
wrong.png  5 kb
 
mohamed elsharkawey #:
look for that 
check the code of your ea. if you do not have the code, then, check with the author.
 
The deal history can tell you exactly what closed each trade. Call HistorySelect() for the period, then read DEAL_REASON on each closing deal: DEAL_REASON_TP means the server closed it at your take profit, DEAL_REASON_SL the stop loss, and DEAL_REASON_EXPERT means an EA sent a market close itself - if you see EXPERT there, the "random" prices come from your EA (or another EA/mobile app on the same account) closing at market, not from the TP. If the reason really is TP but the price looks off, remember buys close at Bid and sells at Ask: a sell TP triggers when Ask touches it, which on a chart (drawn from Bid) looks like it closed a spread-width away from your level - and gold spreads widen a lot around news. A TP can also fill at a worse price when the market gaps over it (weekend open, fast news candles), because it executes at the first available price after the gap. Finally, make sure the EA normalizes the TP to the symbol's Digits before sending the order.
 

Mobina's  DEAL_REASON  point is the right first move, and I'd make it concrete so you can settle this in one log line instead of guessing.

Two mechanisms produce a close price that is not your TP level, and neither is a bug:

  1. Side of the book. A long closes on the bid, a short closes on the ask. If you compare the fill to the ask on a long, or set the TP off the wrong side, the close looks off by roughly the spread even though it fired correctly.
  2. Gaps and fast fills. A TP is not a guaranteed limit at that exact price. When the bid (for a long) reaches the TP it becomes a market close, so on a gap or a fast tick the actual fill can print past the level. That is expected on volatile closes, not a wrong price.

To tell which one you have, capture the target while the position is still open and log it next to the real fill. In  OnTradeTransaction , on the closing deal, read  DEAL_PRICE  and  DEAL_REASON  and compare them to the  POSITION_TP  you stored while the trade was live:

  • DEAL_REASON_TP  with the price a hair off: spread or gap, normal.
  • DEAL_REASON  of  SL ,  SO  (stop out),  CLIENT ,  EXPERT  or  MOBILE : it was not your TP at all. Something else closed it, a margin stop-out, a manual or basket close, or the EA sending its own market order, and that is where the real cause is.

The one trap: read  POSITION_TP  while the position is still open. Once the position is gone you cannot read it off the position anymore, so if you only look afterward you have lost the exact number you are trying to compare against.