[Python] "None" return in a buy order in MT5 via Python

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to put a buy order but the result is "none". If I try to put the same order (same lot, SL,TP) directly in MT5 it goes well. Below the abstract code. I set "algo trading" in MT5. Can someone help me please?

    symbol = "NDA_CFD.DE"
    lot = 1.0
    tick = mt5.symbol_info_tick(symbol)

    buy_price = tick.ask
    sell_price = tick.bid
    point = mt5.symbol_info(symbol).point
    psl = 0.05
    ptp = 0.10
    buy_sl = buy_price*(1-psl)
    buy_tp = buy_price*(1+ptp)
    sell_sl = sell_price*(1+psl)
    sell_tp = sell_price*(1-ptp)
    deviation = 10
    print ('Ask price', tick.ask)
    ordine_acquisto = mt5.ORDER_TYPE_BUY
    ordine_vendita = mt5.ORDER_TYPE_SELL

    def crea_ordine (simbolo,quantita,tipo_ordine,prezzo,stop_loss,take_profit):
    request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": simbolo,
    "volume": quantita,
    "type": tipo_ordine,
    "price": prezzo,
    "sl": stop_loss,
    "tp": take_profit,
    "deviation": deviation,
    #"magic": 234000,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_IOC,
    #"position": mt5.positions_get()[0]._asdict()['ticket']
    }
    result = mt5.order_send(request)
    print(result)


    #Ordine di acquisto
    crea_ordine(tick,lot,ordine_acquisto,buy_price,buy_sl,buy_tp)

    Continue reading...

Compartilhe esta Página