Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Bar Start Time/EndTime

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

    Current Bar Start Time/EndTime

    Hello,

    I am very new to NinjaScript.

    Could you please help me to Current Bar Start time/End time in BackTesting mode.

    I am able to get OHLC data eg. for open --> Open[0]

    #2
    Hello ziaul,

    Thank you for your post.

    You can use Time[0] to pull the current bar's time. If you have CalculateOnBarClose set to false, then you will get the current time of the bar. If CalculateOnBarClose is set to true, then you will get the last bar's close time. In backtesting through the Strategy Analyzer, CalculateOnBarClose will always be true.

    If you want the previous bar's close time you can use Time[1], this will also be the start time of the current bar as the closing tick is used to open the next bar.

    For information on Time please visit the following link: http://www.ninjatrader.com/support/h...s/nt7/time.htm

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello ziaul,

      Thank you for your post.

      You can use Time[0] to pull the current bar's time. If you have CalculateOnBarClose set to false, then you will get the current time of the bar. If CalculateOnBarClose is set to true, then you will get the last bar's close time. In backtesting through the Strategy Analyzer, CalculateOnBarClose will always be true.

      If you want the previous bar's close time you can use Time[1], this will also be the start time of the current bar as the closing tick is used to open the next bar.

      For information on Time please visit the following link: http://www.ninjatrader.com/support/h...s/nt7/time.htm

      Please let me know if you have any questions.
      This is a good explanation and helped. How do I do it with MTF bars?

      My indi is finding the hourly pivots. The indicator will be on the 5 min charts. An easy way to do this is by using the 60 min bars.

      So, in Initialize section, I have Add(PeriodType.Minute, 60) to add 60 minute bars data.

      I calculate the pivot with: (Closes[0][i] + Highs[0][i] + Lows[0][i])/3.

      But I need to know when that hour started and stopped using the barshift number (which is "i" in the above example). I tried
      Starttime = Times[0][i+1]
      Endtime = Times[0][i]

      But I get an error saying I am converting "System.DateTime" to "NinjaTrader.Data.DateTimeSeries."

      Can you tell me what I am doing wrong to get this error? I am sure I have the wrong delcaration type, but cannot find how to fix this in thehelp.

      Thanks,
      Stearno

      Comment


        #4
        Hello Stearno,

        Thank you for your note.

        What did you declare Starttime and Endtime as?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Cal View Post
          Hello Stearno,

          Thank you for your note.

          What did you declare Starttime and Endtime as?
          In Variable section I have:
          private DateTimeSeries[]HourMPTimeOpen;
          private DateTimeSeries[]HourMPTimeClosed;

          (Because I want to use them as arrays and store the datetime).

          I have tried to find what different time formats there are, but again did not find anything in the help on it (for example, maybe one type presents it in number of seconds since a particular date, another might provide string of the date and time, etc.).

          Thanks.

          -Stearno

          Comment


            #6
            Stearno,

            You will need to use .Set() and then pass through the date time structures.

            Starttime.Set(Times[0][i+1]);
            Endtime.Set(Times[0][i]);
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Oh, okay. Thanks!

              -Steanro

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              22 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X