Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a function that tells how long a condition has existed?

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

    Is there a function that tells how long a condition has existed?

    Guys, I want to be able to know how long a moving average has been flat. Is there a Function that can look back like CountIf(), but with an unlimited scope?

    I want to use this information to then determine how the market oscillates above and below its mean. I want to be able to describe the range so I can trade it while it lasts and then trade the breakout.

    Does anyone have any suggestions please?

    #2
    crmcwi, I think you can work with LRO for this to check since how many bars back condition x returned true - http://www.ninjatrader-support.com/H...urenceLRO.html

    Comment


      #3
      LRO not quite right

      Thanks Bertrand, I appreciate it.

      The LRO, however, requires a lookback period. I need a function that will return the number of bars for which a condition is continuously true.

      For example, let's say that 78 minutes ago, a SMA went flat. I would like a function that can tell me that. In CQG, for example, there's a WHEN() function that will tell you the last time a condition was true or false. You can ask, "when was the SMA not flat", for example and it will return 79 in our case.

      If such a function does not exist in NJ Script, have you come across anything that was custom coded? Please advise, thank you, Craig.

      Comment


        #4
        Craig, unfortunately I'm not aware of one not needing a lookback period input - but you could custom code this yourself, just save the current bar number to a variable when your condition for the flat MA triggers and then take the difference from the CurrentBar to this variable for the value you seek.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Craig, unfortunately I'm not aware of one not needing a lookback period input - but you could custom code this yourself, just save the current bar number to a variable when your condition for the flat MA triggers and then take the difference from the CurrentBar to this variable for the value you seek.

          yep, cool. thank you. when I do, I would like to post it for the community. Is there a vetting process or coding standard?

          Comment


            #6
            We would appreciate a post in the sharing section of our forums when this finalized - http://www.ninjatrader-support2.com/...splay.php?f=37

            As for a coding standard, please take a look at the system indicators and reference samples for how the code is structured and formatted.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            549 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            549 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X