but it doesn't work
What that means exactly ?
Don't place such code in OnInit(), it will never work correctly.
What that means exactly ?
Don't place such code in OnInit(), it will never work correctly
Let's say I want to copy M1 and D1 data, and I attach the indicator to chart on M1 timeframe. when I run the code it will only copy M1 rates, and won't copy D1 rates. Basically, CopyRates function works properly only if used to copy rates at current timeframe.
Can you elaborate on why not in OnInit?
Thanks a alot,
Nima
Let's say I want to copy M1 and D1 data, and I attach the indicator to chart on M1 timeframe. when I run the code it will only copy M1 rates, and won't copy D1 rates. Basically, CopyRates function works properly only if used to copy rates at current timeframe.
Can you elaborate on why not in OnInit?
Thanks a alot,
Nima
CopyRates() works properly on any timeframe. But the timeseries may be updating or needing download, check the return code and error code in code of error.
There is a greater chance timeseries are not yet available in OnInit(). Use OnTimer() or OnCalculate() instead.
Just a little comment ...
Price Rates are the same on all time frames !!!.
Just a little comment ...
Price Rates are the same on all time frames !!!.
It's an old thread, I know, but someone may be reading it in future (like me now), and may get confused, so I will complement the information:
Price Rates are "the same" just for the last [the most recent] bar. Technically index[0] if ordered as AsSeries.
If you need rates from older bars (like Bar.index[1] or older) , they will be different for each timeframe you query them.
It's an old thread, I know, but someone may be reading it in future (like me now), and may get confused, so I will complement the information:
Price Rates are "the same" just for the last [the most recent] bar. Technically index[0] if ordered as AsSeries.
If you need rates from older bars (like Bar.index[1] or older) , they will be different for each timeframe you query them.
Hi,
I recently try to use metatrader5 in Jupyter Notebook using python .
When I use this code to copy rates, there are error that shown below:
utc_from = datetime(2017, 1, 5, tzinfo=timezone) utc_to = datetime(2019, 12, 27, hour = 23, minute=59, tzinfo=timezone) rates = mt5.copy_rates_range("EURUSD", mt5.TIMEFRAME_M1, utc_from, utc_to) print("Display obtained data 'as is'") counter=0 for rate in rates: counter+=1 if counter<=10: print(rate)
Then error occured :
TypeError Traceback (most recent call last) <ipython-input-10-5307ec9302f7> in <module> 2 print("Display obtained data 'as is'") 3 counter=0 ----> 4 for rate in rates: 5 counter+=1 6 if counter<=10: TypeError: 'NoneType' object is not iterable
This code working with Time Frame D1 and H1 (I have try it), but doesn't work with Time Frame M1.
Any solution for this? Thanks
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Guys,
I am trying to code an indicator for D1 charts, which uses M1 price/volume/spread/etc. data to calculate the indicator daily values. I use this code to copy rates:
but it doesn't work. For some reason I have to change chart timeframe inside the code to be able to read the rates:
However, this creates all sorts of further issues. For example, (this piece of code is placed in OnInit() section) it runs twice! and if I have opened a file it causes the second run to fail, and etc. Does any of you guys have any idea how to deal with this?
Thanks a lot,
Nima