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

Problem with LowestBar()

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

    Problem with LowestBar()

    I have a scenario where LowestBar() is returning the current bar as the lowest even though the bar previous to the current bar is actually the lowest. I'm using Yahoo historical daily feed for the S&P500. The 1st bar close is $870.26. The 2nd bar close is $871.79. The statement: if (LowestBar(Close, LookBackPeriod) == 0) where LookBackPeriod=1 is processing out as "true" for some reason. I monitored variable values in Debug via Visual Studio 2008 Pro.

    #2
    aascotty, in the future could you please just ask a question once? Thank you.

    As for your inquiry, the code is working correctly. The code you posted asks this: if the lowest price bar occurs in the latest one bar, evaluate true. Since there is only one bar being looked at (LookBackPeriod = 1), it will always be true. If you'd like to monitor more bars in the past, you can change the look back period to a higher value. For example, to get the lowest bar of the last 10 bars: LowestBar(Close, 10).
    AustinNinjaTrader Customer Service

    Comment


      #3
      Problem with LowestBar()

      I tried it with a lookback period of 2 and the if statement is still evaluating to "true". According to the NinjaTrader documentation, the lookbackperiod includes the bars before the current bar. If the current bar is the 2nd bar of the data feed, a lookback period of 1 should include the 1st bar of the data feed. Like I said, assuming your advice was correct, I tried a lookback period of 2 bars and the if statement still evaluated to true.

      Comment


        #4
        Problem with LowestBar()

        "Working with price data" in Help documentation verifies what I'm saying with an example. The following is the copy and paste:

        You will notice that to reference any price data you need to include a value for [int barsAgo]. This is a very simple concept; barsAgo represents the number of bars ago to reference and int indicates that barsAgo is an integer value. As an example, we could write a statement to check if the the high price of 1 bar ago is less than the high price of the current bar like this:


        High[1] < High[0];

        Comment


          #5
          aascotty, please take a look at the attached screenshot and indicator. Keep in mind we're using the close prices to determine the lowest "low". I chose the line on close chart type because it is easiest to see how LowestBar() works.

          I'm not saying the documentation is incorrect, but sometimes it is best to test an idea out yourself to see how it works.
          Attached Files
          AustinNinjaTrader Customer Service

          Comment


            #6
            Originally posted by aascotty View Post
            "Working with price data" in Help documentation verifies what I'm saying with an example. The following is the copy and paste:

            You will notice that to reference any price data you need to include a value for [int barsAgo]. This is a very simple concept; barsAgo represents the number of bars ago to reference and int indicates that barsAgo is an integer value. As an example, we could write a statement to check if the the high price of 1 bar ago is less than the high price of the current bar like this:


            High[1] < High[0];
            barsAgo is not the same as lookback period.
            AustinNinjaTrader Customer Service

            Comment


              #7
              LowestBar() problem not resolved

              I included the Close prices for bar 1 and 2 in my original post: 1st bar close is $870.26. The 2nd bar close is $871.79. Why isn't the statement: if (LowestBar(Close, LookBackPeriod) == 0) where LookBackPeriod=2 evaluating to false if what you are saying is correct? The attachment you responded with does not clear anything up for me. Please forward my problem to technical support. It looks like there is a bug or inconsistency in Ninjatrader. At the very least, have tech support provide me with a correct explanation for how LowestBar() is really supposed to work.

              Comment


                #8
                Originally posted by aascotty View Post
                I included the Close prices for bar 1 and 2 in my original post: 1st bar close is $870.26. The 2nd bar close is $871.79. Why isn't the statement: if (LowestBar(Close, LookBackPeriod) == 0) where LookBackPeriod=2 evaluating to false if what you are saying is correct? The attachment you responded with does not clear anything up for me. Please forward my problem to technical support. It looks like there is a bug or inconsistency in Ninjatrader. At the very least, have tech support provide me with a correct explanation for how LowestBar() is really supposed to work.
                Ok we need to make sure we're on the same page. I have been assuming that when you say the 1st bar that you mean the most current bar (right-most bar on the chart) - is this correct? Following that, the 2nd bar is the second most recent bar. If that is indeed the case, the most current bar has the lowest close price, so LowestBar(Close, 2) will return 0 (indicating the current bar), thus evaluating to true.

                I will propose another scenario: the most recent bar's (bar 0) close is 4. The second most recent bar's (bar 1) close is 5. Bar 2's close is 6.
                Code:
                LowestBar(Close, 1) // will return 0, indicating the current bar has the lowest close (which makes sense because it is the only bar being looked at)
                LowestBar(Close, 2) // will return 1, indicating that one bar ago was the lowest close
                LowestBar(Close, 3) // will return 2, indicating that two bars ago (3rd most recent bar) was the lowest close.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  LowestBar() problem unresolved

                  Per the Ninjatrader documentation, I'm assuming the convention or "bars ago" of accessing price data with LowestBar() is the same as accessing a DataSeries object such as Close[0] or Close[1]. Close[0] implies current bar or zero bars ago. Close[1] implies 1 bar ago. LowestBar(Close,0) means current bar and no lookback period. LowestBar(Close,1) means a lookback period that includes the current bar and the bar before it or 2 bars total. Otherwise, the documentation on the LowestBar() function is at best ambiguous.

                  Nothing changes in my scenario if I use a lookback period of 1 or 2. LowestBar() is not seeing that the current bar Close of $871.79 is not lower than the 1 bar ago Close prior to the currentbar of $870.26. The statement "if (LowestBar(Close, LookBackPeriod) == 0)" with a lookback of 2 bars should be evaluating to "false".

                  Please forward my problem to tech support.

                  Comment


                    #10
                    Incorrect. lookBackPeriod is not the same concept as [] index values.

                    0 lookback period means zero bars to test. You still get a value from it to prevent errors, but it is not meaningful. 1 means test 1 bar or the current bar. lookback of 1 is not useful either since you are only testing the current bar and there is no need to do such a test. 2 means test current bar and previous bar.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Problem with LowestBar() unresolved still

                      Nothing changes in my scenario if I use a lookback period of 2. LowestBar() is not seeing that the 1 bar ago Close, prior to the currentbar, of $870.26 is the lowest bar when compared to the current bar Close of $871.79. The statement "if (LowestBar(Close, LookBackPeriod) == 0)" with a lookback of 2 bars should be evaluating to "false". It's evaluating to "true". Debug is showing LowestBar(Close, LookBackPeriod) is evaluating to zero which causes the entire "if" statement to evaluate to "true".

                      Please forward my problem to tech support.

                      Comment


                        #12
                        aascotty,

                        This is tech support.

                        We are unable to reproduce your scenario on our end. Please provide exact reproducible steps with an as simple as possible sample script and an export of your data set in use. Thank you.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        14 views
                        0 likes
                        Last Post Pattontje  
                        Started by flybuzz, 04-21-2024, 04:07 PM
                        17 responses
                        229 views
                        0 likes
                        Last Post TradingLoss  
                        Started by agclub, 04-21-2024, 08:57 PM
                        3 responses
                        17 views
                        0 likes
                        Last Post TradingLoss  
                        Started by TradingLoss, 04-21-2024, 04:32 PM
                        4 responses
                        43 views
                        2 likes
                        Last Post TradingLoss  
                        Started by cre8able, 04-17-2024, 04:16 PM
                        6 responses
                        56 views
                        0 likes
                        Last Post cre8able  
                        Working...
                        X