[Python] How to limit order requests

 

Hello,

I'm trying to automate trade Eurusd but I can't figure out how to limit order requests.

When the program recognize "price in y", it buys as much as possible but i would like that it buys just once.

Here is the code 

symbol="EURUSD"
volume=0.01
price=mt.symbol_info_tick("EURUSD").ask
y=(1.07760,1.07750..etc)


While True:

        if price in y :

                request = { 
                            "action": mt.TRADE_ACTION_DEAL, 
                            "symbol":"EURUSD", 
                            "volume":volume, 
                            "type":mt.ORDER_TYPE_BUY,            
                            "price":price,
                            "sl":price-0.0002,
                            "tp":0.00, 
                            "deviation":0,
                            "type_time": mt.ORDER_TIME_GTC,
                            "Type_filling":mt.ORDER_FILLING_IOC,
                }


                result=mt.order_send(request)
                print(result)
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Check out the MetaTrader for Python Documentation section. Especially this:

positions_total

Get the number of open positions

positions_get

Get open positions with the ability to filter by symbol or ticket

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

Check out the MetaTrader for Python Documentation section. Especially this:

positions_total

Get the number of open positions

positions_get

Get open positions with the ability to filter by symbol or ticket

I tried this, but don't know how to get data from positions get.

The idea was if x==open position ( the open price for a position from position get() ), the request wouldn't be sent , and that would resolve my problem, but don't know how to do it. 

 
josip2247 # :

I tried this, but don't know how to get data from positions get.

The idea was if x==open position ( the open price for a position from position get() ), the request wouldn't be sent , and that would resolve my problem, but don't know how to do it. 

You need to learn MQL5 first. MQL5 is a terminal language. This is the basis, the foundation. Only those who know MQL5 can work with MQL5+Python.

If you don't know the basics, no Python will help you.

 
josip2247 # :


Do you want to learn MQL5?

 

Maybe later, but now I need smb who know it already to resolve my problem. To get data from position_get(), the price open.

(TradePosition(ticket=1099780544, time=1653942214, time_msc=1653942214521, time_update=1653942214, time_update_msc=1653942214521, type=0, magic=0, reason=0, volume=0.01, price_open=1.07839, sl=0.0, tp=0.0, price_current=1.07831, swap=0.0, profit=-0.08, symbol='EURUSD', comment='', external_id=''),)

 
josip2247 # :

Maybe later, but now I need smb who know it already to resolve my problem. To get data from position_get(), the price open.

(TradePosition(ticket=1099780544, time=1653942214, time_msc=1653942214521, time_update=1653942214, time_update_msc=1653942214521, type=0, magic=0, reason=0, volume=0.01, price_open=1.07839 , sl=0.0, tp=0.0, price_current=1.07831, swap=0.0, profit=-0.08, symbol='EURUSD', comment='', external_id=''),)

You need to read and study the documentation: MetaTrader for Python .

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
The documentation ( positions_get ) has a very good example.
Documentation on MQL5: Integration / MetaTrader for Python / positions_get
Documentation on MQL5: Integration / MetaTrader for Python / positions_get
  • www.mql5.com
positions_get - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:
The documentation ( positions_get ) has a very good example.

Thank you, but how can I take the open_position data. To define it.

With position_get i get the data, but from that data i want to use only open_position. So I can use it with other variables. To select it so the program know what it is.

So I can write if x==open_position don't trade.



   

 
josip2247 #:

Thank you, but how can I take the open_position data. To define it.

With position_get i get the data, but from that data i want to use only open_position. So I can use it with other variables. To select it so the program know what it is.

So I can write if x==open_position don't trade.



   

do you have the full code i see if i can be of help
 
josip2247 #:

Thank you, but how can I take the open_position data. To define it.

With position_get i get the data, but from that data i want to use only open_position. So I can use it with other variables. To select it so the program know what it is.

So I can write if x==open_position don't trade.



   

I think what @Vladimir Karputov is trying to say is: First, can you do that with MQL5 first? You're asking a very simple and basic problem. It would not take you more than 5 minutes to figure it out going through the documentation (position_get)
Documentation on MQL5: Integration / MetaTrader for Python / positions_get
Documentation on MQL5: Integration / MetaTrader for Python / positions_get
  • www.mql5.com
positions_get - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: