PureBytes Links
Trading Reference Links
|
Hi,
My code returns empty value whenever there is an all time high/low,
you cannot say that it's been n days since price was lower than
today if it's an all time low. However if you want the function to
return the barnumber in these cases just use the code below.
Johan
//-------------------------------------
SetBarsRequired(100000,0);
function nDayExtreme(f)
//NOTE: f should be a string, "H" or "L".
{
n=Null; sgn=IIf(f=="H",-1,1);
a=IIf(f=="H",H,IIf(f=="L",L,Null));
if(LastValue(Cum(!IsTrue(a)))==0)
{
for(i=0; i<BarCount; i++)
{
for(j=i-1; j>=0; j--)
{
if(sgn*a[j]<sgn*a[i]){n[i]=i-j; /*break loop*/ j=-1;}
else n[i]=i; // <-- added this line
}
}
}
return n;
}
nH=nDayExtreme("H");
nL=nDayExtreme("L");
Filter=nH>=20 OR nL>=20;
AddColumn(nL,"nL",1.0);
AddColumn(nH,"nH",1.0);
Plot(C,"",colorDefault,styleCandle);
Title="It's been "+NumToStr(nL,1.0)+
" bars since low was lower than current low,"+
"\nand "+NumToStr(nH,1.0)+
" bars since high was higher than current high";
//----------------------------------------------
--- In amibroker@xxxxxxxxxxxxxxx, "Kropotkin" <backup_dayad@xxxx>
wrote:
> Thanks,
>
> I couldn't get those to work completely. (Johan's mostly worked,
but
> gave a lot of "{Empty}" where it shouldn't have.)
>
> I've also realised that the approach I suggested doesn't account
for
> all time highs. So, I am just using a function to test for break
of
> n-day high & low, called from within a do-while loop which
> progressively increases the value of n, (using "n=n*1.5;"
and "while
> n<1000").
>
> Not perfect, but it'll do for now.
>
> Thanks again.
>
> Chris
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|