Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
x-value of current bar
Collapse
X
-
x-value of current bar
Is it possible to get the x value of the current bar to us in order to plot text just to the right of the current bar? I have programming set up so the text is floating with price for the y-value but can't get it to scroll left and right as I scroll the chart left and right. The text is staying on the right side of the screen. Any ideas? -
Hello jhowinvest,
Yes, this would be possible by overriding the plot method inside of NinjaTrader. This is not something that we can support but you can view the following references to help you get started with this.
1. You may go to Tools -> Edit NinjaScript -> Indicators -> CustomPlotSample.
2. Our File Sharing Section does have a few indicators that do this as well, one of which is at the following link.
Let us know if we can be of further assistance.JCNinjaTrader Customer Service
-
Thanks but I am still having trouble. This is a variation of the tick counter 3 in the file sharing section. The float with price is great for the y-value but I would like it to slide left and right as I manually scroll the chart. I did set up a private int called "marginValue" that will allow a person to change how far from the right margin the text prints but it is not dynamic like the y-value is.
Here is the section of code if anyone wants to tackle this.
// calculate x,y location for text display
float x;
float y;
switch (DispLocation)
{
case DisplayLocation3.Float_with_price: //the x = line did say x = bounds.X + bounds.Width - ChartControl.BarMarginRight + 5;
x = bounds.X + bounds.Width - ChartControl.BarMarginRight + marginValue;
y = (int)(((bounds.Y + bounds.Height) - ((Close[0] - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height) - textHeight*0.4);
if(ChartControl.BarMarginRight < textWidth-12)
graphics.DrawString("Increase chart Properties - Right side margin", TextFont, textBrush, bounds.X + bounds.Width - noTickTextWidth, bounds.Y + bounds.Height - noTickTextHeight, stringFormat);
break;
Comment
-
Hello jhowinvest,
Thank you for your response.
The ChartControl.BarMarginValue is based on the right side margin as you know, this means if you set the x value to this it will stay static in correlation to the bounds on the right side of the chart. If you would like the x value to stay at a point such as a bar on the chart does you will need to use something such as the bar it's self as the reference point and not the right side margin.
Comment
-
Thanks Patrick. I changed things around because I was making it too complicated. I used your advice and have it working now. I used draw text to keep the tick counter right near the current price bar. Thanks again. Basic code is below:
int ticksRemaining = Bars.Period.Value - Bars.TickCount;
Font textFont = new Font("Arial", textSize, FontStyle.Bold);
if (Bars.Period.Id == PeriodType.Tick && printSymbol == true)
{
DrawText("tag1", false, "<" + ticksRemaining, 0 - counterOffset, Close[0], 0, textColor, textFont, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by justin74444, Today, 03:50 AM
|
0 responses
2 views
0 likes
|
Last Post
by justin74444
Today, 03:50 AM
|
||
Started by Pabulon, Today, 03:08 AM
|
0 responses
7 views
0 likes
|
Last Post
by Pabulon
Today, 03:08 AM
|
||
Started by sukhob, 05-18-2023, 08:26 PM
|
2 responses
128 views
0 likes
|
Last Post
by TraderJA
Today, 01:45 AM
|
||
Started by timwey, Yesterday, 10:55 AM
|
4 responses
24 views
0 likes
|
Last Post
by timwey
Yesterday, 09:33 PM
|
||
Started by DJ888, 06-28-2024, 10:18 PM
|
3 responses
39 views
0 likes
|
Last Post
by AdamDJ8
Yesterday, 08:24 PM
|
Comment