How to close active order with Pyhon application?

 

plz, who know about - write example of these ... It's my current setting, but it's only for pending orders ... 

                request = {
                    "action": mt5. TRADE_ACTION_REMOVE,
                    "position": Order.ticket, # result from mt5.positions_get(group="*"), I was check it - true values of ticket here
                    #"symbol": Symbol,
                    #"deviation": 5,
                    #"magic": 234000,
                    #"type_time": mt5.ORDER_TIME_GTC,
                    #"type_filling": mt5.ORDER_FILLING_IOC,
                }
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trade Operation Types - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

1.  Please insert the code correctly: when editing a message, press the button  Code and paste your code into the pop-up window 

2. Read the examples from the documentation: order_send 

Documentation on MQL5: Integration / MetaTrader for Python / order_send
Documentation on MQL5: Integration / MetaTrader for Python / order_send
  • www.mql5.com
order_send - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

1.  Please insert the code correctly: when editing a message, press the button   and paste your code into the pop-up window 

2. Read the examples from the documentation: order_send 

Thank, I'm using these settings, that equal to my active Order (I was get them from the result of positions_get() function):

                    "action": mt5.TRADE_ACTION_DEAL,
                    "symbol": Symbol,
                    "volume": Order.volume,
                    "type": mt5.ORDER_TYPE_BUY,
                    "position": Order.ticket,
                    "price": Order.price_current,
                    "deviation": 5,
                    "magic": 234000,
                    "comment": "python script close",
                    "type_time": mt5.ORDER_TIME_GTC,
                    "type_filling": mt5.ORDER_FILLING_RETURN,

But get retcode=10013

Request data:

request=TradeRequest(
action=1, 
magic=234000, 
order=0, 
symbol='GBPSGD', 
volume=0.01, 
price=1.79088, 
stoplimit=0.0, 
sl=0.0, tp=0.0, 
deviation=5, 
type=0, 
type_filling=2, 
type_time=0, 
expiration=0, 
comment='python script close', 
position=242265476, 
position_by=0
)
 

I was get equal retcode=10013 within:

price=mt5.symbol_info_tick(Symbol).bid

nothing changes

I not understand how it's works ...
 
sergey087 # :

I was get equal  retcode=10013 within:


nothing changes

I not understand how it's works ...

Compare your code and the code from the documentation:

your code
documentation
price=mt5.symbol_info_tick(Symbol).bid


price=mt5.symbol_info_tick(symbol).bid

 
Vladimir Karputov #:

Compare your code and the code from the documentation:

your code
documentation



oh, it's only my variable name ... 

Can you show your workers code? Important only config data
 

wow, it's works ... But need use "type" = ORDER_TYPE_SELL for "BUY" orders ... Need to set mirror value of really order


                    "action": mt5.TRADE_ACTION_DEAL,
                    "symbol": Symbol,
                    "volume": Order.volume,
                    "type": mt5.ORDER_TYPE_SELL,
                    "position": Order.ticket,
                    "price": Order.price_current, #mt5.symbol_info_tick(Symbol).bid
                    "deviation": 20,
                    "magic": 234000,
                    "type_time": mt5.ORDER_TIME_GTC,
                    "type_filling": mt5.ORDER_FILLING_IOC,

 
sergey087 # :

wow, it's works ... But need use "type" = ORDER_TYPE_SELL for "BUY" orders ... Need to set mirror value of really order


I told you - take an example from the documentation :) . But you decided to go your own way - by trial and error :)

Reason: