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 Waxavi, Today, 02:10 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            7 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Working...
            X