MetaTrader 5 Python User Group - the summary - page 19

 
nicholi shen:

Where is the changelog?

1. Fixed numpy objects auto-deleting issue

2. Fixed Buy/Sell/Close scripts error handling (__init__.py)
 
Almaz:

1. Fixed numpy objects auto-deleting issue

2. Fixed Buy/Sell/Close scripts error handling (__init__.py)

Thanks!

 

One question on the copy_ticks_range output:

#copy_ticks_range
utc_from = datetime(2020, 1, 1, tzinfo=timezone)
utc_to = datetime(2021, 1, 1, tzinfo=timezone)
init_mql5()
ticks = mt5.copy_ticks_range(symbol, utc_from, utc_to, mt5.COPY_TICKS_ALL)
mt5.shutdown()
ticks_frame = pd.DataFrame(ticks)
ticks_frame['time']=pd.to_datetime(ticks_frame['time'], unit='s')
ticks_frame['time_msc']=pd.to_datetime(ticks_frame['time_msc'], unit='ms')
ticks_frame.set_index('time_msc')[['ask', 'bid']].plot(title='EURUSD ticks', figsize=(18,4))
print('Range: {}-{}'.format(ticks_frame.time_msc.min(), ticks_frame.time_msc.max()))
print('{} ticks loaded'.format(len(ticks_frame)))
print('Total volume: {}'.format(ticks_frame.volume.sum()))
print('Total volume_real: {}'.format(ticks_frame.volume_real.sum()))
print('Flags frequency:')
print(ticks_frame.flags.value_counts())
display(ticks_frame.head(2))
display(ticks_frame.tail(2))

The fields volume and volume_real are 0 for all ticks (I have selected COPY_TICKS_ALL). Is it because my broker history (the volume obtained from copy_rates_range correspond with the one in the Metatrader chart)? Also, what is the difference between these two fields?

On the the other hand, I was looking for the meaning of the four different flags that appear in the history without success. Is there any place where can I found such a meaning?

Thanks!

 
Manuel Sanchon:

One question on the copy_ticks_range output:

The fields volume and volume_real are 0 for all ticks (I have selected COPY_TICKS_ALL). Is it because my broker history (the volume obtained from copy_rates_range correspond with the one in the Metatrader chart)?

Read the Reference for MqlTick please. These fields are not ticks volume

The Structure for Returning Current Prices (MqlTick)

This is a structure for storing the latest prices of the symbol. It is designed for fast retrieval of the most requested information about current prices.

struct MqlTick
  {
   datetime     time;          // Time of the last prices update
   double       bid;           // Current Bid price
   double       ask;           // Current Ask price
   double       last;          // Price of the last deal (Last)
   ulong        volume;        // Volume for the current Last price
   long         time_msc;      // Time of a price last update in milliseconds
   uint         flags;         // Tick flags
   double       volume_real;   // Volume for the current Last price with greater accuracy
  };

The variable of the MqlTick type allows obtaining values of Ask, Bid, Last and Volume within a  single call of the SymbolInfoTick() function.

The parameters of each tick are filled in regardless of whether there are changes compared to the previous tick. Thus, it is possible to find out a correct price for any moment in the past without the need to search for previous values at the tick history. For example, even if only a Bid price changes during a tick arrival, the structure still contains other parameters as well, including the previous Ask price, volume, etc.

You can analyze the tick flags to find out what data have been changed exactly:

  • TICK_FLAG_BID –  tick has changed a Bid price
  • TICK_FLAG_ASK  – a tick has changed an Ask price
  • TICK_FLAG_LAST – a tick has changed the last deal price
  • TICK_FLAG_VOLUME – a tick has changed a volume
  • TICK_FLAG_BUY – a tick is a result of a buy deal
  • TICK_FLAG_SELL – a tick is a result of a sell deal


See also the TICK_FLAG enumeration.
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Price Data Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Price Data Structure
  • www.mql5.com
This is a structure for storing the latest prices of the symbol. It is designed for fast retrieval of the most requested information about current prices. The parameters of each tick are filled in regardless of whether there are changes compared to the previous tick. Thus, it is possible to find out a...
 
Rashid Umarov:

Read the Reference for MqlTick please. These fields are not ticks volume

See also the TICK_FLAG enumeration.

Thank you Rashid, I will take a look.

I am finishing to explore the  metatrader python doc. It is really useful!

I am able to execute market orders and manage them (modify sl/tp and close them).

Also I am able to put pending orders (buy/sell limit and buy/sell stop orders). However, I don't know how to find them (none of the available functions in the doc: positions_get, history_deals_get or history_order_get, contains such orders).

Is it possible to obtain them with a mt5 function? Or is it not possible yet? 

It would be useful, for instance, in order to delete all pending orders quickly...


With ther order number I am able to modify/delete it:

#Modify pending order
request = {
    "action": mt5.TRADE_ACTION_MODIFY,
    "order": position_id,
    "price": 1.09000,
    "sl": 1.08000,
    "tp": 1.10000
    }
result = mt5.order_send(request)
if result.retcode != mt5.TRADE_RETCODE_DONE:
    print("Position {} close failed, retcode={}".format(position_id, result.retcode))
else:
    print(result)  

#Delete pending order
request = {
        "action": mt5.TRADE_ACTION_REMOVE,
        "order": position_id,
    }
result = mt5.order_send(request)
if result.retcode != mt5.TRADE_RETCODE_DONE:
    print("Position {} close failed, retcode={}".format(position_id, result.retcode))
else:
    print(result)  

Thanks!

 
Manuel Sanchon:

Thank you Rashid, I will take a look.

I am finishing to explore the  metatrader python doc. It is really useful!

I am able to execute market orders and manage them (modify sl/tp and close them).

Also I am able to put pending orders (buy/sell limit and buy/sell stop orders). However, I don't know how to find them (none of the available functions in the doc: positions_get, history_deals_get or history_order_get, contains such orders).

Is it possible to obtain them with a mt5 function? Or is it not possible yet? 

It would be useful, for instance, in order to delete all pending orders quickly...


With ther order number I am able to modify/delete it:

Thanks!

You have to use orders get. Here is an example using pymt5adapter

import pymt5adapter as mta
from pymt5adapter.order import Order
from pymt5adapter.symbol import Symbol


def main():
    symbol = Symbol('EPM20')
    r = Order.as_buy_limit(symbol=symbol, price=symbol.ask - 1.0, volume=1.0).send()
    print(r)
    for order in mta.orders_get(symbol=symbol):
        print(order)
        r = Order.as_delete_pending(order).send()
        print(r)


if __name__ == '__main__':
    with mta.connected():
        main()
 

Thank you, Nicholi Shen!

 

hi

in python , I want to check market watch base on one indicator  and in this regard  I used ' copyrates_range ' , but sometime getting data from one symbol take more time and I don't want to wait and want to ignore that symbol , what can I do ?

thanks

Documentation on MQL5: Integration / MetaTrader for Python / copy_rates_range
Documentation on MQL5: Integration / MetaTrader for Python / copy_rates_range
  • www.mql5.com
# create 'datetime' objects in UTC time zone to avoid the implementation of a local time zone offset # get bars from USDJPY M5 within the interval of 2020.01.10 00:00 - 2020.01.11 13:00 in UTC time zone                  time     open     high      low    close  tick_volume  spread  real_volume...
 
Behrooz Basaeri:

hi

in python , I want to check market watch base on one indicator  and in this regard  I used ' copyrates_range ' , but sometime getting data from one symbol take more time and I don't want to wait and want to ignore that symbol , what can I do ?

thanks

You can't do much because the terminal blocks when it's downloading rate data from the trade server. Even if you use async, threading, multiprocessing, you still run into the issue of a blocked terminal on subsequent calls. You could spawn multiple processes connected to multiple terminals and use one worker to handle priority fast tasks and another to handle a queue of long running blocking requests. 

 

Forum on trading, automated trading systems and testing trading strategies

MetaTrader 5 Python User Group - how to use Python in Metatrader

Renat Fatkhullin , 07/20/2014 01:19

You can run the python program on charts like regular scripts. They can receive data and trade.

But not in the tester.


Reason: