Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does Ninjascript 8 have a method that returns the index of a bar?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Does Ninjascript 8 have a method that returns the index of a bar?

    Does Ninjascript 8 have a method that returns the index or int of a bar once coder's parameters are met? I've been working on my SR Indicator, and not making much progress. Once a swing high/low is made(my criteria), I want to return the index of the highest high/lowest low so I can do something with that index number.

    Also, how do for loops work with Ninjascript? I've been playing around with them and can't get them to work how I want them to. I've trying a certain look back say 20 bars from CurrentBar and look for say an up bar..if an up bar is found at a certain index to draw text above bar. It's drawing bars all over the chart. I just wanted to use the last 20 bars from the right edge.


    Also, could someone explain what this piece of code does and why it does it?

    "(CurrentBar - startBar)"

    Draw.Rectangle (this, "test", (CurrentBar - startBar), rect_high, 0, rect_low, Brushes.Cornsilk, true);

    Thanks for all of the help.

    #2
    Hello jamestrader21x,

    Thank you for your post.

    CurrentBar will give you the current bar index of the bar currently being evaluated. The code you've got in your example would be subtracting a number of bars saved in a startBar variable from that current bar index. Keep in mind that CurrentBar counts up from 0, with the very first bar on the leftmost of the chart being the 0 bar. This is not the same as how many bars ago the bar was created.

    As far as loops go, could you provide an example of the code you're trying that's not working for you?

    Thanks in advance; I look forward to assisting you further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X