Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Value[0] is throwing IndexOutOfRangeException.

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

    Value[0] is throwing IndexOutOfRangeException.

    I'm trying to write my first Indicator. Its extremely simple and I'm following the code path from SMA but when I step into the code in VS the this.Value isn't initialized and thus this.Value[0] is throwing an exception. I don't see anywhere within SMA source code file where Value is being initialized and the base class NinjaScriptBase defines the property as returning null.

    So, what am I doing wrong?

    #2
    Originally posted by Kabua View Post
    I'm trying to write my first Indicator. Its extremely simple and I'm following the code path from SMA but when I step into the code in VS the this.Value isn't initialized and thus this.Value[0] is throwing an exception. I don't see anywhere within SMA source code file where Value is being initialized and the base class NinjaScriptBase defines the property as returning null.

    So, what am I doing wrong?
    It might help better if you just posted the code, so that someone can see what is wrong.

    Comment


      #3
      Welcome to the forums Kabua!

      It sounds like the indicator is missing AddPlot().

      I suggest using the New Indicator Wizard (NinjaScript Editor > Indicators folder > Right Click > New Indicator) as it can conveniently add all the code necessary for plots. I have also included a link to our AddPlot() documentation which can be referenced for creating working plots.

      AddPlot() - https://ninjatrader.com/support/help...s/?addplot.htm

      As koganam mentions, attaching the code can help us to understand exactly what you are running into.

      I look forward to being of further assistance.

      Comment


        #4
        Yes, me bad. I wasn't sure what was the difference between AddPlot and AddLine when I went through the wizard. Therefore, I choose AddLine but it appears what I really wanted was AddPlot, once I changed the code to AddPlot the Value property was properly initialized. Thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        49 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        69 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        36 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        96 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        59 views
        0 likes
        Last Post PaulMohn  
        Working...
        X