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:
MqlRates RatesM1[],RatesD1[];
datetime first_bar_date=SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_FIRSTDATE);
datetime last_bar_date=SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_LASTBAR_DATE);
ArraySetAsSeries(RatesM1,true);
ArraySetAsSeries(RatesD1,true);
int CopyRatesM1Check=CopyRates(_Symbol,PERIOD_M1,first_bar_date,last_bar_date,RatesM1);
int CopyRatesD1Check=CopyRates(_Symbol,PERIOD_D1,first_bar_date,last_bar_date,RatesD1);
but it doesn’t work. For some reason I have to change chart timeframe inside the code to be able to read the rates:
MqlRates RatesM1[],RatesD1[];
datetime first_bar_date=SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_FIRSTDATE);
datetime last_bar_date=SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_LASTBAR_DATE);
ArraySetAsSeries(RatesM1,true);
ArraySetAsSeries(RatesD1,true);
int CopyRatesM1Check=CopyRates(_Symbol,PERIOD_M1,first_bar_date,last_bar_date,RatesM1);
ChartSetSymbolPeriod(0,_Symbol,PERIOD_D1);
int CopyRatesD1Check=CopyRates(_Symbol,PERIOD_D1,first_bar_date,last_bar_date,RatesD1);
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,