Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code Not Working

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

    Code Not Working

    Can someone tell me why NT will not understand this code. It's hardly rocket science but it keeps killing NT (although it does't take much). Bear in Mind this compiles and works when loading a chart it's only when I add this to a market analyser and try to run it against a number of tickers and try to click through loading charts.....

    (
    (High[0] < High[1] && Low[0] > Low[1] && High[1] >= High[2] && Low[1] > Low[2] && Open[0] <= Close[1] && Close[0] <= Open[0])
    ||
    (High[0] < High[1] && Low[0] > Low[1] && High[1] <= High[2] && Low[1] < Low[2] && Open[0] >= Close[1] && Close[0] >= Open[0] )
    )

    This is the error I see in the logs

    log<date>.txt

    3/01/2012 21:01:43|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 23: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:43|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 39: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:44|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 29: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:45|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 12: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:53|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 14: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:54|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:55|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 19: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:01:58|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    13/01/2012 21:02:16|3|4|Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Trace Log

    012-01-13 21:01:53:265 ERROR: Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 14: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    2012-01-13 21:01:53:734 (IQFeed) Data.Bars.GetBarsNow: instrument='$USDNOK' from='2012-01-13' to='2012-01-13' period=Daily splitAdjusted=False dividendAdjusted=False bars=0 session='Forex'
    2012-01-13 21:01:54:218 (IQFeed) Data.Bars.GetBarsNow: instrument='$USDSEK' from='2012-01-13' to='2012-01-13' period=Daily splitAdjusted=False dividendAdjusted=False bars=0 session='Forex'
    2012-01-13 21:01:54:703 (IQFeed) Data.Bars.GetBarsNow: instrument='$USDSGD' from='2012-01-13' to='2012-01-13' period=1 Min splitAdjusted=False dividendAdjusted=False bars=0 session='Forex'
    2012-01-13 21:01:54:890 ERROR: Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    2012-01-13 21:01:55:796 ERROR: Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 19: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    2012-01-13 21:01:56:468 (IQFeed) Data.Bars.GetBarsNow: instrument='$USDSGD' from='2012-01-10' to='2012-01-12' period=Daily splitAdjusted=False dividendAdjusted=False bars=0 session='Forex'
    2012-01-13 21:01:56:968 (IQFeed) Data.Bars.GetBarsNow: instrument='$USDSGD' from='2012-01-13' to='2012-01-13' period=Daily splitAdjusted=False dividendAdjusted=False bars=0 session='Forex'
    2012-01-13 21:01:58:921 ERROR: Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    2012-01-13 21:02:16:640 ERROR: Error on calling 'OnBarUpdate' method for indicator 'InsideBar' on bar 41: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Trace Log

    012-01-13 20:49:40:937 Code.Editor.OnLoad: Failed to reference 'NinjaTrader.Custom, Version=7.0.1000.4, Culture=neutral, PublicKeyToken=null': System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
    at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
    at System.Reflection.Assembly.InternalLoad(AssemblyNa me assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
    at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
    at System.Reflection.Assembly.LoadFrom(String assemblyFile)
    at NinjaTrader.Code.Editor.OnLoad(Object sender, EventArgs e)

    #2
    Hello,

    Are you running a CurrentBar check at the beginning of this code?

    If you have not yet please try adding the following:
    Code:
    if (Current Bar < 2)
    return;
    Please let me know if that does not help. You can read more about why this is needed from the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170
    MatthewNinjaTrader Product Management

    Comment


      #3
      yes i am

      if (CurrentBar < 2) return;

      Comment


        #4
        Hello Ryebank,

        Then the errors are coming from another statement in the code. From the snippet you provided, the furthest bar you are looking back is 2. If you are doing a CurrentBar check for 2 and still receiving this error, you may have another value that is using a larger look back period. Please try increasing this value, or commenting out other statements that may be in your code.

        When I test the snippet you provided on my end with a CurrentBar check of 2, it works as expected:

        Code:
                protected override void OnBarUpdate()
                {
                    if (CurrentBar < 2)
                        return;
                   
                    if(High[0] < High[1] && Low[0] > Low[1] && High[1] >= High[2] && Low[1] > Low[2] && Open[0] <= Close[1] && Close[0] <= Open[0]
                    || High[0] < High[1] && Low[0] > Low[1] && High[1] <= High[2] && Low[1] < Low[2] && Open[0] >= Close[1] && Close[0] >= Open[0] )
                    {
                    Print("True " +  Time[0]);
                     }
                }
        MatthewNinjaTrader Product Management

        Comment


          #5
          Originally posted by ryebank View Post
          yes i am

          if (CurrentBar < 2) return;
          I never used market analyzer, but can you make the DaysToLoad on your charts or where ever it required something that would feel ridiculous?

          Like if you have 5 DaysToLoad, make it 50.

          I'm not sure either what time frames you are using, but this thread might be of importance:

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          596 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          554 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X