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

Indicator code



PureBytes Links

Trading Reference Links

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