Need help for using another timeframes data...

 

Hi,

I am trying to code an indicator which uses another timeframe for same symbol. I dont want to open this other timeframe's chart for updating its data. I am using ArrayCopyRates for that pupose. This indic should run for the FIRST time and then for only FIRST TICK of new bar of other timeframe. İ tried two ways but none of them worked correctly.

1st way:

ArrayCopyRates( newRates, Symbol(), timeframe );
int error = GetLastError();
while ( error != 0 ) {   
   ArrayCopyRates( newRates, Symbol(), timeframe );            
   error = GetLastError();
}

2nd way:

int copiedBars = 0;
copiedBars = ArrayCopyRates( newRates, Symbol(), timeframe );   
while ( copiedBars <= 0  ) { // also used ( copiedBars < 0 )   
   copiedBars = ArrayCopyRates( newRates, Symbol(), timeframe );    
}

I also tried combination of this two way, but result is same. I have encountered below situations ( for example we use daily as other timeframe ):

1- if there is NO history in history folder, two behaviours:

a) if indic is dragged and dropped on an open chart, works CORRECTLY.

b) if MT4 Terminal is newly opened or restarted with open chart which has the indic attached, Terminal LOCKS.

2- if there is OLD history in history folder, indic is calculated with WRONG data.

I could solve some above problems with checking if Terminal is connected to server or not. But this time new problems have come and indic is calculated with WRONG data, all data is 0, etc...

I also tried to check if there is any data in newRates[ 0 ][ 0 ] and newRates[ 1 ][ 0 ] and compare if newRates[ 0 ][ 0 ] has updated data according to TimeCurrent and alot of way... There may be mixed dates while downloading new data in 0 and 1 indexed array elements. I didnt look further.

Any suggestion is very appreciated.

Thank you very much.

 
Your not giving the terminal any time to get the history, you're in an infinite loop. If the history isn't available RETURN
 

to use other timeframe data use 'i' functions:

iTime

iClose,

Iopen, etc.

no need to copy arrays

Reason: