Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Did not Cross Below / Above in the past X bars

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

    Did not Cross Below / Above in the past X bars

    I'd like to create a strategy where Value of indicator 1 should NOT cross above Value of indicator 2 in the past X bars.

    Example
    if !(CrossBelow(EMA(10), EMA(20), 10)) // will return a crossing that might've occurred during e.g. the 7th last bar. This condition is still true, since it didn't cross Below in one of the bars.

    What I'd to do is: make sure no crossing occurred during the past 10 bars.
    Is there a way to achieve this ?

    Thanks a lot!

    #2
    Hello YakusaTrader,

    Thanks for your post.

    You can save the current bar number at the time of the crossover and then compare the current bar number to see if it has been within the last 10 bars. You can make use of the system's CurrentBar which is a bar counter for this, reference: https://ninjatrader.com/support/help...currentbar.htm
    For example, assume you have created an int variable called lastCrossBar.

    if (CrossBelow(EMA(10), EMA(20), 1))
    {
    lastCrossBar = CurrentBar; //save the bar number where the cross occured.
    }

    if (your entry conditions && CurrentBar - lastCrossBar > 10)
    {
    // do something
    }

    Alternatively, you might consider using the MRO() method: https://ninjatrader.com/support/help...urence_mro.htm

    Comment


      #3
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      119 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      63 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      45 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      82 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X