'send_order' function not working

 

Hello,

I’m trying to use the ‘send_order’ function from the MT5 documentation but it doesn’t seem to be working. I keep getting the same return value from using the ‘send_order’ function with no success.


Here’s my code:

import MetaTrader5 as mt5


# Reinitialize outside of connectToServer function for testing purposes
if not mt5.initialize(path=path, login=login, password=password, server=serv):
    print("initialize() failed, error code =",mt5.last_error())
    quit()

def sendOrder(symbol, vol, buySell):

    if buySell.capitalize()[0] == "B":
        direction = mt5.ORDER_TYPE_BUY
        price = mt5.symbol_info_tick(symbol).ask
    else:
        direction = mt5.ORDER_TYPE_SELL
        price = mt5.symbol_info_tick(symbol).bid
    
    # Sepecifics of the order request
    request = {
        "action": mt5.TRADE_ACTION_DEAL,
        "symbol": symbol,
        "volume": vol,
        "type": direction,
        "price": price,
        "type_time": mt5.ORDER_TIME_GTC,
        "type_filling": mt5.ORDER_FILLING_RETURN,
    }

    # Send request and return answer
    result = mt5.order_send(request)

    return result

print('program started')
print(sendOrder("USDCAD",0.1,"BUY"))


Here’s my output:

program started

OrderSendResult(retcode=10027, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='AutoTrading disabled by client', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=0, order=0, symbol='USDCAD', volume=0.1, price=1.36429, stoplimit=0.0, sl=0.0, tp=0.0, deviation=0, type=0, type_filling=2, type_time=0, expiration=0, comment='', position=0, position_by=0))

From what I understand "retcode=10027" along with the " AutoTrading disabled by client" comment means it's disabled but I've enabled it and I think I turned on all the needed/possible Expert Advisor permissions as can be seen in the attached screenshots. 

The initialization was done properly from what I can tell as other functions such as 'positions_get', 'account_info', and 'copy_rates_from' are working. Something to add though is 'Close' wasn't working which is meant to close an active position but that may be because of another problem, I don't for sure. 

I’ve tried copy-pasting the entire documentation code demo to see if that worked but it threw the same error. I've messed around with the charts, seeing if that affects the function as documentation has an if-statement that checks if it's open. I've tried it with the chart being open and closed but both times gave the same output. 


Any help would be greatly appreciated, thank you!

Documentation on MQL5: Python Integration / copy_rates_from
Documentation on MQL5: Python Integration / copy_rates_from
  • www.mql5.com
Get bars from the MetaTrader 5 terminal starting from the specified date. Parameters symbol [in]  Financial instrument name, for example...
Files: