# Bar Number formula not working

Hi I am trying to get the following formula to work:

/////This indicator shows (1) Close of 200 bars ago <= to 1.5* today’s close and (2) Close of 100 bars ago <= to 1.5* today’s close (but where there is less than 200 bars then uses close of Barnumber days ago instead)

//No of bars since first Listed
BarNumber=Acc(Close()>0);

V18=Close(Barnumber)<=1.5Close() and Close(50)<=1.5Close();
V19=Close(200)<=1.5Close() and Close(100)<=1.5Close();
V20=if(BarNumber<200,V18,V19);
V20

Please see attached chart - the triangle show bar does not work at the start of the chart when it should also appear when there are less than 200 bars. Can you please let me know wheat modifications I need to make to the formula to get it to work.
Thanks,
Karen

OptumaSent12.09.2021-v2.owb (11.7 KB)

Hi,

You should be able to achieve the result you are after using the BARINDEX() function instead of the ACC() setup you have in your example. You can then use an IF() to determine when to use the 100 / 200 offset vs the First Close in cases where there are less than 200 bars.

Here’s an example script:

```//Find Bar Total
V1 = BARINDEX();
//Set Criteria if Bar Count is greater than 200
V2 = CLOSE(200) <= (CLOSE() * 1.5) and CLOSE(100) <= (CLOSE() * 1.5) ;
//Set Criteria if Bar Count is less than 200
V3 = FIRST(Close()) <= (CLOSE() * 1.5) ;
//Show result based on above rules
IF(V1 < 200,V3,V2)```

I have checked it against codes with less than 200 bars, and those with more than 200 bars and the results returned look to be correct based on your description.