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

Need equivalent of LowestBar

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

    Need equivalent of LowestBar

    I have code that I am trying to port from Multicharts and although the variable and functions are similar names, the expected result is different.

    Code:
    result = Low[LowestBar(low, depth)[index]];
    I can find LowestBar in the NinjaTader code but the [index] on the end is additional to the NinjaTrader function call. In the above code, index is the loop value incrementing through the bars, depth is the depth to check back through.

    I've tried the following but the value it returns and rest of the code do not produce any results.

    Code:
    result = Low[LowestBar(Low, depth) + index];

    #2
    Hello davemclaughlin,

    To confirm, on each bar you are wanting to loop backwards through all bars?
    (This would be CPU intensive)

    For example if I wanted to print the low of the last 3 bars starting with the most recent bar (bars ago 0):
    if (int index = 0; index < 3; index++)
    {
    Print(Low[index]);
    }

    Low[int barsAgo]


    Using lowest bar will return a bars ago value.
    For example to find the lowest low in the last 5 bars:
    Print(Low[LowestBar(Low, 5)]);

    LowestBar(IDataSeries series, int period)


    It may be that the method in the other platform uses an offset similar to MIN()
    For example to find the Lowest low from 10 bars ago to 5 bars ago:
    Print(MIN(Low, 5)[5]);

    MIN(IDataSeries input, int period)[int barsAgo]
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, that now returns the value I need.

      Comment


        #4
        Question:

        I have a CL 01-17 5min chart with Trading Hours set to Nymex Energy RTH.

        Looking at the chart, I observe the low's of the first 7 bars for 12-13-16 to be:
        Low1 = 53.02
        Low2 = 53.13
        Low3 = 53.20
        Low4 = 53.16
        Low5 = 53.06
        Low6 = 53.04
        Low7 = 52.80

        I have a script with only the following code......
        Code:
        protected override void OnBarUpdate()
        {   
          int lowestBar = LowestBar(Low, Bars.BarsSinceNewTradingDay);
          
          double lowestPrice = Low[lowestBar];         
          
          Print(lowestPrice);           
        }
        The output for 12-13-16 shows the first value as 53.02 and the second value as 53.13 which holds for both bars 3 & 4. Then 53.06 is printed for bar 5. However, according to the script's logic I would think 53.02 would hold for bars 1 - 6 until the low of 52.80 printed @ bar 7.

        Am I thinking about this incorrectly, or is this unexpected behavior?

        Comment


          #5
          Hello Assiduous,

          The data you have typed doesn't match how this indicator should work.

          Do you have a chart or prints to demonstrate the data you are using and the output you are getting?

          As an example, attached is an exported script I've used to test using the ES 03-17 on 1 minute bars using 1 day to load. In the script, I'm comparing the value produced by CurrentDayOHL indicator for a quick comparison and i'm also printing the low of each bar so that you may double check the lows with the corresponding timestamps yourself.

          I am not able to reproduce the behavior you have described.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            ChelseaB,

            Thanks for the example. Unfortunately, I get the same unexpected behavior when I use your script. I have attached the output in a .txt file as well as a screenshot. You will notice the issue is only with the first low for the first bar of the trading session. For whatever reason, it's not holding.

            As a reminder, I am using the NYMEX Energy RTH Trading Hours template. Do you mind testing this out on your end with the CL 01-17 contract on a 5 min chart and the Trading Hours set to NYMEX Energy RTH?
            Attached Files

            Comment


              #7
              Hi Assiduous,

              The issue is only with the first two bars?

              I think the issue is the period supplied to the LowestBar method is short 1.

              If we're processing the first bar it has been 0 bars since the start of the session.
              If we are processing the second bar, it has been 1 bar since the start of the session. If we supply this 1 to the LowestBar() method it will only include 1 bar, the current bar.

              So add 1 to the value returned Bars.BarsSinceNewTradingDay. This should add the previous bar in. You will need to check that bar exists first of course to make sure you do not get an invalid index on the first bar.
              Code:
              int period = Bars.BarsSinceNewTradingDay + 1;
              if (CurrentBar <= period)
              return;
              int lowestBar = LowestBar(Low, period);
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Ah, makes total sense. Thanks for the simple solution.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by junkone, Today, 11:37 AM
                2 responses
                14 views
                0 likes
                Last Post junkone
                by junkone
                 
                Started by frankthearm, Yesterday, 09:08 AM
                12 responses
                44 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by quantismo, 04-17-2024, 05:13 PM
                5 responses
                35 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by proptrade13, Today, 11:06 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                36 views
                0 likes
                Last Post love2code2trade  
                Working...
                X