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 LawrenHom, Today, 10:45 PM
        0 responses
        3 views
        0 likes
        Last Post LawrenHom  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        37 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        44 views
        0 likes
        Last Post bill2023  
        Working...
        X