[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NR7 day showme code ?



PureBytes Links

Trading Reference Links

Some time ago this subject was discussed, and several of you
asked for my code for this function.  I generally am looking
not necessarily for the narrowest of seven, but for something
more like the third narrowest of 100, so the lowest() function
doesn't do the job.

Anyway, here's what I use; the sorting function is Shell's sort.
Function, then paintbar indicator:

{
  function isnr():
}

{Return 1 if range of last bar of series
 is less than arg (Nof) bars out of total length.
 Return 0 otherwise.
}
input: Nof(numericsimple), length(numericsimple);
var: ni(0), j(0), k(0), n(0), m(0), tmp(0);
array: rhist[200](0);

if CurrentBar = 1 then begin	{Init}
    n = 1;			
    while n <= length-1 begin
        n = n * 3 + 1; end;
    ni = IntPortion(n / 3);
end;

m = 0;
for n = 0 to length-2 begin	{Fill array with ranges}
    if DataCompression > 0	{Check for short tickbars}
     or upticks[n] + downticks[n] >= upticks[n+1] + downticks[n+1]
    then begin
        rhist[m] = High[n] - Low[n];
        m = m+1;
    end;
end;
n = length-1;
if DataCompression > 0
 or upticks[n] + downticks[n] >= upticks[n-1] + downticks[n-1]
then begin
    rhist[m] = High[n] - Low[n];
    m = m+1;
end;

n = ni;		{Sort array into ascending order}
while n >= 1 begin
    for k = n to m-1 begin
        j = k - n;
        tmp = rhist[k];
        while j >= 0 and rhist[j] > tmp begin
             rhist[j + n] = rhist[j];
             j = j - n;
        end;
        rhist[j + n] = tmp;
    end;
    n = IntPortion(n / 3);
end;

if High - Low < rhist[Nof]
 and (DataCompression > 0 or upticks + downticks >= upticks[1] + downticks[1])
then
    isnr = 1
else
    isnr = 0;



{
  Paintbar nr():
}

input: Nof(1), length(7);

if isnr(Nof, length) = 1
 and time >= Sess1StartTime and time <= Sess1EndTime then begin
    Plot1(High, "high");
    Plot2(Low, "low");
    if CheckAlert then Alert = true;
end;