Validation error - PositionModify

 

MQL5 validation gives me this result, does anyone know why or how can I correct it?

test on EURUSD, H1 (netting) 2019.05.03 10:00:00 failed instant sell 1.4 EURGBP at 0.85750, close # 6 buy 1.4 EURGBP 0.85734 [Modification failed due to order or position being close to market]

2019.06.05 03:00:00 failed instant sell 1 EURCHF at 1.11689, close # 19 buy 1 EURCHF 1.11563 [Modification failed due to order or position being close to market]

strategy tester report 14 total trades

---

It seems that the problem comes from the TP update, which would be these lines:

// OP_BUY
                  if(PosTP!=TP&&TP>NormalizeDouble(Bid+minStop*SPoint,SDigits)){
                     if(!trade.PositionModify(iTicket,PosSL,TP)){
                        Print("PositionModify error ",trade.ResultRetcode());
                        return;
                        }
                     break;
                     }
// OP_SELL
                  if(PosTP!=TP&&TP<NormalizeDouble(Ask-minStop*SPoint,SDigits)){
                     if(!trade.PositionModify(iTicket,PosSL,TP)){
                        Print("PositionModify error ",trade.ResultRetcode());
                        return;
                        }
                     break;
                     }
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
David Diez:

MQL5 validation gives me this result, does anyone know why or how can I correct it?

test on EURUSD, H1 (netting) 2019.05.03 10:00:00 failed instant sell 1.4 EURGBP at 0.85750, close # 6 buy 1.4 EURGBP 0.85734 [Modification failed due to order or position being close to market]

2019.06.05 03:00:00 failed instant sell 1 EURCHF at 1.11689, close # 19 buy 1 EURCHF 1.11563 [Modification failed due to order or position being close to market]

strategy tester report 14 total trades

---

It seems that the problem comes from the TP update, which would be these lines:

The checks a trading robot must pass before publication in the Market

The article contains all the steps that you must implement in your code.

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
 
Vladimir Karputov #:

The checks a trading robot must pass before publication in the Market

The article contains all the steps that you must implement in your code.

Following the article, runtime errors are expected to be printed through GetLastError (in this case ResultRetcode()). Already used but no solution.

 
David Diez # :

Following the article, runtime errors are expected to be printed through GetLastError (in this case ResultRetcode()). Already used but no solution.

Show your solution (show your FIXED solution). The code from the first post is useless, it will not pass a single check.

 
Vladimir Karputov #:

Show your solution (show your FIXED solution). The code from the first post is useless, it will not pass a single check.

Have not fixed, that's why I ask the community.

 
David Diez # :

Have not fixed, that's why I ask the community.

You must correct your code. And an example of all the checks is given in the article. Have you read the article?

 
Vladimir Karputov #:

You must correct your code. And an example of all the checks is given in the article. Have you read the article?

What's wrong in my code?

  • Buying is done at the Ask price — the TakeProfit and StopLoss levels must be at the distance of at least SYMBOL_TRADE_STOPS_LEVEL points from the Bid price.
  • Selling is done at the Bid price — the TakeProfit and StopLoss levels must be at the distance of at least SYMBOL_TRADE_STOPS_LEVEL points from the Ask price.
 
David Diez # :

What's wrong in my code?

There is no check for the proximity of the price to the freeze level. There is no check for closeness of the price to the stop level ... There is no level repeat check.

Please read the article. Is it really that hard to READ the article ???

 
Vladimir Karputov #:

There is no check for the proximity of the price to the freeze level. There is no check for closeness of the price to the stop level ...

Please read the article. Is it really that hard to READ the article ???

I think I know what's the mistake, will check and get back to this thread.

 
David Diez # :

There is a condition to modify stops, taking this (from the article) into account:

  • Buying  is done at the Ask price — the TakeProfit and StopLoss levels must be  at the distance of at least SYMBOL_TRADE_STOPS_LEVEL points from the Bid price.
  • Selling  is done at the Bid price — the TakeProfit and StopLoss levels must be  at the distance of at least SYMBOL_TRADE_STOPS_LEVEL points from the Ask price.

You DO NOT have these checks - you get an error

Modification failed due to order or position being close to market

Please STUDY the article. Please USE the code from the article. The validator does a lot of checks - and the validator immediately throws bad code into the trash.

 
David Diez :


By the way, you can take the ready-made code from the article An attempt at developing an EA constructor 

An attempt at developing an EA constructor
An attempt at developing an EA constructor
  • www.mql5.com
In this article, I offer my set of trading functions in the form of a ready-made EA. This method allows getting multiple trading strategies by simply adding indicators and changing inputs.