Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

High of Highs Bars Syntax

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

    High of Highs Bars Syntax

    I feel like I am losing my mind, so I will just ask the question. I have tried 20 ways and I'm not getting the expected result.

    Assume the following:

    -- multi-instrument, multi-timeframe strat
    -- default [0] Bar is 1 minute bar


    I want to calc the high of a one second bar.

    Easy,

    Code:
    Add(PeriodType.Second, 1);      // Add a 1 sec Bars object - BarsInProgres index = 1
    OnBarUpdate:

    Code:
    double oneSecHigh = Highs[1][0];
    Great, now I want to know the "High" over the last 5 minutes, updating every second.

    So I am adding a 300 second ( = 5 min) bar, and having it update every second. This is Bar Index 2.

    The code appears as follows:

    Code:
    Add(PeriodType.Second, 300);      // Add a 300 sec Bars object - BarsInProgres index = 2
    OnBarUpdate:

    Code:
    If (BarsInProgress == 1)
    {double fiveMinHigh = Highs[2][0];}
    What in my crowded brain have I done wrong? I feel like I am staring straight at it, but it is not returning the value I expect.

    Help straighten me out

    Regards,

    Andrew
    Last edited by alabell; 02-05-2013, 09:59 PM.

    #2
    HI Andrew, the issue in understanding is here -

    'Great, now I want to know the "High" over the last 5 minutes, updating every second.

    So I am adding a 300 second ( = 5 min) bar, and having it update every second. This is Bar Index 2.'

    You would only see updates to the 300 sec series for every tick for example in realtime or replay, as you would need to have access to intrabar data - as otherwise in backtesting CalculateOnBarClose is always 'true', thus you get the last completed bar value only, not the developing one.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I have been using MarketReplay and I have set COBC to false during this entire process...

      and still I am not getting satisfactory results.

      Sorry I wasn't more clear Bertrand.

      I am not using backtest.


      Originally posted by NinjaTrader_Bertrand View Post
      HI Andrew, the issue in understanding is here -

      'Great, now I want to know the "High" over the last 5 minutes, updating every second.

      So I am adding a 300 second ( = 5 min) bar, and having it update every second. This is Bar Index 2.'

      You would only see updates to the 300 sec series for every tick for example in realtime or replay, as you would need to have access to intrabar data - as otherwise in backtesting CalculateOnBarClose is always 'true', thus you get the last completed bar value only, not the developing one.

      Comment


        #4
        Ok no worries. Would you mind sending me your scirpt to test to support at ninjatrader dot com?

        Please then include which market / date / timeframe you ran as well.

        Also, it could be you would not see any intrabar update - consider this candle case for the 300 sec. High / Low is established very early in the bar and then we're just meandering between them. This will give you a print of the same High / Low from 1 sec perspective for the full 300sec bar of course.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I will send the code and thank you for offering Bertrand, but i think I can now ask the question more simply:

          what is the syntax for locating the high price over the last 300 seconds, updating every second...I feel like there should be a way that there IS a completed bar every second, and that bar is 300 seconds long, even if COBC = true. It would be a bar made of of 300 data elements that drops the 300th element and adds the most recent element every second.

          Does that make sense?

          Thanks and regards,

          Andrew

          Comment


            #6
            Andrew, you could look into using the MAX method on the 1 second series then with a large lookback (your 300).



            This would attempt emulating calling it with a shorter lookback on a higher frame.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              yes, that's what I need to do.

              Many thanks Bertrand.

              I'm not sure why I created a 300 second Bar, because even with COBC off, once I close a bar
              and it becomes Highs[2][1], then my Highs[2][0] bar will only evaluate 1...then 2...then 3...seconds of data...all the way to 300.

              In other words, it will completely ignore the prior 300 seconds once the bar closes, correct?

              Best,

              Andrew

              Comment


                #8
                Yes Andrew, so the bar index really refers to only the bar specified, which ever series that is. Only if have you have methods in place that would need lookbacks for example for averaging / smoothing then of course the 'older' bars do contribute as well. But Highs[x][y] is a single bar high value.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Absolutely understood Bertrand.

                  But given that in this instance, I am trying to "limit" data and to record the high of the most recent 5 mins/300 seconds only (ignoring a higher trade that may have occurred 301 seconds ago), your method of using MIN and MAX is what I should have done from the start.


                  Many Thanks,

                  Andrew

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by nandhumca, Today, 03:41 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post nandhumca  
                  Started by The_Sec, Today, 03:37 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post The_Sec
                  by The_Sec
                   
                  Started by GwFutures1988, Today, 02:48 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by ScottWalsh, 04-16-2024, 04:29 PM
                  6 responses
                  33 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by frankthearm, Today, 09:08 AM
                  10 responses
                  36 views
                  0 likes
                  Last Post frankthearm  
                  Working...
                  X