Can not open trade from python at metatrader5.

 
Hello, first of all thank for helping my issue. I can not open trade from python at metatrader5. I used mt5.order_send(request) function for it but it can not work. I am confused it. If anyone solve it pls help. I reward you
 
GHH_tug77 :
Hello, first of all thank for helping my issue. I can not open trade from python at metatrader5. I used mt5.order_send(request) function for it but it can not work. I am confused it. If anyone solve it pls help. I reward you

Have you tried the example from the help? (MetaTrader for Python -> order_send )

 
Vladimir Karputov:

Have you tried the example from the help? (MetaTrader for Python -> order_send )

I tried from https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py. But it can not open trade. With these errors AttributeError: 'NoneType' object has no attribute 'retcode', AttributeError: 'NoneType' object has no attribute 'bid'. I am using Spyder. Python version is 3.8.5

 
GHH_tug77 :

I tried from  https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py. But it can not open trade. With these errors AttributeError: 'NoneType' object has no attribute 'retcode', AttributeError: 'NoneType' object has no attribute 'bid'. I am using Spyder. Python version is 3.8.5

I just ran this script. In the MetaTrader 5 terminal, I first enabled Auto trading - Algo Tradindg On, then moved the order_send script to the chart.

Result:

2021.08.23 17:55:44.063 Python  script order_send (EURAUD,H1) started successfully
2021.08.23 17:55:44.314 Trades  '39892627': instant buy 0.1 USDJPY at 109.738 sl: 109.638 tp: 109.838 (deviation: 20)
2021.08.23 17:55:44.386 Trades  '39892627': deal #1078625304 buy 0.1 USDJPY at 109.738 done (based on order #1095471398)
2021.08.23 17:55:44.387 Trades  '39892627': accepted instant buy 0.1 USDJPY at 109.738 sl: 109.638 tp: 109.838 (deviation: 20)
2021.08.23 17:55:44.407 Trades  '39892627': order #1095471398 buy 0.1 / 0.1 USDJPY at 109.738 done in 93.110 ms
2021.08.23 17:55:44.505 Trades  use Hosting Service to speed up the execution - 0.11 ms via 'MQL5 Amsterdam 02 (MQL5.community)' instead of 63.15 ms
2021.08.23 17:55:46.419 Trades  '39892627': instant sell 0.1 USDJPY at 109.733, close #1095471398 buy 0.1 USDJPY 109.738 (deviation: 20)
2021.08.23 17:55:46.494 Trades  '39892627': accepted instant sell 0.1 USDJPY at 109.733, close #1095471398 buy 0.1 USDJPY 109.738 (deviation: 20)
2021.08.23 17:55:46.502 Trades  '39892627': deal #1078625373 sell 0.1 USDJPY at 109.733 done (based on order #1095471465)
2021.08.23 17:55:46.503 Trades  '39892627': order #1095471465 sell 0.1 / 0.1 USDJPY at 109.733 done in 84.276 ms
2021.08.23 17:55:46.523 Python  script order_send (EURAUD,H1) removed
 
Vladimir Karputov:

I just ran this script. In the MetaTrader 5 terminal, I first enabled Auto trading - , then moved the order_send script to the chart.

Result:

How did you run it successfully? Pls explain it step by step with more detailed
 
Vladimir Karputov:

I just ran this script. In the MetaTrader 5 terminal, I first enabled Auto trading - , then moved the order_send script to the chart.

Result:

i want run it at python. but it can not work
 
GHH_tug77:
How did you run it successfully? Pls explain it step by step with more detailed

I showed my steps:

Forum on trading, automated trading systems and testing trading strategies

Can not open trade from python at metatrader5.

Vladimir Karputov, 2021.08.23 16:59

I just ran this script. In the MetaTrader 5 terminal, I first enabled Auto trading - Algo Tradindg On, then moved the order_send script to the chart.

Result:

2021.08.23 17:55:44.063 Python  script order_send (EURAUD,H1) started successfully
2021.08.23 17:55:44.314 Trades  '39892627': instant buy 0.1 USDJPY at 109.738 sl: 109.638 tp: 109.838 (deviation: 20)
2021.08.23 17:55:44.386 Trades  '39892627': deal #1078625304 buy 0.1 USDJPY at 109.738 done (based on order #1095471398)
2021.08.23 17:55:44.387 Trades  '39892627': accepted instant buy 0.1 USDJPY at 109.738 sl: 109.638 tp: 109.838 (deviation: 20)
2021.08.23 17:55:44.407 Trades  '39892627': order #1095471398 buy 0.1 / 0.1 USDJPY at 109.738 done in 93.110 ms
2021.08.23 17:55:44.505 Trades  use Hosting Service to speed up the execution - 0.11 ms via 'MQL5 Amsterdam 02 (MQL5.community)' instead of 63.15 ms
2021.08.23 17:55:46.419 Trades  '39892627': instant sell 0.1 USDJPY at 109.733, close #1095471398 buy 0.1 USDJPY 109.738 (deviation: 20)
2021.08.23 17:55:46.494 Trades  '39892627': accepted instant sell 0.1 USDJPY at 109.733, close #1095471398 buy 0.1 USDJPY 109.738 (deviation: 20)
2021.08.23 17:55:46.502 Trades  '39892627': deal #1078625373 sell 0.1 USDJPY at 109.733 done (based on order #1095471465)
2021.08.23 17:55:46.503 Trades  '39892627': order #1095471465 sell 0.1 / 0.1 USDJPY at 109.733 done in 84.276 ms
2021.08.23 17:55:46.523 Python  script order_send (EURAUD,H1) removed

 
Vladimir Karputov:

I showed my steps:


Run it at python not at metatrader5
 
GHH_tug77 :
Run it at python not at metatrader5

There is no difference. I have successfully executed the script in 'jupyter notebook'

MetaTrader5 package author:  MetaQuotes Software Corp.
MetaTrader5 package version:  5.0.34
1. order_send(): by USDJPY 0.1 lots at 109.832 with deviation=20 points
2. order_send done,  OrderSendResult(retcode=10009, deal=1079235630, order=1096075489, volume=0.1, price=109.832, bid=109.83, ask=109.832, comment='Request executed', request_id=21, retcode_external=0, request=TradeRequest(action=1, magic=234000, order=0, symbol='USDJPY', volume=0.1, price=109.832, stoplimit=0.0, sl=109.732, tp=109.93199999999999, deviation=20, type=0, type_filling=2, type_time=0, expiration=0, comment='python script open', position=0, position_by=0))
   opened position with POSITION_TICKET=1096075489
   sleep 2 seconds before closing position #1096075489
3. close position #1096075489: sell USDJPY 0.1 lots at 109.83 with deviation=20 points
4. position #1096075489 closed, OrderSendResult(retcode=10009, deal=1079235673, order=1096075530, volume=0.1, price=109.83, bid=109.83, ask=109.832, comment='Request executed', request_id=22, retcode_external=0, request=TradeRequest(action=1, magic=234000, order=0, symbol='USDJPY', volume=0.1, price=109.83, stoplimit=0.0, sl=0.0, tp=0.0, deviation=20, type=1, type_filling=2, type_time=0, expiration=0, comment='python script close', position=1096075489, position_by=0))
   retcode=10009
   deal=1079235673
   order=1096075530
   volume=0.1
   price=109.83
   bid=109.83
   ask=109.832
   comment=Request executed
   request_id=22
   retcode_external=0
   request=TradeRequest(action=1, magic=234000, order=0, symbol='USDJPY', volume=0.1, price=109.83, stoplimit=0.0, sl=0.0, tp=0.0, deviation=20, type=1, type_filling=2, type_time=0, expiration=0, comment='python script close', position=1096075489, position_by=0)
       traderequest: action=1
       traderequest: magic=234000
       traderequest: order=0
       traderequest: symbol=USDJPY
       traderequest: volume=0.1
       traderequest: price=109.83
       traderequest: stoplimit=0.0
       traderequest: sl=0.0
       traderequest: tp=0.0
       traderequest: deviation=20
       traderequest: type=1
       traderequest: type_filling=2
       traderequest: type_time=0
       traderequest: expiration=0
       traderequest: comment=python script close
       traderequest: position=1096075489
       traderequest: position_by=0
True
​
 
Vladimir Karputov:

There is no difference. I have successfully executed the script in 'jupyter notebook'

how to successfully execute the code? pls
 
Vladimir Karputov:

There is no difference. I have successfully executed the script in 'jupyter notebook'

psl help how to construct integration? How to connect with you social ?