How to use RefreshRates() correctly? sometimes not working...

 

I wish to retrieve the close price of the previous bar for 12 pairs, at the appearance of each new bar on a 30min chart.

I have used RefreshRates() before retrieve the close price of previous bar, and even adding a 40 sec delay, but it seems like sometimes still getting non-updated because the calculated value can change if reload my EA.

My question is how to use RefreshRates() to retrieve the close price of the previous bar more reliably, or it is not meant for charts other than the one it is attached to? Is there other commands which can do the job better?

I have tried iMA but it gives the same unreliable results. I guess increasing the delay to 1 min or more may help, but it means my EA will lag too much.

Part of my code:

string PairList[12] = {"AUDUSD",
"EURAUD",
"EURCHF",
"EURGBP",
"EURJPY",
"EURUSD",
"GBPCHF",
"GBPJPY",
"GBPUSD",
"USDCAD",
"USDCHF",
"USDJPY"};

int cmin = Minute();
int csec = Seconds();

if(((cmin == 0) && (csec >=40)) || ((cmin == 1) && (csec < 40)) || ((cmin == 30) && (csec >=40)) || ((cmin == 31) && (csec < 40)))
{

for(int id=0; id<12; id++)
{
for(timecount=0; timecount<20000; timecount++)
{
RefreshRates();

Price[id] = iClose(PairList[id], TimeFrame, 1);

if(Price[id] <= 0)
Sleep(1);
else
break;
}
}

}

 

*default/attached chart/symbol+period

or it is not meant for charts other than the one it is attached to?

not meant for others - only chart code loaded onto.

*other chart/symbol+period

look at ArrayCopySeries()

look at error codes - loop with sleep until GetLastError()==0

but... i work on this at present and in tests have seen that terminal not always map lattest data.

i mean i do above calls/loopings and get for period=MN a Time Array[0] value with month time at start 2008

i increase sleep time or increase loops - can take long time.

you try with simple script that print out values - best way to 'be sure' you got ok code idea

*or look any call that needs series array 'data' and terminal got none - must ask server

even iTime(), even MarketInfo() u can force to have !=0 error code...

you gotta play - i find help not help all time in mql ;)

Reason: