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

The last displayed bar on the chart screen

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

    #16
    Originally posted by forrestang View Post
    @koganam, do you know of a way to reference the right most bar that can be SEEN on a chart at all times?

    For example, so the most right bar on the chart is 5000, if you scroll your chart by 1-bar to the left, the right most bar would then be 4999. Would it be possible to reference that bar, although the most recently loaded bar is 5000?

    Asking more as I think it would be cool to do such a thing.
    The second option that I posted.
    Code:
    int intLastBarPaintedOnChart = this.LastBarIndexPainted;

    Comment


      #17
      @koganam

      May I ask... if you have ever loaded the standard 'Pivots' indie onto a chart, when you scroll it left and right on the chart, the pivots will redraw based on the day they are on.

      Is ":this.LastBarIndexPainted;" the way to go about achieving the ability to do that? For example, say I wanted to simply draw a line at the top of the highest high of the last 5 bars, based on whatever bar happens to be the right-most on the chart.

      Code:
                              int lBack1 = 5;
      			double myHigh=MAX(High,lBack1 )[0]; 
      			
      			DrawLine("High",lBack1 -1,myHigh,0,myHigh,Color.Green);
      This would do it in the standard fashion. Where it would look at the right-most bar on the chart, and take that and the 4 bars before it, and plot a line from 5 bars ago on the HH of those bars.

      How would this be modified to place this line on whatever bar happens to be at the most right of the chart, if you where to scroll back with the left arrow? Is it possible with 'this.LastBarIndexPainted?' Or am I barking up the wrong tree?

      Comment


        #18
        Originally posted by forrestang View Post
        @koganam

        May I ask... if you have ever loaded the standard 'Pivots' indie onto a chart, when you scroll it left and right on the chart, the pivots will redraw based on the day they are on.

        Is ":this.LastBarIndexPainted;" the way to go about achieving the ability to do that? For example, say I wanted to simply draw a line at the top of the highest high of the last 5 bars, based on whatever bar happens to be the right-most on the chart.

        Code:
                                int lBack1 = 5;
        			double myHigh=MAX(High,lBack1 )[0]; 
        			
        			DrawLine("High",lBack1 -1,myHigh,0,myHigh,Color.Green);
        This would do it in the standard fashion. Where it would look at the right-most bar on the chart, and take that and the 4 bars before it, and plot a line from 5 bars ago on the HH of those bars.

        How would this be modified to place this line on whatever bar happens to be at the most right of the chart, if you where to scroll back with the left arrow? Is it possible with 'this.LastBarIndexPainted?' Or am I barking up the wrong tree?
        Look at the code of that Pivots indicator, and you will see that it is using a Custom Plot that uses a GraphicsPath for drawing. Yes, it uses this.LastBarIndexPainted etc.,

        You can use a similar method for drawing your line.

        Comment


          #19
          Ironically, I have used the plot override method years ago, as I had a desire to change text colors on a chart based on some calculations... but I really didn't understand it.

          I also didn't understand that this will allow the bars to be referenced in a way that can draw things based on bars despite WHERE the current chart scroll happens to be located.

          I notice now though, that say you add a Print Command(like in the script attached below), that will allow referencing of whatever bar happens to be at the right-most edge of the chart. You can then make your calculations off of that bar. This allows calculations to be done on the right edge of the chart, despite the most recently LOADED bar.

          As Printing using the "this.LastBarIndexPainted," in the onBarUpdate will only ever reference the most recently LOADED bar.

          This simple script below will draw a line from the right-most edge of the chart, even if you scroll to the left of the most recently LOADED bar. THe line is plotted at the highest high of the most recent bars(lBack1 is the parameter for how many bars to use).

          Good exercise for me!

          Code:
          		public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
          		{
          			int lBoC = this.LastBarIndexPainted;
          			Print(Time[0]+",  "+CurrentBar +",  "+lBoC +",  "+Time[CurrentBar-lBoC]);
          			
          			double myHigh=MAX(High,lBack1)[CurrentBar-lBoC]; 
          
          			int x1 =(CurrentBar-lBoC)+lBack1-1;//lBack1-1;
          			
          			DrawLine("High",x1,myHigh,CurrentBar-lBoC,myHigh,Color.Green);
          			
          		}
          Last edited by forrestang; 08-31-2016, 09:21 AM.

          Comment


            #20
            So one weird thing I am noticing with this, which is not a big deal...

            If I use the arrows on my keyboard to scroll back and forth on my chart, it mis-draws some of the objects I have placed.

            But if I click ANYWHERE on the chart, without moving the chart, it will fix itself! It only happens occasionally.

            I've spent time trying to recreate and figure out exactly what this issue is about, but I am unsure still?

            Again, it's not a big deal for me, and this issue won't affect what I need to do, but figured I'd mention it in case anyone else noticed such a thing if they search for this thread some time from now.

            Below is an example of correct/incorrect drawings my indie produced, and the ONLY thing I did from the incorrect to the correct was click somewhere on the chart.

            -----EDIT----
            One thing I've noticed, is that if looking at the print window with Print() Commands somewhere in the override block, anytime the chart is clicked, it will issue a print command to the window. Similar to the way onBarUpdate() will issue a Print() Command to the output window anytime a new bar is loaded.

            So it must be reliant on chart interactivity?
            Attached Files
            Last edited by forrestang; 08-31-2016, 10:45 AM.

            Comment


              #21
              Originally posted by forrestang View Post
              So one weird thing I am noticing with this, which is not a big deal...

              If I use the arrows on my keyboard to scroll back and forth on my chart, it mis-draws some of the objects I have placed.

              But if I click ANYWHERE on the chart, without moving the chart, it will fix itself! It only happens occasionally.

              I've spent time trying to recreate and figure out exactly what this issue is about, but I am unsure still?

              Again, it's not a big deal for me, and this issue won't affect what I need to do, but figured I'd mention it in case anyone else noticed such a thing if they search for this thread some time from now.

              Below is an example of correct/incorrect drawings my indie produced, and the ONLY thing I did from the incorrect to the correct was click somewhere on the chart.
              Have you called the base.Plot(...) method in your custom Plot()?
              -----EDIT----
              One thing I've noticed, is that if looking at the print window with Print() Commands somewhere in the override block, anytime the chart is clicked, it will issue a print command to the window. Similar to the way onBarUpdate() will issue a Print() Command to the output window anytime a new bar is loaded.

              So it must be reliant on chart interactivity?
              The Plot() uses the OnPaint() event, so yes, anytime that the chart is painted, everything in the Plot() runs.

              Comment


                #22
                Originally posted by koganam View Post
                Have you called the base.Plot(...) method in your custom Plot()?
                I have not. I am not sure what that does?

                Comment


                  #23
                  Originally posted by forrestang View Post
                  I have not. I am not sure what that does?
                  It calls the base method that you are inheriting and overriding, so as to make sure that anything that NT would have done gets done.

                  Comment


                    #24
                    What is the syntax for it? Do you just put the line of code somewhere in the custom plot block?

                    Code:
                    base.Plot(Graphics graphics, Rectangle bounds, double min, double max)

                    Comment


                      #25
                      Originally posted by forrestang View Post
                      What is the syntax for it? Do you just put the line of code somewhere in the custom plot block?

                      Code:
                      base.Plot(Graphics graphics, Rectangle bounds, double min, double max)
                      Like every other method that is called with parameters, you call it without the parameter descriptors.
                      Code:
                      base.Plot(graphics, bounds, min, max)
                      usually at the beginning or the end of the block, depending on how you want to process the drawing data.

                      Comment


                        #26
                        Hmmm...

                        So I tried adding that method in the custom Plot Block, at the beginning and the end. I was still able to reproduce that error.

                        I also tried adding it after each line that called for a drawing object to be made.

                        I added a Print at the end of a block also, I had a thought that maybe there were times when the entire block may not be processed for some reason... but this isn't the case, as there is always an output to the output window, even when the indie calculates incorrectly.

                        Comment


                          #27
                          Originally posted by forrestang View Post
                          Hmmm...

                          So I tried adding that method in the custom Plot Block, at the beginning and the end. I was still able to reproduce that error.

                          I also tried adding it after each line that called for a drawing object to be made.

                          I added a Print at the end of a block also, I had a thought that maybe there were times when the entire block may not be processed for some reason... but this isn't the case, as there is always an output to the output window, even when the indie calculates incorrectly.
                          Given all that it would be impossible to say anything sensible at this time without seeing your actual code.

                          Comment


                            #28
                            It doesn't matter now as it wasn't much of an issue, but just posting in case someone else has such an issue.

                            But since I was only drawing one object at a time(Only one object on screen at all times with a common string tag), I just used:

                            Code:
                            RemoveDrawObject("Body"); RemoveDrawObject("tWic"); RemoveDrawObject("bWic");
                            Inserted this right before every instance where I was going to redraw those objects for the right edge of the screen, and it removed that problem I was having.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by pechtri, 06-22-2023, 02:31 AM
                            9 responses
                            122 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by frankthearm, 04-18-2024, 09:08 AM
                            16 responses
                            66 views
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by habeebft, Today, 01:18 PM
                            1 response
                            5 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by benmarkal, Today, 12:52 PM
                            2 responses
                            14 views
                            0 likes
                            Last Post benmarkal  
                            Started by f.saeidi, Today, 01:38 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Working...
                            X