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

Need Help on this Paint Bar Study

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

    Need Help on this Paint Bar Study

    Hello, I'm trying to create a simple paint bar study, based on ADX and DM value. It works as a strategy, but would not "paint" bar as an indicator. It compiles without any issue. Can someone please help?

    Here's the indicator code:

    // Wizard generated variables
    private int level = 20;
    // Default setting for Level
    // User defined variables (add any user defined variables below)
    private Color upcolor = Color.Blue;
    private Color downcolor = Color.Red;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Overlay = true;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (ADX(5)[0] > level
    && ADX(5)[0] > ADX(5)[1]
    && DM(5).DiPlus[0] > DM(5).DiMinus[0])
    {
    BarColor = upcolor;
    }

    if (ADX(5)[0] > level
    && ADX(5)[0] > ADX(5)[1]
    && DM(5).DiPlus[0] < DM(5).DiMinus[0])
    {
    BarColor = downcolor;
    }

    }

    #2
    Hello shzhning,

    Thank you for your note.

    When enabling the indicator on the chart do you see any errors listed on the Log tab of the Control Center? If so, what do they report?

    Comment


      #3
      This is the message: Error on calling "OnBarUpdate" method for indicator "ADXPaintBar" on bar 0: You are accessing an index with a value that is invalid since it's out of range, I.E. acessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      How can I correct this issue? I do have dozens of bars - it's a generic 10 minute bar chart.

      FYI: this part of code is directly copy and pasted from the strategy generated by ninjatrader

      if (ADX(5)[0] > level
      && ADX(5)[0] > ADX(5)[1]
      && DM(5).DiPlus[0] > DM(5).DiMinus[0])

      Thanks

      Comment


        #4
        Originally posted by shzhning View Post
        This is the message: Error on calling "OnBarUpdate" method for indicator "ADXPaintBar" on bar 0: You are accessing an index with a value that is invalid since it's out of range, I.E. acessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        How can I correct this issue? I do have dozens of bars - it's a generic 10 minute bar chart.

        FYI: this part of code is directly copy and pasted from the strategy generated by ninjatrader

        if (ADX(5)[0] > level
        && ADX(5)[0] > ADX(5)[1]
        && (CurrentBar > 0)
        && DM(5).DiPlus[0] > DM(5).DiMinus[0])

        Thanks
        Added, in blue, to your original text.
        Last edited by koganam; 10-13-2014, 02:44 PM.

        Comment


          #5
          thanks for the quick reply. I added "&& (CurrentBar > 0)" as you suggested, but for some reason it's still not working. Received same error message in the log.

          Really at a loss...

          Comment


            #6
            Originally posted by shzhning View Post
            thanks for the quick reply. I added "&& (CurrentBar > 0)" as you suggested, but for some reason it's still not working. Received same error message in the log.

            Really at a loss...
            That means that your error is coming from a different part of your code.

            I have reread your first post. There are 2 different code blocks, each of which will require the necessary modification. I responded to your post that showed only one block.

            The alternative would be to use a Bars escape at the start of your OnBarUpdate() code. Put this as the first statement:
            Code:
            if (CurrentBar < 1) return;
            Last edited by koganam; 10-13-2014, 10:57 PM.

            Comment


              #7
              It's working now

              Thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by GLFX005, Today, 03:23 AM
              0 responses
              1 view
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              11 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              6 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              14 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              3 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Working...
              X