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

BarsRequiredToPlot

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

    BarsRequiredToPlot

    Hi,

    I had a question regarding BarsRequiredToPlot.

    When I look at the standard SMA indicator (provided by NT8) in the NT editor, it doesn't appears to have a BarsRequiredToPlot defined.

    But when I drop the standard SMA indicator on a chart with a parameter of 10, it appears to skips the first 20 bars.

    I wrote a replica of the standard SMA indicator, with BarsRequiredToPlot equal to the Period and even that indicator skips the first 20 bars (for a SMA parameter of 10).

    Why is this so?

    See attached graph.
    Attached Files

    #2
    Hello uday12,

    Thanks for the note.

    The developers made the default 20 bars if no BarsReqiredToPlot is defined. The MA will always begin plotting at the 20th bar. You can set the BarsReqiredToPlot = 0 if you want to override the property.

    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello uday12,

      Thanks for the note.

      The developers made the default 20 bars if no BarsReqiredToPlot is defined. The MA will always begin plotting at the 20th bar. You can set the BarsReqiredToPlot = 0 if you want to override the property.

      Please let us know if we may be of any further assistance.
      Chris,

      I had another question. Suppose I want to set the BarsRequiredToPlot as a function of some parameter Period.

      Suppose I set BarsRequiredToPlot within OnStateChange() such as

      ----

      if (State == State.SetDefaults)
      {
      BarsRequiredToPlot = (int)Math.Sqrt(Period);
      }

      ----

      the code compiles fine.

      But then when I try the indicator on a chart, I get an error in the log "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.".

      Removing the BarsRequiredToPlot line from the code seems to remover the error during plot the indicator.

      In which State can I assign a value to BarsRequiredToPlot when the value of BarsRequiredToPlot is a function of input parameters?

      Comment


        #4
        Hello uday12,

        Thanks for the reply.

        I was able to do this in State.Configure. You would need to make sure that the Period property is set before you try to use it in a formula.

        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        30 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        6 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X