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

[amibroker] Re: Help with Coding Problem Please



PureBytes Links

Trading Reference Links

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 amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> 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 <sjdugas@xxx> 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" <chorlton-c-hardy@xxx>
> >  To: <amibroker@xxxxxxxxxxxxxxx>
> >  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,
> >  >
>




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/