I'm trying to write MQL5 code that submits a buy limit order but it always fails with "error buy stop (4756)". The code is:
The journal shows the values being sent:
failed buy stop 0.5 US30_SB at 35286.0 (35286.0) sl: 35186.0 tp: 35366.0 [Invalid request]
...and the current price is 34960
Anyone have any idea why this is failing?
The current price doesn't mean anything tell us instead: what are Ask and Bid and the time of the order (is the market open).
The current price doesn't mean anything tell us instead: what are Ask and Bid and the time of the order (is the market open).
I included the current price because I read that has to be lower than the order price for buy stop orders.
The market is open and bid = 34,978.8, ask = 34983.6
I'm trying to write MQL5 code that submits a buy limit order but it always fails with "error buy stop (4756)". The code is:
The journal shows the values being sent:
failed buy stop 0.5 US30_SB at 35286.0 (35286.0) sl: 35186.0 tp: 35366.0 [ Invalid request ]
...and the current price is 34960
Anyone have any idea why this is failing?
Take an example from the ( Trade Operation Types ) help and compare with your example.
#property description "Example of placing pending orders" #property script_show_inputs #define EXPERT_MAGIC 123456 // MagicNumber of the expert input ENUM_ORDER_TYPE orderType=ORDER_TYPE_BUY_LIMIT; // order type //+------------------------------------------------------------------+ //| Placing pending orders | //+------------------------------------------------------------------+ void OnStart() { //--- declare and initialize the trade request and result of trade request MqlTradeRequest request={}; MqlTradeResult result={}; //--- parameters to place a pending order request.action =TRADE_ACTION_PENDING; // type of trade operation request.symbol =Symbol(); // symbol request.volume =0.1; // volume of 0.1 lot request.deviation=2; // allowed deviation from the price request.magic =EXPERT_MAGIC; // MagicNumber of the order int offset = 50; // offset from the current price to place the order, in points double price; // order triggering price double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT); // value of point int digits=SymbolInfoInteger(_Symbol,SYMBOL_DIGITS); // number of decimal places (precision) //--- checking the type of operation if(orderType==ORDER_TYPE_BUY_LIMIT) { request.type =ORDER_TYPE_BUY_LIMIT; // order type price=SymbolInfoDouble(Symbol(),SYMBOL_ASK)-offset*point; // price for opening request.price =NormalizeDouble(price,digits); // normalized opening price } else if(orderType==ORDER_TYPE_SELL_LIMIT) { request.type =ORDER_TYPE_SELL_LIMIT; // order type price=SymbolInfoDouble(Symbol(),SYMBOL_ASK)+offset*point; // price for opening request.price =NormalizeDouble(price,digits); // normalized opening price } else if(orderType==ORDER_TYPE_BUY_STOP) { request.type =ORDER_TYPE_BUY_STOP; // order type price =SymbolInfoDouble(Symbol(),SYMBOL_ASK)+offset*point; // price for opening request.price=NormalizeDouble(price,digits); // normalized opening price } else if(orderType==ORDER_TYPE_SELL_STOP) { request.type =ORDER_TYPE_SELL_STOP; // order type price=SymbolInfoDouble(Symbol(),SYMBOL_ASK)-offset*point; // price for opening request.price =NormalizeDouble(price,digits); // normalized opening price } else Alert("This example is only for placing pending orders"); // if not pending order is selected //--- send the request if(!OrderSend(request,result)) PrintFormat("OrderSend error %d",GetLastError()); // if unable to send the request, output the error code //--- information about the operation PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order); } //+------------------------------------------------------------------+

- www.mql5.com
Take an example from the ( Trade Operation Types ) help and compare with your example.
Thanks Vladimir!
That helped. It's working now. It seemed to be the declaration and use of zero memory that I had wrong. I'm using the declaration as above now:
MqlTradeRequest request={}; MqlTradeResult result={};

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm trying to write MQL5 code that submits a buy limit order but it always fails with "error buy stop (4756)". The code is:
The journal shows the values being sent:
failed buy stop 0.5 US30_SB at 35286.0 (35286.0) sl: 35186.0 tp: 35366.0 [Invalid request]
...and the current price is 34960
Anyone have any idea why this is failing?