Thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
On Render
Collapse
X
-
Hi, one additional question, I am working on the scaling for my indicator using OnCalculateMinMax(), where I set the MaxValue and the MinValue depending on the displayed values, this works fine when the indicator is applied to a chart, but it doesnt when I scroll in or out, when is OnCalculateMinMax() called, only on configuration or always? How do I get this working on zooming in and out?
Thanks
-
This is what I have in my code:
if (State == State.SetDefaults)
{
IsAutoScale = true;
}
is this correct?
Comment
-
Basically what I am doing is loop through the displayed bars and try to find Max and Min, attached code
public override void OnCalculateMinMax()
{
int FirstBar = ChartBars.FromIndex + 1;
int LastBar = ChartBars.ToIndex;
for (int index = FirstBar; index <= LastBar; index ++)
{
MaxValue = Math.Max(MaxValue,SeriesHigh.GetValueAt(index));
Print("Max" + MaxValue);
MinValue = Math.Min(MinValue, SeriesLow.GetValueAt(index));
Print("Min" + MinValue);
}
}
Comment
-
I believe I see what you are trying to do, but you may be confused about the purpose of OnCalculateMinMax(). This callback method is triggered when the chart scale on the Y axis is changed, and is also continuously run to determine the highest and lowest values on the chart scale, but this does not relate specifically to High and Low prices in a Data Series.
I recommend giving this a try, instead, and doing it within OnBarUpdate():
Code:protected override void OnBarUpdate() { int FirstBar = ChartBars.FromIndex + 1; int LastBar = ChartBars.ToIndex; if (CurrentBar >= FirstBar) { for (int index = FirstBar; index <= LastBar; index++) { // MaxValue = Math.Max(MaxValue, SeriesHigh.GetValueAt(index)); Print(String.Format("Bar: {0}, High: {1}", index, High.GetValueAt(index))); // MinValue = Math.Min(MinValue, SeriesLow.GetValueAt(index)); Print(String.Format("Bar: {0}, Low: {1}", index, Low.GetValueAt(index))); } } }
Dave I.NinjaTrader Product Management
Comment
-
Hi Dave,
thats what i am trying to do, the max and min dataseries values should be the upper and lower bounds of the chartpanel in which the values are displayed. Which works when the indicator is applied or when I zoom out and max increases or min decreases, when I zoom in the former values stay unchanged. think they needed to be reseted.
Comment
-
Originally posted by NinjaTrader_Dave View Post... But in this context we're talking about using SharpDX drawing methods (DrawText, DrawLine, etc.), which rely on a RenderTarget passed in to the method.
When drawing directly with SharpDX, rather than using drawing methods in the NinjaScript namespace, the clipping bounds will prevent you from drawing across the panel. Without this clipping in place, SharpDX draw method coordinates (Vector2's) would relate to the entire chart canvas, so you could potentially have things drawn across multiple panels at once, as the coordinates would be based upon the entire canvas.
Is there any way to get a RenderTarget which refers to all chart ?
Thanks
Comment
-
There is currently not a way to do this. "RenderTarget" itself does refer to the entire chart, but we've added clipping logic to ensure that objects cannot be drawn across multiple panels. I've spoken with our developers about this issue, and it is something that we specifically put in place to mitigate potential drawing issues, and is not likely to be changed soon.
That being said, I'll be more than happy to log a suggestion so we can track demand for this, if you would like.Dave I.NinjaTrader Product Management
Comment
-
Originally posted by NinjaTrader_Dave View PostThere is currently not a way to do this. "RenderTarget" itself does refer to the entire chart, but we've added clipping logic to ensure that objects cannot be drawn across multiple panels. I've spoken with our developers about this issue, and it is something that we specifically put in place to mitigate potential drawing issues, and is not likely to be changed soon.
That being said, I'll be more than happy to log a suggestion so we can track demand for this, if you would like.
In NT7, my indicator is loaded on the indicator panel, but simultaneously draws both the indicatorPanel and the pricePanel, using the Plot method of the indicator (not Draw objects).I get this through Reflection, but that is not useful with SharpDX.
Comment
-
Just a thought,
But would a Callback in the ChartStyle OnRender() which passes the parameters back to the subscribing "User" work? It might be cleaner in the indicator to have an OnRender() for the indicator panel and a different one for the Price Panel?
This might be something you can implement in a custom chart style as well. I don't need this capability yet, but might work on it in a month or so. I want to try and cut the CPU usage time down so I want a single "Core" indicator that does the processing and then others that simply display them on the chart.
Comment
-
NT7 graphics.FillPolygon equivalent
Hi,
I'm trying to fill a polygon in the OnRender(...) function but with no success. Basically, I'm trying to do what I did with the graphics.FillPolygon in NT7.
So far here is the code I wrote :
Code:SharpDX.Direct2D1.Brush linebrush = couleur.ToDxBrush(RenderTarget); SharpDX.Direct2D1.Factory factory = new SharpDX.Direct2D1.Factory(); SharpDX.Direct2D1.PathGeometry geo1 = new SharpDX.Direct2D1.PathGeometry(factory); SharpDX.Direct2D1.GeometrySink sink1 = geo1.Open(); sink1.BeginFigure(p0.ToVector2(), new SharpDX.Direct2D1.FigureBegin()); sink1.AddLines(new SharpDX.Vector2[] { p1.ToVector2(), p2.ToVector2(), p3.ToVector2() }); sink1.EndFigure(new SharpDX.Direct2D1.FigureEnd()); sink1.Close(); RenderTarget.FillGeometry(geo1, linebrush);//!!!<- Problem here !!! geo1.Dispose(); sink1.Dispose(); linebrush.Dispose(); factory.Dispose();
fill the geometry
When I compile and run this code on a chart, the chart is freezing. If I remove the RenderTarget line, the chart works correctly (but obviously, do not show the polygon).
In the SampleCustomPlot example, you use
Code:RenderTarget.FillRectangle(rect, areaBrushDx); RenderTarget.DrawRectangle(rect, areaBrushDx, 2);
Thanks in advance
-----------------------------------------------
Christophe - Ninja-Addons.com
CEO Azur Investment Technologies "AzurITEC" sas
3rd Party Add-On Vendor
Comment
-
You're creating new objects that don't need to be for this case.
I.E. the Direct2D1 factory is already in place by using Core.Globals.D2DFactory
Also there are enums in place for the FigureBegin and FigureEnd, no need to create a new object for them.
Changes are in bold
Try this code out -
Code:SharpDX.Direct2D1.Brush linebrush = myBrush.ToDxBrush(RenderTarget); Point p0 = new Point(100, 100); Point p1 = new Point(100, 125); Point p2 = new Point(200, 125); Point p3 = new Point(200, 100); SharpDX.Vector2[] vectors = new [] {p1.ToVector2(), p2.ToVector2(), p3.ToVector2() }; SharpDX.Direct2D1.PathGeometry geo1 = new SharpDX.Direct2D1.PathGeometry([B]Core.Globals.D2DFactory[/B]); SharpDX.Direct2D1.GeometrySink sink1 = geo1.Open(); sink1.BeginFigure(p0.ToVector2(), [B]SharpDX.Direct2D1.FigureBegin.Filled[/B]); sink1.AddLines(vectors); sink1.EndFigure([B]SharpDX.Direct2D1.FigureEnd.Closed[/B]); sink1.Close(); [B] RenderTarget.DrawGeometry(geo1, linebrush); RenderTarget.FillGeometry(geo1, linebrush)[/B]; geo1.Dispose(); sink1.Dispose(); linebrush.Dispose();
Last edited by Calonious; 09-23-2015, 12:49 PM.
Comment
-
Works like a charm !
Many thanks to you.
-----------------------------------------------
Christophe - Ninja-Addons.com
CEO Azur Investment Technologies "AzurITEC" sas
3rd Party Add-On Vendor
Comment
-
Originally posted by Calonious View PostYou're creating new objects that don't need to be for this case.
I.E. the Direct2D1 factory is already in place by using Core.Globals.D2DFactory
Also there are enums in place for the FigureBegin and FigureEnd, no need to create a new object for them.
Changes are in bold
Try this code out -
Code:SharpDX.Direct2D1.Brush linebrush = myBrush.ToDxBrush(RenderTarget); Point p0 = new Point(100, 100); Point p1 = new Point(100, 125); Point p2 = new Point(200, 125); Point p3 = new Point(200, 100); SharpDX.Vector2[] vectors = new [] {p1.ToVector2(), p2.ToVector2(), p3.ToVector2() }; SharpDX.Direct2D1.PathGeometry geo1 = new SharpDX.Direct2D1.PathGeometry([B]Core.Globals.D2DFactory[/B]); SharpDX.Direct2D1.GeometrySink sink1 = geo1.Open(); sink1.BeginFigure(p0.ToVector2(), [B]SharpDX.Direct2D1.FigureBegin.Filled[/B]); sink1.AddLines(vectors); sink1.EndFigure([B]SharpDX.Direct2D1.FigureEnd.Closed[/B]); sink1.Close(); [B] RenderTarget.DrawGeometry(geo1, linebrush); RenderTarget.FillGeometry(geo1, linebrush)[/B]; geo1.Dispose(); sink1.Dispose(); linebrush.Dispose();
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by arvidvanstaey, Today, 02:19 PM
|
2 responses
7 views
0 likes
|
Last Post Today, 03:12 PM | ||
Started by jordanq2, Today, 03:10 PM
|
0 responses
5 views
0 likes
|
Last Post
by jordanq2
Today, 03:10 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
46 views
0 likes
|
Last Post Today, 02:36 PM | ||
Started by mmckinnm, Today, 01:34 PM
|
3 responses
6 views
0 likes
|
Last Post Today, 02:12 PM |
Comment