Order Sent Failed with Error #130

孤者浪人 提交于 2019-12-24 15:03:47

问题


I'm trying to insert a takeprofit and stoploss argument in my SendOrder() function, but I'm getting the following error:

Order Sent Failed with Error #130

This is my code:

extern double takeprofit = 30.0;
extern double stoploss   = 20.0;

stoploss   = NormalizeDouble( stoploss,   5 );                  // SET stop loss
Print( "stoploss", stoploss );

takeprofit = NormalizeDouble( takeprofit, 5 );                  // SET take profit

ticket     = OrderSend( Symbol(),
                        OP_SELL,
                        lotsize,
                        Ask,
                        100,
                        stoploss,
                        takeprofit,
                        0,
                        0,
                        0,
                        CLR_NONE
                        );
if (  ticket < 0 ) {
      Print( "Order send failed with error #", GetLastError() );
   }
else  Print( "Order send sucesso!!" );

I already checked documentation for the function NormalizeDouble(), but I'm still getting the error.

What should I do?


回答1:


A ) Fully comply with the MQL4 OrderSend() syntax requirements

int    anOrderTKT;                                // DECLARE int
double anOrderLotSIZE;                            // DECLARE double
string anOrderCommentSTRING;                      // DECLARE string

anOrderTKT = OrderSend( _Symbol,                  // CPU-glitch, is faster than calling Symbol(),
                        OP_SELL,                  // XTO.Type
                        anOrderLotSIZE,           // XTO.Size       [LT]s
                        Bid,                      // XTO.EntryPRICE { OP_BUY: Ask | OP_SELL: Bid }
                        100,                      // XTO.SLIPPAGE   [PT]s
                        0,                        // XTO.SL_PRICE
                        0,                        // XTO.TP_PRICE,
                        anOrderCommentSTRING,     // XTO.Comment
                        0,                        // XTO.MagNUM#
                        0,                        // XTO.PendingOrderEXPIRE
                        CLR_NONE                  // GUI.MarkerCOLOR
                        );                        // ==> { EMPTY | aTkt# }

Your code fails at setting a correct SHORT trade Entry-Price, as it shall read rather Bid, not Ask ( this error is hidden as it is effectively masked-out by a rather cosmic distance of 100 points in a tolerable slippage distance from the said price ).

Your code fails at assigning int ( 0 ) in place, where string is expected.

B) Error 130: == "invalid stops"

You shall verify with your Broker a few details:

  1. Does their Terms & Conditions allow to OrderSend() one-stop-instruction, incl, TP & SL, or does the Broker T&C require to first open a trade-position & only after that happens to allow an OrderModify() instruction to setup TP & SL price-levels?
  2. In either case, check your Broker T&C settings for STOPLEVEL & FREEZELEVEL distances, within which Broker rejects any TP & SL setup(s) or modification(s) thereof.

C) A good practice is not to assign into extern iterator-variables

While this is not a root-cause for your trouble, do get accustomed with an industry best practices, one of which is not to assign any value to a declared extern. Rather declare your own variable, that you control scope & assignments thereof, but leave extern(s) un-touched from your code side.



来源:https://stackoverflow.com/questions/26331310/order-sent-failed-with-error-130

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!