• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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

    Comment


      #3
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AresBowman, Today, 12:02 AM
      0 responses
      1 view
      0 likes
      Last Post AresBowman  
      Started by patpat, Yesterday, 10:14 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by [email protected], Yesterday, 09:18 PM
      0 responses
      3 views
      0 likes
      Last Post bpatel20@gmail.com  
      Started by johnnybegoode, Yesterday, 06:46 PM
      0 responses
      6 views
      0 likes
      Last Post johnnybegoode  
      Started by DTSSTS, Yesterday, 02:58 PM
      3 responses
      13 views
      0 likes
      Last Post DTSSTS
      by DTSSTS
       
      Working...
      X