Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to draw a line using the PlotStyle from a Plot?
Collapse
X
-
Hello koganam,
Thanks for your post. This would require custom rendering to accomplish. Below is a modified snippet from the help guide which can demonstrate drawing from the last bar to the right side margin.
Code:protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); // get the starting and ending bars from what is rendered on the chart float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex); float endX = (ChartPanel.X + ChartPanel.W); // Loop through each Plot Values on the chart for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++) { // get the value at the last bar on the chart (if it has been set) if (Values[seriesCount].IsValidDataPointAt(ChartBars.ToIndex)) { double plotValue = Values[seriesCount].GetValueAt(ChartBars.ToIndex); // convert the plot value to the charts "Y" axis point float chartScaleYValue = chartScale.GetYByValue(plotValue); // calculate the x and y values for the line to start and end SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue); SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue); // draw a line between the start and end point at each plot using the plots SharpDX Brush color and style RenderTarget.DrawLine(startPoint, endPoint, Plots[seriesCount].BrushDX, Plots[seriesCount].Width, Plots[seriesCount].StrokeStyle); } } }
With the small vertical lines drawn on top of the horizontal line, you will have achieved the same visual effect as having the PlotStyle.Cross plot extend to the right side margin.
Please let me know if I can be of further assistance.JimNinjaTrader Customer Service
-
Originally posted by NinjaTrader_Jim View PostHello koganam,
Thanks for your post. This would require custom rendering to accomplish. Below is a modified snippet from the help guide which can demonstrate drawing from the last bar to the right side margin.
Code:protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); // get the starting and ending bars from what is rendered on the chart float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex); float endX = (ChartPanel.X + ChartPanel.W); // Loop through each Plot Values on the chart for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++) { // get the value at the last bar on the chart (if it has been set) if (Values[seriesCount].IsValidDataPointAt(ChartBars.ToIndex)) { double plotValue = Values[seriesCount].GetValueAt(ChartBars.ToIndex); // convert the plot value to the charts "Y" axis point float chartScaleYValue = chartScale.GetYByValue(plotValue); // calculate the x and y values for the line to start and end SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue); SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue); // draw a line between the start and end point at each plot using the plots SharpDX Brush color and style RenderTarget.DrawLine(startPoint, endPoint, Plots[seriesCount].BrushDX, Plots[seriesCount].Width, Plots[seriesCount].StrokeStyle); } } }
With the small vertical lines drawn on top of the horizontal line, you will have achieved the same visual effect as having the PlotStyle.Cross plot extend to the right side margin.
Please let me know if I can be of further assistance.
I was asking how to do the same using whatever the user may have already chosen. I really did not want to have to think through and code for each specific choice in the enumeration. I am way too lazy for that.
Comment
-
Wondering if there is a way to add a desired PlotStyle to a existing or called Ray, and Referenced Ray instead of them using DashStyle to be able to call the string name or ray to hard code a PlotStyle TriangleUp/Down. Is it possible using these line types?
Comment
-
Hello LoganJKTrader,
I may not be understanding the question fully.
PlotSyles are specific for customizing plots. Plots also contains a Stroke which has a Brush (color) and DashStyle.
If you want to customize plotting code, you will have to override the indicator's OnRender method.
Drawing Objects may only have the Stroke (includes DashStyle) to customize.
A list of available drawing commands that would not require custom rendering code in OnRender can be found below. Maybe you are looking to use Draw.ArrowUp/Draw.ArrowDown?
If there are additional questions, could you further describe what you are trying to accomplish?JimNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View PostHello LoganJKTrader,
I may not be understanding the question fully.
PlotSyles are specific for customizing plots. Plots also contains a Stroke which has a Brush (color) and DashStyle.
If you want to customize plotting code, you will have to override the indicator's OnRender method.
Drawing Objects may only have the Stroke (includes DashStyle) to customize.
A list of available drawing commands that would not require custom rendering code in OnRender can be found below. Maybe you are looking to use Draw.ArrowUp/Draw.ArrowDown?
https://ninjatrader.com/support/help...t8/drawing.htm
If there are additional questions, could you further describe what you are trying to accomplish?
Comment
-
Hello LoganJKTrader,
Ray's do not have a PlotStyle, We would only be able to customize the DashStyle, and we would us the following overloads for that purpose:
Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width)
Draw.Ray(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)
Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)
https://ninjatrader.com/support/help...l?draw_ray.htm
If you wanted to make a custom Ray that looks like a PlotStyle, that would require custom rendering in a drawing tool. You could make a copy of the Lines DrawingTool if you wanted to make modifications for a customized Ray.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ZenCortexHurry, Today, 01:04 PM
|
0 responses
0 views
0 likes
|
Last Post Today, 01:04 PM | ||
Started by f.saeidi, Today, 12:14 PM
|
3 responses
9 views
0 likes
|
Last Post Today, 01:02 PM | ||
Started by Russ Moreland, Today, 12:54 PM
|
1 response
3 views
0 likes
|
Last Post Today, 01:01 PM | ||
Started by philmg, Today, 12:55 PM
|
1 response
4 views
0 likes
|
Last Post Today, 01:00 PM | ||
Started by TradeForge, 04-19-2024, 02:09 AM
|
2 responses
31 views
0 likes
|
Last Post
by TradeForge
Today, 12:32 PM
|
Comment