簡體   English   中英

如何在調用OrderModify()函數時修復錯誤4059。 MQL4?

[英]How to repair an Error 4059 on calling the OrderModify() function | MQL4?

我的EA出現錯誤代碼4059
意思是
(回退)測試中顯然不允許使用OrderModify()函數。

有什么辦法可以允許這樣做嗎?

我想要做的就是將頭寸改變為盈虧平衡,當它獲得100點的“好”

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;
}

4059 ERR_FUNC_NOT_ALLOWED_IN_TESTING
清楚了,
不是它的來源
雖然

測試模式下不允許使用此功能
[ HIDDEN REMAINS _WHERE_ + _WHY_ IT IS REPORTED] :)

所以,
修改有關錯誤檢測的一些細節
以便回到騎乘馬鞍,並在您的完全控制下將東西取回:

 .
 ..
 ...
 // ======================================== .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 )
 ...
 ..
 .

使用類似的系統化方法進行錯誤檢測,您將很快意識到所觀察到的問題的根本原因,並且任何錯誤處理都將開始變得有意義。

最可能的是,錯誤起源幾SLOC你的下-s較低, OrderModify()調用,其中SendMail()調用出現,盡管事實上,它有助於明確地說:


Note

在設置中可以禁止發送,也可以省略電子郵件地址。 有關錯誤信息,請調用GetLastError()

SendMail()函數在Strategy Tester中不起作用。

OrderModify() 不會生成錯誤4059
該錯誤來自SendMail() 文檔指出:
https://docs.mql4.com/common/sendmail

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM