Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to code bars since condition

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

    How to code bars since condition

    Hi NT8,

    How do I code bars since a condition other than entry. similar to the bars since entry/exit condition, I'd like to reference the number of bars since another condition.

    Such as

    If
    (MACD cross 0)

    Then
    (variable = bars since that event)

    Thank you!

    #2
    I'd like to clarify that I can't use the look back period, what I am trying to do is replicate the Bars since entry for a different condition, so that I can do this:

    Condition (Bars Since last Condition > 10)

    ^ I don't believe the look back period can do this because it checks if a condition happened within the look back period and I'd like to set if a condition happened to bars greater than a lookback period.

    Comment


      #3
      Hello Austiner87, thanks for writing in.

      We have the MRO (Most Recent Occurrence) method that will return the bar index where a condition happened:
      https://ninjatrader.com/support/help...urence_mro.htm

      There is an example on that page on how to use it.

      If you have any further questions please let me know.

      Comment


        #4

        Hi NT8, I need some more help on this:

        // Prints the high price of the most recent up bar over the last 10 bars (current bar + look back period's 9 bars before that)
        int barsAgo = MRO(() => Close[0] > Open[0], 1, 9);
        if (barsAgo > -1)
        Print("The bar high was " + High[barsAgo]);

        ^using the example, how would I check for if a variable increased by 1 (+=1) greater than 12 bars ago. my assumption is below, can you please let me know if this is correct?

        int barsAgo = MRO((variable += 1) => Close[0] > Open[0], 1,12);
        if (barsAgo >= 12)


        Comment


          #5
          Hello Austiner87, thanks for your reply.

          The (variable) => is a way to pass in parameters into the lambda function. To check if a variable increased by one you would need to store the variable in a custom Series<T> object:

          https://ninjatrader.com/support/help.../?iseriest.htm

          Then you can compare MySeries[0] against MySeries[11 to 1] to see if MySeries[0] == MySeries[x]+1

          Make sure to test thoroughly with Print statements to check the output.

          Please let me know if I can assist any further.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          133 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X