Graham & Steve, Many Thanks guys for your assistance. Its v much appreciated.
I'll take a look at your code and try to fully understand it. For some reason I seem to struggle with looping. Thanks once again.... Chorlton --- In [email protected], Graham <[EMAIL PROTECTED]> wrote: > > you would need to create a function for this, something like this might work > > function range(lookback,RangePercent) > { > RangeHigh = Close + (Close*(RangePercent/100)); > RangeLow = Close - (Close*(RangePercent/100)); > Count = 0; > for(n=1;n<lookback;n++) > { > count = count + ((Ref(Close,-n) <= RangeHigh) AND (Ref(Close,-n) >= > RangeLow)); > } > return Count; > } > > Plot( range(100,3) , " Support Percentage", ParamColor( > "Color",colorCycle ), ParamStyle("Style") ); > > -- > Cheers > Graham Kav > AFL Writing Service > http://www.aflwriting.com > > > > On 23/02/2008, Steve Dugas <[EMAIL PROTECTED]> wrote: > > Hi - If you are just concerned about today's value, you can try this ( > > untested ). If you need to do it correctly for the entire array, then off > > the top of my head, you may need to rewrite it for a loop... > > > > Steve > > > > Lookback = 100; > > RangePercent = 3; > > LastClose = LastValue( Close ); > > RangeHigh = LastClose + (LastClose*(RangePercent/100)); > > RangeLow = LastClose - (LastClose*(RangePercent/100)); > > > > WithinRange = (Close <= RangeHigh) AND (Close >= RangeLow); > > NoOfBars = Sum(WithinRange,Lookback); > > Plot( NoOfBars , " Support Percentage", ParamColor( "Color", colorCycle ), > > ParamStyle("Style") ); > > > > > > ----- Original Message ----- > > From: "chorlton_c_hardy" <[EMAIL PROTECTED]> > > To: <[email protected]> > > Sent: Friday, February 22, 2008 6:41 AM > > Subject: [amibroker] Help with Coding Problem Please > > > > > > > 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, > > > >
