Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How many bars ago did a signal happen?

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

    How many bars ago did a signal happen?

    NT support,

    Could you please help?

    Probably a really simple question, how do I determine how many bars ago a signal occurred?

    For instance, if I was using a standard MA crossover with CrossAbove(). How could I work back in the USDJPY (for example) prices to determine how may bars ago a CrossAbove happened?

    Thanks and regards,

    drolles

    #2
    Hi drolles,

    You may want to look into MRO, LRO for this. They express the number of bars since a condition.





    You can also custom code it. This can be done by capturing CurrentBar at the time of a condition, and then taking the difference of CurrentBar & this captured value.

    Code:
    #region Variables
    private int myConditionBar;
    #endregion

    protected override void OnBarUpdate()
    {
    if (Close[0] > Open[0])
    myConditionBar = CurrentBar;

    int barsSinceUpClose = CurrentBar - myConditionBar;
    }
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

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