order_send failed, retcode=10027

 
Hello i am trying to open trade from Spyder IDE to metatrader5. When i run python script at MetaEditor to Metatrader5 terminal i resulted this error "order_send failed, retcode=10027". How to solve it? Python script simply open trade then colse it.
"
 
GHH_tug77 :
Hello i am trying to open trade from Spyder IDE to metatrader5. When i run python script at MetaEditor to Metatrader5 terminal i resulted this error " order_send failed, retcode=10027". 

Error 10027:

10027

TRADE_RETCODE_CLIENT_DISABLES_AT

Autotrading disabled by client terminal


You have been instructed several times to enable the AutoTrade button ( Algo Tradindg On).


GHH_tug77:
Python script simply open trade then colse it.

Yes, this is how the python ' order_send ' script works: it opens a position and closes it.

 
Vladimir Karputov:

Error 10027:

10027

TRADE_RETCODE_CLIENT_DISABLES_AT

Autotrading disabled by client terminal


You have been instructed several times to enable the AutoTrade button ( ).


Yes, this is how the python ' order_send ' script works: it opens a position and closes it.

This error is appearing when autotrade button is enabled.

 
Vladimir Karputov:

Error 10027:

10027

TRADE_RETCODE_CLIENT_DISABLES_AT

Autotrading disabled by client terminal


You have been instructed several times to enable the AutoTrade button ( ).


Yes, this is how the python ' order_send ' script works: it opens a position and closes it.

how to solve?

 
Vladimir Karputov:

Error 10027:

10027

TRADE_RETCODE_CLIENT_DISABLES_AT

Autotrading disabled by client terminal


You have been instructed several times to enable the AutoTrade button ( ).


Yes, this is how the python ' order_send ' script works: it opens a position and closes it.

If you can not help complete do not act to helping to me. My problem not solved completely!

 

Check the state of the button again and show the screenshot - no one believes in words here.

Second, connect to the MetaQuotes-Demo demo server and run the script.

And one more thing: you have NEVER shown your CODE. YOU HAVE NEVER SHOWED the log file. There are no telepaths here - you are required to: ALWAYS show your code and ALWAYS show a log file.

 

I have just DISABLED the Algo trading button (the button has become in the state Algo Tradindg Off) - and I immediately got error 10027.

Therefore, for the hundredth time I repeat: strictly follow where you press and think strongly about what you are doing - YOU BANCHED TRADING IN THE TERMINAL, YOU HAVE RETURNED THE BUTTON !!!

 
Vladimir Karputov:

Check the state of the button again and show the screenshot - no one believes in words here.

Second, connect to the MetaQuotes-Demo demo server and run the script.

And one more thing: you have NEVER shown your CODE. YOU HAVE NEVER SHOWED the log file. There are no telepaths here - you are required to: ALWAYS show your code and ALWAYS show a log file.

message is below:

2021.08.25 20:49:50.382 python_1 (USDJPY,H1) MetaTrader5 package author:  MetaQuotes Software Corp.
2021.08.25 20:49:50.382 python_1 (USDJPY,H1) MetaTrader5 package version:  5.0.35
2021.08.25 20:49:50.382 python_1 (USDJPY,H1) 1. order_send(): by USDJPY 0.1 lots at 109.974 with deviation=20 points
2021.08.25 20:49:50.382 python_1 (USDJPY,H1) 2. order_send failed, retcode=10027
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    retcode=10027
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    deal=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    order=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    volume=0.0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    price=0.0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    bid=0.0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    ask=0.0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    comment=AutoTrading disabled by client
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    request_id=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    retcode_external=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)    request=TradeRequest(action=1, magic=234000, order=0, symbol='USDJPY', volume=0.1, price=109.974, stoplimit=0.0, sl=109.87400000000001, tp=110.074, deviation=20, type=0, type_filling=2, type_time=0, expiration=0, comment='python script open', position=0, position_by=0)
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: action=1
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: magic=234000
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: order=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: symbol=USDJPY
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: volume=0.1
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: price=109.974
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: stoplimit=0.0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: sl=109.87400000000001
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: tp=110.074
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: deviation=20
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: type=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: type_filling=2
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: type_time=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: expiration=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: comment=python script open
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: position=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1)        traderequest: position_by=0
2021.08.25 20:49:50.382 python_1 (USDJPY,H1) shutdown() and quit


python script is below:

import time
import MetaTrader5 as mt5
 
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ", mt5.__author__)
print("MetaTrader5 package version: ", mt5.__version__)
 
# establish connection to the MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
 
# prepare the buy request structure
symbol = "USDJPY"
symbol_info = mt5.symbol_info(symbol)
if symbol_info is None:
    print(symbol, "not found, can not call order_check()")
    mt5.shutdown()
    quit()
 
# if the symbol is unavailable in MarketWatch, add it
if not symbol_info.visible:
    print(symbol, "is not visible, trying to switch on")
    if not mt5.symbol_select(symbol,True):
        print("symbol_select({}}) failed, exit",symbol)
        mt5.shutdown()
        quit()
 
lot = 0.1
point = mt5.symbol_info(symbol).point
price = mt5.symbol_info_tick(symbol).ask
deviation = 20
request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": lot,
    "type": mt5.ORDER_TYPE_BUY,
    "price": price,
    "sl": price - 100 * point,
    "tp": price + 100 * point,
    "deviation": deviation,
    "magic": 234000,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}
 
# send a trading request
result = mt5.order_send(request)
# check the execution result
print("1. order_send(): by {} {} lots at {} with deviation={} points".format(symbol,lot,price,deviation));
if result.retcode != mt5.TRADE_RETCODE_DONE:
    print("2. order_send failed, retcode={}".format(result.retcode))
    # request the result as a dictionary and display it element by element
    result_dict=result._asdict()
    for field in result_dict.keys():
        print("   {}={}".format(field,result_dict[field]))
        # if this is a trading request structure, display it element by element as well
        if field=="request":
            traderequest_dict=result_dict[field]._asdict()
            for tradereq_filed in traderequest_dict:
                print("       traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed]))
    print("shutdown() and quit")
    mt5.shutdown()
    quit()
 
print("2. order_send done, ", result)
print("   opened position with POSITION_TICKET={}".format(result.order))
print("   sleep 2 seconds before closing position #{}".format(result.order))
time.sleep(2)
# create a close request
position_id=result.order
price=mt5.symbol_info_tick(symbol).bid
deviation=20
request={
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": lot,
    "type": mt5.ORDER_TYPE_SELL,
    "position": position_id,
    "price": price,
    "deviation": deviation,
    "magic": 234000,
    "comment": "python script close",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}
# send a trading request
result=mt5.order_send(request)
# check the execution result
print("3. close position #{}: sell {} {} lots at {} with deviation={} points".format(position_id,symbol,lot,price,deviation));
if result.retcode != mt5.TRADE_RETCODE_DONE:
    print("4. order_send failed, retcode={}".format(result.retcode))
    print("   result",result)
else:
    print("4. position #{} closed, {}".format(position_id,result))
    # request the result as a dictionary and display it element by element
    result_dict=result._asdict()
    for field in result_dict.keys():
        print("   {}={}".format(field,result_dict[field]))
        # if this is a trading request structure, display it element by element as well
        if field=="request":
            traderequest_dict=result_dict[field]._asdict()
            for tradereq_filed in traderequest_dict:
                print("       traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed]))
 
# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()


auto trading button is enabled at attached picture.

How to solve problem bro?

Files:
ss_1.JPG  413 kb
 
GHH_tug77:

Thanks for the information. Connect to the MetaQuotes-Demo demo server and run the script

 
Vladimir Karputov:

Thanks for the information. Connect to the MetaQuotes-Demo demo server and run the script

What does it mean? How to do it in step by step? I do not fully understand it. My account is demo account.

 
GHH_tug77 :

What does it mean? How to do it in step by step? I do not fully understand it. My account is demo account .

Right click on the Accounts -> Open an Account:


and enter the server name 'MetaQuotes-Demo'


Reason: