indicator using data from different time frame possible? Please help.

 

After some time and frustration I have discovered that the compiler/terminal will not display the custom indicator if the buffer is calculated with data from another time frame. For example, displaying the daily ATR even when I am looking at the hourly chart. The first line below will work, but the second won't. There's no error and calculations come out right when tested with Print(). The terminal will simply not draw the indicator. Is there any way around this?

AtrBuffer[i]=iATR( Symbol(), PERIOD_CURRENT, x, rates_total-i-1 );

AtrBuffer[i]=iATR( Symbol(), InputTimeFrame, x, rates_total-iBarShift(Symbol(), InpTimeFrame, time[i])-1 );
 

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

 
skatt:

After some time and frustration I have discovered that the compiler/terminal will not display the custom indicator if the buffer is calculated with data from another time frame. For example, displaying the daily ATR even when I am looking at the hourly chart. The first line below will work, but the second won't. There's no error and calculations come out right when tested with Print(). The terminal will simply not draw the indicator. Is there any way around this?


Do you really want to draw it in reversed order (unless you are playing with ArraySetAsSeries, which you don't show) ?
AtrBuffer[i]=iATR( Symbol(), PERIOD_CURRENT, x, rates_total-i-1 );                 

Mix of indexing ?

AtrBuffer[i]=iATR( Symbol(), InputTimeFrame, x, rates_total-iBarShift(Symbol(), InpTimeFrame, time[i])-1 );
 

You are finding the bar shift of a particular time in another timeframe and then deducting it from the amount of bars in the chart timeframe. That doesn't make sense

AtrBuffer[i]=iATR( Symbol(), InputTimeFrame, x, rates_total-iBarShift(Symbol(), InpTimeFrame, time[i])-1 );

I'm not sure, but don't you just need

AtrBuffer[i]=iATR( Symbol(), InputTimeFrame, x,iBarShift(Symbol(), InpTimeFrame, time[i]) );

I find your method a bit confusing

 
I'm pretty sure that part of it is correct, as I've tested the numbers. My indicator buffer indexes in chronological order (same as the sample ATR indicator's buffer), but iATR goes in reverse, hence the total-i-1. Perhaps it might be less confusing if both went in reverse order, but that's not what I'm having trouble with. I'm looking for a way to use data from another time frame for the indicator without rewriting another indicator inside my own.
 

It'd probably be less confusing if i'd included this in my comment as well:

   ArraySetAsSeries(AtrBuffer,false);
   ArraySetAsSeries(time,false);
 
skatt:
I'm pretty sure that part of it is correct, as I've tested the numbers. My indicator buffer indexes in chronological order (same as the sample ATR indicator's buffer), but iATR goes in reverse, hence the total-i-1. Perhaps it might be less confusing if both went in reverse order, but that's not what I'm having trouble with. I'm looking for a way to use data from another time frame for the indicator without rewriting another indicator inside my own.


Well I think that both iBarShift and iATR work on series arrays

So, if time[i] returns Barshift 5 in the other time-frame, you need to use 5 as the shift in iATR

I must admit that I simply don't bother with the new arrays in OnCalculate. I don't see the point, especially as they are not available to functions unless passed by reference and not available at all in EAs and scripts.

 
GumRai:


Well I think that both iBarShift and iATR work on series arrays

So, if time[i] returns Barshift 5 in the other time-frame, you need to use 5 as the shift in iATR

This is exactly what I pointed.