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

Re: Indicator code



PureBytes Links

Trading Reference Links

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");