Hi All,

Can anyone help out please, as I'm currently stuck with a coding 
problem and struggling to resolve it.

What I want to do is calculate the number of previous bars (within 
the last 100bars) where the previous closes were within 3% of the 
CURRENT Closing Price.

What I have so far is shown below. The code is not very elegant as 
I'm trying to keep it very simple in an attempt to find out where I'm 
going wrong.


Lookback = 100;
RangePercent = 3;

RangeHigh = Close + (Close*(RangePercent/100));
RangeLow = Close - (Close*(RangePercent/100));

WithinRange = (Close <= RangeHigh) AND (Close >= RangeLow);

NoOfBars = Sum(WithinRange,Lookback);

Plot( NoOfBars , " Support Percentage", ParamColor( "Color", 
colorCycle ), ParamStyle("Style") );



At the moment, when I plot this code the line remains at 100.00. 

I believe the reason for this is that for each previous bar, the same 
previous Close value is also referenced which results in the 
Rangehigh & RangeLow ALWAYS being either side of the corresponding 
close and therefore the WithinRange value ALWAYS being true, which is 
clearly not what I want :-(

Consequently, can anyone suggest how I can resolve this as my coding 
skills are pretty limited.

Thanks in advance,

Reply via email to