[Python] How to limit order requests - page 2

 
Patrick Muoka #:
do you have the full code i see if i can be of help
import MetaTrader5 as mt
import pandas as pd
import plotly.express as px
from datetime import datetime 

mt.initialize()

login=xxxxx
password=xxxxx
server=xxxx
mt.login(login,password,server)





while True:

        x=mt.symbol_info_tick("EURUSD").ask
        positions = mt.positions_get()
        num_positions=mt.positions_total()
        symbol_info=mt.symbol_info("EURUSD")
        symbol="EURUSD"
        volume=0.01
        price=mt.symbol_info_tick("EURUSD").ask
        y=(1.03010,     1.03020,        1.03030,        1.03040,        1.03050,        1.03060,        1.03070,        1.03080,        1.03090,        1.03100,        1.03110,        1.03120,        1.03130,        1.03140,        1.03150,..etc)



        if x in y :

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


                result=mt.order_send(request)
                print(result)

So, from mt.position_get() I would like to extract price_open, after that I would say if x in y and x != price_open.....do the request.
The idea is to avoid the same price. If you buy, let say,  on 5$ (x=ask price, 5$), then the price_open==5$.So, when the  first time x==5$ I send the request, but the second time x==5$ then the  price_open of the first trade ==5$, then if x==price_open there will be no trade(request), and like this I avoid that python buys at a same price each time of a loop.

If x==6$, and price_openof the first trade==5$. The new request will be sent. Because if x in y and x != price_open then the request will be sent.

 

Print the size of 'positions':

len(positions)
 
Vladimir Karputov #:

Print the size of 'positions':

Thank you.

Ok, what now? python still dont recognize position_open.

 
josip2247 # :

Thank you.

Ok, what now? python still dont recognize position_open.

What is 'position_open'? Please provide a link to the MQL5 documentation.

 
Vladimir Karputov #:

What is 'position_open'? Please provide a link to the MQL5 documentation.

First I m sorry it is not position_open but price_open.

I opened a position on MT5. Now i write mt5_positions_get and print(mt5_positions_get), and I get this (TradePosition(ticket=1100036586, time=1654202682, time_msc=1654202682900, time_update=1654202682, time_update_msc=1654202682900, type=0, magic=0, identifier=1100036586, reason=0, volume=0.01, price_open=1.07477, sl=0.0, tp=0.0, price_current=1.07457, swap=0.0, profit=-0.2, symbol='EURUSD', comment='', external_id=''),)


From that I need price_open=1.07477


Ty for  patience!