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

 
ckeiderling :

Hi All,


I hope you don't mind an English man here. Looking for some guidance after spending lots of time searching the web without success.

I am using the MetaTrader5 Python library after some inspiration from Maxiums articles. I have noticed a problem with memory handling.

When I make a Dataframe using mt5 lib the resultant dataframe works as expected. I have done this within a function that collects the ticks and then performs various analysis before outputting the manipulated df.

However, if I rerun the function that creates the DataFrame I have noticed that the memory is just keeping accumulating from the previous instance.

I get the same problem using mt5.copy_ticks_range () and mt5.copy_rates_range (). I have to reset the kernel in order to clear out the memory.

I get the same problem even after removing all code except the line creating the dataframe. For instance:

def vel (symbol, lookback, lookforward, start_date, end_date, quantile_size):

ticks = pd.DataFrame (mt5.copy_ticks_range (symbol, datetime (start_date.year, start_date.month, start_date.day), datetime (end_date.year, end_date.month, end_date.day), mt5.COPY_TICKS_ALL), columns = [ 'time', 'bid', 'ask', 'last', 'volume', 'time_msc', 'flags', 'volume_real'])

If I run this several times the memory usage goes up 27MiB each time:

Line # Mem usage Increment Line Contents =========================================== ======= 126.3 MiB 126.3 MiB def vel (symbol, lookback, lookforward, start_date, end_date, quantile_size): 153.3 MiB 26.9 MiB ticks = pd.DataFrame (mt5.copy_ticks_range (symbol, datetime (start_date.year, start_date .month, start_date.day), .


Line # Mem usage Increment Line Contents

If you want help debugging then you'll have to give a full MVCE. This snippet is not enough.

 
ckeiderling:

Hi All,


I hope you don't mind an English man here. Looking for some guidance after spending lots of time searching the web without success.

I am using the MetaTrader5 Python library after some inspiration from Maxiums articles. I have noticed a problem with memory handling.

When I make a Dataframe using mt5 lib the resultant dataframe works as expected. I have done this within a function that collects the ticks and then performs various analysis before outputting the manipulated df.

However, if I rerun the function that creates the DataFrame I have noticed that the memory is just keeping accumulating from the previous instance.

I get the same problem using mt5.copy_ticks_range () and mt5.copy_rates_range (). I have to reset the kernel in order to clear out the memory.

I get the same problem even after removing all code except the line creating the dataframe. For instance:

def vel (symbol, lookback, lookforward, start_date, end_date, quantile_size):

ticks = pd.DataFrame (mt5.copy_ticks_range (symbol, datetime (start_date.year, start_date.month, start_date.day), datetime (end_date.year, end_date.month, end_date.day), mt5.COPY_TICKS_ALL), columns = [ 'time', 'bid', 'ask', 'last', 'volume', 'time_msc', 'flags', 'volume_real'])

If I run this several times the memory usage goes up 27MiB each time:

Line # Mem usage Increment Line Contents ================================================== 126.3 MiB 126.3 MiB def vel (symbol, lookback, lookforward, start_date, end_date, quantile_size): 153.3 MiB 26.9 MiB ticks = pd.DataFrame (mt5.copy_ticks_range (symbol, datetime (start_date.year, start_date.month, start_date.day), .


Line # Mem usage Increment Line Contents

maybe you try to usehttps://docs.python.org/3/library/gc.html

https://stackabuse.com/basics-of-memory-management-in-python/

 

Hi all.
Started getting this error when trying to place an order viaMetaTrader5.Buy() / Sell():

order_open = mt5.Buy(symbol, volume)

File "C:\Python3.7.4\lib\site-packages\MetaTrader5\__init__.py", line 313, in Buy

if r.retcode != TRADE_RETCODE_REQUOTE and r.retcode != TRADE_RETCODE_PRICE_OFF:

AttributeError: 'NoneType' object has no attribute 'retcode'


Can you suggest how to correct it?

 
AxxelTrader:

Hello everyone.
Such an error began to appear when trying to place an order through MetaTrader5.Buy () / Sell ():

order_open = mt5.Buy(symbol, volume)

File "C:\Python3.7.4\lib\site-packages\MetaTrader5\__init__.py", line 313, in Buy

if r.retcode != TRADE_RETCODE_REQUOTE and r.retcode != TRADE_RETCODE_PRICE_OFF:

AttributeError: 'NoneType' object has no attribute 'retcode'


Can you tell me how to fix it?

r = mt5.Buy(...)
if r is None:
    print(mt5.last_error())
else:
    if r.retcode ...
 

Which build of the terminal do you use?

Have you updated to the beta version?

 
MetaQuotes:

Which build of the terminal do you use?

Have you updated to the beta version?

I updated to the latest - MetaTrader5 package version: 5.0.31

This error occurs both when using mt5.Buy(), mt5.Sell() and mt5.order_send(requests).

Also writes that there is no "retcode" attribute.

 
AxxelTrader:

I updated to the latest - MetaTrader5 package version: 5.0.31

This error occurs both when using mt5.Buy(), mt5.Sell() and mt5.order_send(requests) functions.

Also writes that there is no "retcode" attribute.

The question was about the terminal version.

 
Renat Fatkhullin:

The question was about the version of the terminal.

MT5 version: 5.00 build 2361 08 mar 2020

 
AxxelTrader:

MT5 version: 5.00 build 2361 08 mar 2020

Upgrade to the beta version, please.

New functions available in beta versions only.

 
Renat Fatkhullin:

Upgrade to the beta version, please.

New functions available in beta versions only.

Upgraded to version 2432.
But the error is still there...
Tried it on different brokers even...