Bar Number formula not working

Optuma Forums Optuma Scripting Bar Number formula not working

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #65989
    Karen
    • Topics: 21
    • Replies: 32
    • Posts: 53

    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.5*Close() and Close(50)<=1.5*Close();
    V19=Close(200)<=1.5*Close() and Close(100)<=1.5*Close();
    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

    #65999
    Matthew
    • Topics: 5
    • Replies: 421
    • Posts: 426

    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:

    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.

    • This reply was modified 4 days ago by Matthew.
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest