0

My EA comes up with an error code of 4059
which means
that the OrderModify() function is apparently not allowed in (back) testing.

Is there any way in which this could be allowed at all?

All I'm wanting to do is change the position to breakeven, when it gets 100 pips "to the good"

PrintFormat( "TKT[%.2d]OP:[%7.5f]SL:[%7.5f]CurrentPrice:[%7.5f]Stoplevel:[%.3d]FreezeLevel:[%.3d]",
              aTicket,
              anOpenPrice,
              aCurrentSL,
              anAskPrice,
              stopLevel,
              freezeLevel
              );
SellMod = OrderModify( aTicket,
                       NormalizeDouble( anOpenPrice, Digits ),
                       NormalizeDouble( aNewSLPrice, Digits ),
                       NormalizeDouble( aNewTpPrice, Digits ),
                       0,
                       sellcolor
                       );
SendMail( "Notification of Order Modification for Ticket#"
         + IntegerToString( OrderTicket(), 10 ),
           "Good news! Order Ticket#"
         + IntegerToString( OrderTicket(), 10 )
         + "has been changed to breakeven"
           );
if (  !SellMod )
{     PrintFormat( "Order modification for ticket %10d has failed modify the order under the Error Code# %5d. Check MQL4 Documentation",
                   aTicket,
                   GetLastError()
                   );
      result = false;
}
user3666197
  • 1
  • 6
  • 50
  • 92

2 Answers2

0

4059 ERR_FUNC_NOT_ALLOWED_IN_TESTING
is clear,
not the source of it
though

Function is not allowed in testing mode
[ HIDDEN REMAINS _WHERE_ + _WHY_ IT IS REPORTED] :)

So,
modify a few details on Error-Detection
so as to get back to the riding saddle and to get the things back under your full control:

 .
 ..
 ...
 // ======================================== .ASSUME NOTHING       ; the best
 //                                                                      advice
 //                                                                      ever :)
 //                //     ALWAYS (pre-clear) 
 GetLastError();   /* _ _ _ _ _ _ _ _ _ _ _  AND   ERR_SYSREG, 0   ; CLEAR SYSREG
                                                                   ; (
                                                                   ; prevents 
                                                                   ; from reading
                                                                   ; a value from
                                                                   ; some "old"
                                                                   ; error-code
                                                                   ; on a "next"
                                                                   ; GetLastError
                                                                   ; call
                                                                   ; )
                   */
 OrderModify(...); //                        CALL  _OrderModify

 gotLastERROR =    //                        MOV   VAR, ERR_SYSREG ; CATCH ERR
 GetLastError();   // _ _ _ _ _ _ _ _ _ _ _  AND   ERR_SYSREG, 0   ; CLEAR SYSREG

 // ---------------------------------------- ( a main-effect )
 //                                          ( VAR has this _FUN call error-code )

 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ( a side-effect )
 //                                          ( ERR_SYSREG is clear AGAIN )
 ...
 ..
 .

With a similarly systematic approach to Error-Detection you will soon realise the root cause of the observed problem and any Error-Handling will only start to have sense.

Most probably, the error originates a few SLOC-s lower, under your OrderModify() call, where SendMail() call appears, in spite of the fact, that HELP explicitly says:


Note

Sending can be prohibited in settings, email address can be omitted as well. For the error information call GetLastError().

SendMail() function does not work in the Strategy Tester.

user3666197
  • 1
  • 6
  • 50
  • 92
0

OrderModify() does NOT generate error 4059.
That error comes from SendMail(). Documentation states that:
https://docs.mql4.com/common/sendmail

user3666197
  • 1
  • 6
  • 50
  • 92
jlee88my
  • 2,935
  • 21
  • 28
  • Exactly, Joseph Lee, you might have noticed, that the May 4th post has stated that already altogether with some didactic reasoning around this root-cause. – user3666197 May 17 '16 at 20:30