Indicator for time periods since given range?

Posted By: CL1

Indicator for time periods since given range? - 09/09/13 08:29

Hi, is there a built in indicator that gives the time periods since a given range (high-low) occurred? Something like the inverse of average true range, but without time averaging.

So one might give an input of 0.01 as a 1 cent move for EUR/USD, and the number of time periods to the first time High-Low exceeded 1 cent is returned.

I tried to code this in an indicator using:
int i=1; var HL=0.0;
while(HL<0.01) {
HL=HH(Data[i])-LL(Data[i];
i=i+1; }
return (i-1)

However, this hung Zorro, and even when I tried with 4 hour data for just a few months, Zorro still hung with the message "compiling.........."

Thanks for any guidance.
Posted By: jcl

Re: Indicator for time periods since given range? - 09/09/13 12:25

This code, if I understand it right, can cause an endless loop or even a crash. If you program an indicator with a loop, you must build in some stop criteria for preventing that it exceeds the Lookback period.
Posted By: CL1

Re: Indicator for time periods since given range? - 09/09/13 12:35

Hi, yes that is true. However, I actually tried it with an extremely low range, like 10 pips which should be triggered within just a few 1m periods. I also never specified a Lookback, and started with i=1 and incremented i instead.

Shouldn't this work?
Posted By: CL1

Re: Indicator for time periods since given range? - 09/09/13 13:12

Hi again, I added a Period limit and as mentioned, it stops Zorro from crashing. However, the code is not executed properly. It seems like for small difference (like 1 pip), 1 period is returned. However, increasing to 5 pips gives 1 period for most points, and spiking to the maximum allowed (1440) at points. The following code was run for EUR/USD:

var fxn_HL(var* Data, int Period)
{
int i=1; var HL=0.0;
while(HL<0.0005 and i<Period)
{
HL=HH(Data[i])-LL(Data[i]);
i=i+1;
}
return (i-1);
}

function run()
{
StartDate = 2013; // start the simulation with September 2005
LookBack=1440;
BarPeriod=60;
set(PLOTPRICE+PLOTNOW);
PlotBars = 20000;
var* Price = series(price());

vars HL_ser = series(fxn_HL(Price,1440));
vars HH_ser=series(HH(24));
vars LL_ser=series(LL(24));
plot("HL",HL_ser[0],NEW,BLUE);
plot("HH",HH_ser[0],NEW,BLUE);
plot("LL",LL_ser[0],NEW,BLUE);
}

The graph of HH and LL for the last 24 hours is plotted. As you can imagine, a 5 pip range must be obtained in every given past hour.

Am I making some huge mistake??
Posted By: jcl

Re: Indicator for time periods since given range? - 09/09/13 13:51

Hint: have a look at your call of the HH and LL functions.
Posted By: CL1

Re: Indicator for time periods since given range? - 09/09/13 14:05

Thanks man, that was much more kind than just calling me an idiot! Substituting period for Price at period.
© 2023 lite-C Forums