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 Price Trade At This Level X Bars Ago?

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

    Did Price Trade At This Level X Bars Ago?

    Does anyone have an idea of how to write up code to be true if:

    "At any time, price traded at 1.4320 over the last 20 bars"

    IOW, I want to return true if price has ever hit 1.4320 in the last X amount of bars.

    It would be easy to do this just based on Close... but I want to do this based on Bid or Ask... so basically (I assume) I'd have to do this at the tick level...

    Thoughts?

    #2
    Hi trend747,

    There's a few built in methods that check conditions over a lookback to return a useful value.

    CountIf() method.


    MRO:


    LRO:


    When looking at historical bars, you only have four price points to work from: OHLC. These methods will not work in a multiseries framework which you may need to work at the tick level. Similar functionality is possible through custom coding by iterating through previous bars.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Yes, there's not exactly one way to do it, and the best technique varies depending on whether you need this historically/real time or within multiseries framework.

      For single series, CountIf() works well to check occurrence of a condition. I'd use something like this to check bars over a lookback to see if they contain the specified price:

      if (CountIf(delegate {return Low[0] <= 1.4320 && High[0] >= 1.4320 ;}, 20) > 0)
      Print("There's been at least one occurence of my test condition");
      Last edited by NinjaTrader_RyanM1; 07-27-2011, 08:32 AM.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by trend747 View Post
        Does anyone have an idea of how to write up code to be true if:

        "At any time, price traded at 1.4320 over the last 20 bars"

        IOW, I want to return true if price has ever hit 1.4320 in the last X amount of bars.

        It would be easy to do this just based on Close... but I want to do this based on Bid or Ask... so basically (I assume) I'd have to do this at the tick level...

        Thoughts?
        Check for Highest High and Lowest Low. If the reference price is between them, then the reference price must have been traded through at least once.

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Yes, there's not exactly one way to do it, and the best technique varies depending on whether you need this historically/real time or within multiseries framework.

          For single series, CountIf() works well to check occurrence of a condition. I'd use something like this to check bars over a lookback to see if they contain the specified price:

          if (CountIf(delegate {return Low[0] >= 1.4320 && High[0] <= 1.4320 ;}, 20) > 0)
          Print("There's been at least one occurence of my test condition");
          Ryan, should that not be the other way around?

          if (CountIf(delegate {return Low[0] <= 1.4320 && High[0] >= 1.4320 ;}, 20) > 0)

          Comment


            #6
            Hi koganam,

            Yes, you're right. Thanks for the spot and post corrected above.
            Last edited by NinjaTrader_RyanM1; 07-27-2011, 08:32 AM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by KenneGaray, Today, 03:48 AM
            0 responses
            1 view
            0 likes
            Last Post KenneGaray  
            Started by thanajo, 05-04-2021, 02:11 AM
            4 responses
            470 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by aa731, Today, 02:54 AM
            0 responses
            4 views
            0 likes
            Last Post aa731
            by aa731
             
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            10 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,237 views
            0 likes
            Last Post sidlercom80  
            Working...
            X