Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mizzouman1, Today, 07:35 AM
      4 responses
      18 views
      0 likes
      Last Post Mizzouman1  
      Started by philmg, Today, 01:17 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by cre8able, Today, 01:01 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by manitshah915, Today, 12:59 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by ursavent, Today, 12:54 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X