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

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
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by royhagerman, Today, 04:30 AM
            0 responses
            1 view
            0 likes
            Last Post royhagerman  
            Started by haas88, 03-21-2024, 02:22 AM
            18 responses
            208 views
            0 likes
            Last Post haas88
            by haas88
             
            Started by Board game geek, Today, 02:20 AM
            0 responses
            6 views
            0 likes
            Last Post Board game geek  
            Started by knighty6508, Today, 01:20 AM
            2 responses
            15 views
            0 likes
            Last Post knighty6508  
            Started by franatas, Today, 01:53 AM
            0 responses
            5 views
            0 likes
            Last Post franatas  
            Working...
            X