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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      29 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      46 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X