int intLastBarPaintedOnChart = this.LastBarIndexPainted;
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!
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
NinjaTrader
The last displayed bar on the chart screen
Collapse
X
-
@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);
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
-
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);
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?
You can use a similar method for drawing your line.
Comment
-
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
-
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?Last edited by forrestang; 08-31-2016, 10:45 AM.
Comment
-
Originally posted by forrestang View PostSo 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?
Comment
-
-
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
-
Originally posted by forrestang View PostWhat 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)
Code:base.Plot(graphics, bounds, min, max)
Comment
-
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
-
Originally posted by forrestang View PostHmmm...
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
-
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");
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment