PureBytes Links
Trading Reference Links
|
That is definitely faster but does not solve the problem.
Say (just as an example) the most recent price is 100 and the preceding 5
prices were 99,97,97,99,99.
I want to return a value of how many times in the previous 4 bars (say) the
price has been at 100 (setting band to zero).
The answer, by inspection, is 0. However my code (and yours) will give a
value of 2 because instead of comparing the last 4 values with 100, it does
the following:
99<>97 therfore count = 0
97 = 97 therefore count =1
97<>99 therfore count= 1(still)
99=99 therefore count=2.
Regards
VT.
----- Original Message -----
From: "Bob Fulks" <bfulks@xxxxxxxxxxxx>
To: "Virgin Trader" <virgin_trader@xxxxxxxxxxx>
Cc: "omega list" <omega-list@xxxxxxxxxx>
Sent: Sunday, July 08, 2001 3:19 PM
Subject: Re: Indicator code
> It is a lot more direct (and much, much faster) to just keep track as you
move forward rather than count back. Something like the following might
help:
>
> Condition1 = Close[1] < topband and Close[1] > bottomband;
> if Condition1 then Count = Count + 1;
> significance = 100 * (Count - Count[Length]) / Length;
>
> I don't follow why you want some integral number of days but if you do,
you can calculate the proper value for "Length" and still use the above
code.
>
> Bob Fulks
>
>
> At 11:03 AM +0100 7/8/01, Virgin Trader wrote:
>
> >I am trying to write an indicator which expresses the percentage of time
a
> >price has spent at (or close to) the level it is at now, over a period of
a
> >few days.
> >
> >To do this I have used the COUNTIF function. The problem is that I do not
> >know how to fix the level (see code below) at the current price through
the
> >COUNTIF process. In other words the value used shifts back one bar every
> >time a count is done, when I actually want the value to remain fixed at
the
> >current bar's value throughout the COUNTIF process.
> >
> >I hope I've explained it clearly enough. Can anyone suggest a solution?
> >
> >VT.
> >
> >****************************************************
> >
> > inputs: daysback(1),barsinday(101), band(5);
> >vars: length(0),barstoday(0),significance(0),
> >todaysfirstbar(0),topband(0),bottomband(0),level(0);
> >
> >if date<>date[1] then todaysfirstbar = currentbar;
> >barstoday= currentbar-todaysfirstbar;
> >length = daysback*barsinday + barstoday;
> >
> >level=close; { <THIS BIT DOESN'T WORK}
> >topband = level+band/2;
> >bottomband = level-band/2;
> >
> >condition1 =close[1] < topband and close[1]>bottomband;
> >significance= CountIF(condition1, length)/length*100;
> >
> >plot1(significance,"significance");
>
|