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

Plotting bars on a chart

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

    Plotting bars on a chart

    I have an indicator that I've made. My plan is to plot it via a bar graph (like a volume chart looks).

    The indicator works, the math is correct (I can see this from the data box plus copious use of print statements to the output window). Everything works fine BUT.....

    My problem is my lack of true understanding of the Add() and/or DataSeries commands.

    I have enough of it down to get everything to work EXCEPT that I cannot 'see' anything being plotted to the chart.

    Here's a snip or two:

    protected override void Initialize()
    {
    Add(new Plot(Color.Green, PlotStyle.Bar, "Barplot"));
    ....
    }

    protected override void OnBarUpdate()
    {
    ......

    double barplotnum = Close[0];
    Barplot.Set(barplotnum);

    }

    #region Properties
    .....
    public DataSeries Barplot
    {
    get { return Values[3]; }
    }

    #endregion


    Yes, the above "Values[3]" is evidently correct as I have other plots that are working fine. They were copy and pasted from other indicators but when I tried to duplicate my "BarPlot" plot, it would not show up on screen.


    I feel like I am so close, but I just can't see it..

    #2
    Steve,

    I suspect you are trying to access an array before that array has any size.

    Please try adding the following to your OnBarUpdate() method.

    if(CurrentBar < 1 )
    return;

    So far your code sample looks OK but I may need to see more of your code to comment further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Actually, I didn't include it but it already had at the beginning of the OnBarUpdate(), the following:

      if (CurrentBar == 0)
      return;

      I'm assuming it works to the same thing?

      Oddly, and this is the thing, I get plots from this indicator that are basically like the regression lines (which is where I stole the code from in the first place).

      They plot fine in the panel (Can I assume I can have both lines and bars in the same panel?) I can even see the value of "BarPlot" as I said before (I see that in the Data Box) so we know it's populating (with the correct data) too.

      Clearly, and obviously I don't really understand the whole Add(new Plot...) as it pertains to DataSeries and related issues, so my ability to copy-paste code around has run into a snag that I can't figure out despite being what looks like 95% of the way there.

      Where, exactly, in my mess of code does it actually 'plot' the bar that I see in the panel?

      I've read the help files but they're not helping me enough :-)

      Comment


        #4
        Steve,

        Actually, the code you posted looks ok so I suspect something else is going on here. The Add method should be adding a plot generally. Could you attach your code to a post so I may test on my end?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hi Adam,

          Well, let me tell you the short story, lol. Last night after getting about 75% of the way through I came across some help files and saw that I had certainly taken the long approach to things, but having gotten that far in my indicator I was hesitant to halt the ship and change course.

          I figured I'd ask here to see if my problem was easily solvable. After it didn't seem that obvious as to why, I decided to start afresh using a far easier method that I had seen earlier.

          An hour later and I've got it working more or less how I want it. All there is is a bit more coding, then the window dressing.

          So thanks for the effort but at this point the new code is working.

          I do have a couple other question though that this new code has spun off. I'll ask in a new post here on the same thread as it is somewhat related.

          Comment


            #6
            OK, let's get back to it.

            My code is in part looking for when the current price is above (or below) the Regression line "middle" value. (The actual regression line itself with the other two plots being the SD's above and below the regression line itself). This came from viewing the RegressionChannel code I do believe.

            As mentioned earlier, I realized long after the fact that I could simply call the "LinReg()" function.

            It works and my bars plot (new panel). I double-checked the LinReg() calc's with the 'middle' value of the 'Regression Channel' indicator that ships with NT. The two numbers are different. The "middle" value from the Reg Channel indicator as I understand it should be the same number as the "LinReg()" function, should it not?

            Also, my bars start out one color, but I want to change the color at will depending... how do I change the plot color on a temporary basis?

            Let's use for example that they are dark green when Price is above the RegLin() but turn bright green when they are above the RegLin() AND above Close[1] . (That would be above the previous bar's close, correct?
            Last edited by Steve R; 06-03-2012, 06:07 PM.

            Comment


              #7
              Steve,

              The LinReg function is a running linear regression, so it sort of looks like a moving average.

              The Regression Channel, is a regression over the last X bars plotted as lines on your chart. It has an overridden plot method to make the lines I believe.

              When you say you want to set plot colors on a temporary basis, do you mean you want to change past plot colors or only future/current ones?

              Here is a reference sample on changing plot colors : http://www.ninjatrader.com/support/f...ead.php?t=3227

              Close[X] is the close of "X bars ago", so with 1 it would be the previous bar.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_AdamP View Post
                Steve,

                The LinReg function is a running linear regression, so it sort of looks like a moving average.

                The Regression Channel, is a regression over the last X bars plotted as lines on your chart. It has an overridden plot method to make the lines I believe.

                When you say you want to set plot colors on a temporary basis, do you mean you want to change past plot colors or only future/current ones?

                Here is a reference sample on changing plot colors : http://www.ninjatrader.com/support/f...ead.php?t=3227

                Close[X] is the close of "X bars ago", so with 1 it would be the previous bar.
                Hmmm. The LinReg() function has a "Period" associated with it, correct? Would it not calculate, for the 'current bar' anyway, the same calculation as the regression channel's current bar?

                Comment


                  #9
                  Originally posted by NinjaTrader_AdamP View Post
                  Steve,

                  The LinReg function is a running linear regression, so it sort of looks like a moving average.

                  The Regression Channel, is a regression over the last X bars plotted as lines on your chart. It has an overridden plot method to make the lines I believe.

                  When you say you want to set plot colors on a temporary basis, do you mean you want to change past plot colors or only future/current ones?

                  Here is a reference sample on changing plot colors : http://www.ninjatrader.com/support/f...ead.php?t=3227

                  Close[X] is the close of "X bars ago", so with 1 it would be the previous bar.
                  Minus the little LinReg() discrepancy, everything is perfect now including the plot colors.

                  Thanks Adam.

                  Comment


                    #10
                    Steve,

                    Thanks for letting me know.

                    Please don't hesitate to contact us should you require additional assistance.
                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cmtjoancolmenero, Yesterday, 03:58 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post cmtjoancolmenero  
                    Started by Stanfillirenfro, Today, 07:23 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post Stanfillirenfro  
                    Started by olisav57, Yesterday, 07:39 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by cocoescala, 10-12-2018, 11:02 PM
                    7 responses
                    942 views
                    0 likes
                    Last Post Jquiroz1975  
                    Started by oviejo, Today, 12:28 AM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X