Invalid Stops

 

Hi


I have this order to sell


def open_trade_sell2(action, symbol, lot, tp, deviation, ea_magic_number,comment):
                    '''https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py
                    '''
                    # prepare the buy request structure
                    symbol_info = get_info(symbol)
                    print("symbol info",symbol_info)

                    #symbol_info_tick_dict = mt5.symbol_info_tick(symbol)._asdict()
                    #for prop in symbol_info_tick_dict:
                    #        print("  {}={}".format(prop, symbol_info_tick_dict[prop]))
                   
                    if not mt5.initialize():
                        print("initialize() failed, error code =",mt5.last_error())
                        quit()
                    # display the last GBPUSD tick
                    lasttick=mt5.symbol_info_tick(symbol)
                    print(lasttick)

                    if action == 'buy':
                        trade_type = mt5.ORDER_TYPE_BUY
                        price = mt5.symbol_info_tick(symbol).ask
                        pass
                    elif action =='sell':
                        trade_type = mt5.ORDER_TYPE_SELL
                        
                        price = mt5.symbol_info_tick(symbol).bid
                        print(price)
                        pass
                    #point = mt5.symbol_info(symbol).point
                    if tp< price:
                        print("el precio mt5 es:", price)
                        tp=str(tp)
                        tp=tp[:8]
                        tp=float(tp)
                        now = time.time()
                        if comment == "5min":
                           el_tiempo = int(now + 300)
                        if comment == "15min":
                           el_tiempo = int(now + 900)
                        if comment == "30min":
                           el_tiempo = int(now + 1800)
                        if comment == "1hour":
                           el_tiempo = int(now + 3600)

                        buy_request = {
                            "action": mt5.TRADE_ACTION_DEAL,
                            "symbol": symbol,
                            "volume": lot,
                            "type": trade_type,
                            "price": price,
                            "sl": price + (price -tp),
                            "tp": tp,
                            "deviation": deviation,
                            "magic": ea_magic_number,
                            "comment": comment,
                            "type_time": mt5.ORDER_TIME_SPECIFIED , # good till cancelled
                            "expiration": el_tiempo,
                            "type_filling": mt5.ORDER_FILLING_IOC,
                        }
                        # send a trading request
                        result = mt5.order_send(buy_request)       
                        print("¿orden enviada?")    
                        print("resultado de la orden", result)  
                    else:
                        print("no puede vender")
                        result = "no posible comprar"
                        buy_request = "no posible comprar nene"
                    return result, buy_request 


but for some reason I don't know, the orders are never done. This is the message:


OrderSendResult(retcode=10016, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='Invalid stops', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=4494609, order=0, symbol='EURCHF', volume=0.1, price=0.97846, stoplimit=0.0, sl=0.978479, tp=0.978441, deviation=100, type=1, type_filling=1, type_time=2, expiration=1682463619, comment='1hour', position=0, position_by=0))

it comments: invalid stops, but when looking the sl and tp, they are ok .... whats happening here?

 

When asking for help on a forum, you should at least answer the ones trying to help you.

https://www.mql5.com/en/forum/446051

python order breaks ... don't know why??? please help
python order breaks ... don't know why??? please help
  • 2023.04.22
  • www.mql5.com
hi I'm using this order: and, when it does an order at the first time...
 
Alain Verleyen #:

When asking for help on a forum, you should at least answer the ones trying to help you.

https://www.mql5.com/en/forum/446051

hi


I get this error:


symbol_info_tick() failed, error code = (1, 'Success')

but the order has not been done???


edited:


some sells where made ... but they are not closing in the that time? Am I using correctly the timestamp? (couldn't get the errors when the orders passed.

and the error when the order is not made is the success one.

 

Invalid stops is a recurrent error, very often discussed on this forum. You can search and learn about it, then apply the same logic to your python code.

You should start to print the values you are using (price, sl, tp) then check they match the rules about stops.

Reason: