MT5 on Python - 'No Money' error.

Damian Brady  

I’m in the process of learning how to use MT5 with python.


My demo account through the broker had a starting balance of £1,000, and it looks like this:

account_info=mt.account_info()

account_info


AccountInfo( trade_mode=0, leverage=1, limit_orders=200, margin_so_mode=0, trade_allowed=True, trade_expert=True, margin_mode=2, currency_digits=2, fifo_close=False, balance=1002.37, credit=0.0, profit=0.0, equity=1002.37, margin=0.0, margin_free=1002.37, margin_level=0.0, margin_so_call=100.0, margin_so_so=50.0, margin_initial=0.0, margin_maintenance=0.0, assets=0.0, liabilities=0.0, commission_blocked=0.0, currency='GBP', ...)


When I try to place an order with a volume of 0.01, the code and resulting output looks like this:


symbol="USDJPY"


# prepare the request

point=mt.symbol_info(symbol).point

request = {

"action": mt.TRADE_ACTION_DEAL,

"symbol": symbol,

"volume": 0.01,

"type": mt.ORDER_TYPE_BUY,

"price": mt.symbol_info_tick(symbol).ask,

"sl": mt.symbol_info_tick(symbol).ask-100*point,

"tp": mt.symbol_info_tick(symbol).ask+100*point,

"comment": "python script",

"type_time": mt.ORDER_TIME_GTC,

"type_filling": mt.ORDER_FILLING_IOC,

}

result = mt.order_send(request)


result


OrderSendResult(retcode=10009, deal=381890714, order=524025709, volume=0.01, price=150.764, bid=150.764, ask=150.764, comment='Request executed', request_id=1796337626, retcode_external=0, request=TradeRequest(action=1, magic=0, order=0, symbol='USDJPY', volume=0.01, price=150.764, stoplimit=0.0, sl=150.66400000000002, tp=150.864, deviation=0, type=0, type_filling=1, type_time=0, expiration=0, comment='python script', position=0, position_by=0))


However, when I try to place an order with a larger volume, I get the ‘no money’ error:


# prepare the request

point=mt.symbol_info(symbol).point

request = {

"action": mt.TRADE_ACTION_DEAL,

"symbol": symbol,

"volume": 0.02,

"type": mt.ORDER_TYPE_BUY,

"price": mt.symbol_info_tick(symbol).ask,

"sl": mt.symbol_info_tick(symbol).ask-100*point,

"tp": mt.symbol_info_tick(symbol).ask+100*point,

"comment": "python script",

"type_time": mt.ORDER_TIME_GTC,

"type_filling": mt.ORDER_FILLING_IOC,

}

result = mt.order_send(request)


result 


OrderSendResult(retcode=10019, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='No money', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=0, order=0, symbol='USDJPY', volume=0.02, price=150.82, stoplimit=0.0, sl=150.72, tp=150.92, deviation=0, type=0, type_filling=1, type_time=0, expiration=0, comment='python script', position=0, position_by=0))


What am I misunderstanding or doing wrong?  Is my balance too low, even for such a small order?  Do I need to add leverage?

It’s likely that I am overlooking something obvious, but I am new to this.


Any advice will be appreciated.


Thanks

Conor Mcnamara  

It's probably that you need to set the leverage

Reason: