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

Error in Bars.GetBar()

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

    Error in Bars.GetBar()

    Hi
    I have a ninja7 strategy and want to convert it to 8.
    It calculates the max and min value between a special period. it uses GetBar to do that and i converted it to this piece of code :

    localZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
    startDate = TimeZoneInfo.ConvertTimeFromUtc(startDate, localZone);
    endDate = TimeZoneInfo.ConvertTimeFromUtc(endDate, localZone);


    startBarsAgo = Bars.GetBar(startDate);
    endBarsAgo = Bars.GetBar(endDate);


    nightSessionHigh = MAX(High, startBarsAgo - endBarsAgo + 1)[endBarsAgo];
    nightSessionLow = MIN(Low, startBarsAgo - endBarsAgo + 1)[endBarsAgo];


    it calculates two important values : startBarsAgo and startBarsAgo according to the time zone of PC. the it runs Bars.GetBar(startDate) and here i catch an exepction:

    Value of property 'Period' of NinjaScript 'MAX' is -43692 and not in valid range between 1 and 2147483647.

    The values of fields are
    startBarsAgo : 618791
    endBarsAgo : 662484

    So what should i do?

    #2
    Hello amiralimadadi,
    Thanks for your post.

    I have seen this before, but I can't find the post right now. What I would do is Print() each line in NT7 and NT8 to the NS Output window and compare the values. This will help us figure out where exactly the issue is.

    Let me know where you find the difference and we can go from there.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      I have done it before and this is the line where the error exactly occurred:


      startBarsAgo = Bars.GetBar(startDate);

      Comment


        #4
        What was the NT7 code for that line?
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          That's a simple question:
          How to get max and min values of bars during a special time?
          for example: from 8/22/2018 8AM to 8/23/2018 2PM. The distance is too big and NT8 says that :

          Value of property 'Period' of NinjaScript 'MAX' is -43692 and not in valid range between 1 and 2147483647.

          Comment


            #6
            Looking at the help guide it looks like you may need to do something like this instead:
            Code:
            startBarsAgo = CurrentBar - Bars.GetBar(startDate);
            Help Guide GetBar()
            Josh G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bmartz, 03-12-2024, 06:12 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by Aviram Y, Today, 05:29 AM
            4 responses
            13 views
            0 likes
            Last Post Aviram Y  
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            28 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X