Strange invalid stops problem when placing pending buy stop order

 

I'm confused with this problem. Below are the parameters and still I get the "invalid stops" error:

rates[i].close=1.29171 rates[i].close is the close of the bar at which I'm placing the pending buy stop order i.e. the current price.

request.price=1.29185 request.price is the price at which I'm placing the pending buy stop order.

request.tp=1.31175 request.tp is the target point of my pending buy stop order.

request.sl=1.28736 request.sl is the stop loss of my pending buy stop order.

As you can see the prices are correct, but regardless I get that error :(

Below is the code for the order placement:

            //int buffer=SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
            request.action=TRADE_ACTION_PENDING;
            request.price=buy_stop_price+10*_Point;
            //request.stoplimit=buy_stop_price;
            request.tp=buy_stop_price+TP*_Point*10;
            request.sl=sell_stop_price-SL*_Point*10;
            request.type=ORDER_TYPE_BUY_STOP;
            request.type_time=ORDER_TIME_GTC;
            request.expiration=ORDER_TIME_SPECIFIED;
            OrderSend(request,result);
           }
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
I just run into another problem related to this one. I was able to place pending sell stop orders using the same logic as above and am still left wondering why buy stops wont work. My problem now is that when I'm debugging my expert and see it placing pending sell stop orders just as it should and then when price goes through my sell stop order price it won't result in trade execution and my PositionsTotal() remains at zero. I can't understand why this happens. Must I code a separate piece for the execution of the pending order? I thought that it executes automatically when price trades through it. Below is the code I use to set the pending sell stop:
         if(OrdersTotal()==0)
           {
            request.symbol       =Symbol();
            request.volume       =Lots;
            request.deviation    =10000;
            request.type_filling =ORDER_FILLING_IOC;
            request.action       =TRADE_ACTION_PENDING;
            request.price        =sell_stop_price-10*_Point;
            //request.stoplimit    =sell_stop_price-10*_Point;
            request.tp           =sell_stop_price-TP*_Point*10;
            request.sl           =buy_stop_price+SL*_Point*10;
            request.type         =ORDER_TYPE_SELL_STOP;
            request.type_time    =ORDER_TIME_GTC;
            //request.expiration   =ORDER_TIME_SPECIFIED;
            
            OrderSend(request,result);
            ZeroMemory(request);
            
            old_buy_stop_price=buy_stop_price;
            old_sell_stop_price=sell_stop_price;            
           }
 
I think I got it solved I had something fundamentally wrong with my EA :) All should be well now.

 
The open price of pending should far beyond STOP_LEVEL and/or FREEZE_LEVEL from the current Bid/Ask price
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 

Yeah, that's true, but I tried placing it very far e.g. 100 pips away from the current price but still got the same error. But like a said I had something else fundamentally wrong in my EA and after fixing it I believe it works OK.

Thanks!

Br, Candles

EDIT:

As expected it works perfectly now :)

 
Candles:

Yeah, that's true, but I tried placing it very far e.g. 100 pips away from the current price but still got the same error. But like a said I had something else fundamentally wrong in my EA and after fixing it I believe it works OK.

Thanks!

Br, Candles

EDIT:

As expected it works perfectly now :)

Congrats :)