Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
skatt
186
skatt 2014.05.01 20:43 

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 );
Alain Verleyen
Moderator
28672
Alain Verleyen 2014.05.01 22:56  

Hello,

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


This time, I edited it for you.

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.05.01 23:02  
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 );
Keith Watford
Moderator
8008
Keith Watford 2014.05.02 00:03  

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

skatt
186
skatt 2014.05.02 00:40  
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.
skatt
186
skatt 2014.05.02 00:43  

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

   ArraySetAsSeries(AtrBuffer,false);
   ArraySetAsSeries(time,false);
Keith Watford
Moderator
8008
Keith Watford 2014.05.02 03:38  
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.

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.05.02 08:51  
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.
/
To add comments, please log in or register