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
Question for Market Profile Indicator
Collapse
X
-
Question for Market Profile Indicator
I'm in the process of creating a Market Profile indicator and need to be able to draw horizontal lines that extend beyond the last bar on the chart. I'm currently using DrawLine() but that only allows the line to be drawn '0' bars ago (i.e., the price bar furthest to the right). Is there a way to do this? Below are a couple of screenshots to illustrate what I'm doing. Also, will NinjaTrader eventually support vertical scrolling? I'm currently using Pepe's VerticalScale indicator, but I think this is basic functionality that should be coded within NinjaTrader, not an indicator. Will it be in NT 7.0? Thanks.
Tags: None
-
Function Calls vs Inline Code
One other question... When I coded the Market Profile indicator for TradeStation using EasyLanguage, it was recommended to avoid function calls to improve performance. Are function calls in NinjaScript also costly? That is, should I avoid functional calls and use inline code? Thanks.
-
Originally posted by antonio View PostOne other question... When I coded the Market Profile indicator for TradeStation using EasyLanguage, it was recommended to avoid function calls to improve performance. Are function calls in NinjaScript also costly? That is, should I avoid functional calls and use inline code? Thanks.
Regards
Ralph
Comment
-
To draw beyond the last bar you cannot use the Draw methods. You need to override the Plot method and just use C# drawing methods. Unfortunately this is completely outside of the scope of what we can offer support for. Suggest you check out MSDN or Google for more info.Josh P.NinjaTrader Customer Service
Comment
-
Ralph,
Currently I'm using inline code, but wanted to convert it to functions. However, I am reluctant to do it, because of performance issues that may arise while running this indicator in real-time, especially with Zen-Fire during high volume times. However, in anticipation of this, I did code my indicator to be pretty efficient in that if the last price does not change the Value Area or the Market Profile graphic then the code is not executed.
cls71,
Nice indicator! I'm currently using Pepe's VerticalScale indicator to handle the vertical scrolling. Without it, I would have the same issue as you. I think this indicator will help you with your indicator. Just search for it in the forum. I'm really hoping that NT adds this basic functionality in the near future.
Josh,
I appreciate your response, but must admit that it's frustrating to get a response like yours (i.e., this is outside the scope... search Google). I'd like to suggest that NT add the following functionality:- Flexibility in it's drawing tools to go beyond the last price on chart. In the meantime, I'll probably use a 1-min chart for Market Profile.
- Support vertical scrolling in native NT code. This is very important, in my opinion. Even TradeStation has this capability called "Background Dragging".
Comment
-
antonio,
NT7 will introduce many improvements in charting. Thank you for the suggestions. We will add it to the list of future considerations.
The reason we cannot support Plot method is simply because this is advanced C#. We just cannot teach this. We can offer support on NinjaScript and its methods, but advanced C# is just outside of what we have bandwidth to support. You can take a look at the CustomPlotSample indicator preinstalled on your NinjaTrader, but we really can't offer much more assistance in this regard.Josh P.NinjaTrader Customer Service
Comment
-
Hi Antonio,
I coded my project the other way around, strictly hierarchical regarding an object oriented point of view. But as stated already, the patterns are plotted to the canvas quite quick. It is not working with live data in the moment, that is what i am working on right now. Let's see how that behaves once finished.
So, before answering the main topic of your question I would like to ask a question: What methods do you use for plotting? The IndicatorBase.Draw-Methods? Or the Graphics-Functions in Plot()?
Regards
Ralph
Comment
-
Hi Antonio,
in that context there is nothing you can do. It is possible to draw into the future only in the context of the Plot() method. Which means you would have to convert your graphical calculations from price to canvas-points. However, you could have a look at the example below. It draws a horizontal line at the close of the CurrentBar just for 20 bars into the future.
Regards
Ralph
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Plot(Graphics graphics, Rectangle bounds, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] min, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] max)[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Pen linePen = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Pen(Color.Blue);[/SIZE][/FONT] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] priceRatio = (bounds.Bottom - bounds.Top) / (max - min);[/SIZE][/FONT] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] x1 = ChartControl.GetXByBarIdx(CurrentBar);[/SIZE][/FONT] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] x2 = x1 + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] * ChartControl.BarSpace;[/SIZE][/FONT] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] y = ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])Math.Round((max - Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) * priceRatio) + bounds.Top;[/SIZE][/FONT] [SIZE=2][FONT=Courier New] graphics.DrawLine(linePen, x1, y, x2, y);[/FONT][/SIZE] [SIZE=2][FONT=Courier New]}[/FONT][/SIZE] [/SIZE][/FONT]
Comment
-
Time axis
antonio, cls71,
the shape of market profiles can vary a lot, also in its horizontal dimension on the time axis. So, sometime it fits into the area of a trading session and sometime it doesn't. Did you guys found a way to control the horizontal dimension a trading session occupies? I am personally adjust that by changing the bar size of the data series (5min, 15min, 30min, ...) which is not satisfying anytime.
Regards
Ralph
Comment
-
Ralph,
I was trying this with a rectangle and it worked but my question is how do I draw from a bar in history. For example I want to draw from price bar 1. Seems like simply replacing CurrentBar with 1 in ChartControl.GetXByBarIdx(1) isn't the right way to do it. I tried (CurrentBar-X), X is some number and that sort of work but it shifts the whole rectangle. My code is below. How do I keep the rectangle going extending to the right boundary and also how can I plot multiple rectangles (and remove them) with this code. I appreciate your help on this. Thank you
protectedoverridevoid OnBarUpdate()
{
if(CurrentBar <1) return;
DrawText("tag3"+CurrentBar, "T"+CurrentBar, 1, High[0]+5, Color.Green);
}
publicoverridevoid Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
Pen linePen = new Pen(Color.Blue);
double priceRatio = (bounds.Bottom - bounds.Top) / (max - min);
int x1 = ChartControl.GetXByBarIdx(CurrentBar);
int y1 = (int)Math.Round((max - High[0]) * priceRatio) + bounds.Top; int h = (int)Math.Round((High[0] - Low[0]) * priceRatio) + bounds.Top;
Pen myPen = new Pen(Color.Red, 5);
SolidBrush myBrush = new SolidBrush(Color.FromArgb(100, 255, 0, 0));
Rectangle myRectangle = new Rectangle(x1, y1, bounds.Width,h);
graphics.FillRectangle(myBrush, myRectangle);
}
Comment
-
Hi jabeztrading,
if you follow my example, that should work as you expect. It is because x2 is just the value of x1 but shiftet by an fixed value, 20*ChartControl.BarSpace in this case.
when using the Plot() method, you don't need to remove your rectangles, just stop plotting them. In general, you could plot as much graphics as you desire.
Regards
Ralph
Comment
-
Originally posted by Ralph View PostHi jabeztrading,
if you follow my example, that should work as you expect. It is because x2 is just the value of x1 but shiftet by an fixed value, 20*ChartControl.BarSpace in this case.
when using the Plot() method, you don't need to remove your rectangles, just stop plotting them. In general, you could plot as much graphics as you desire.
Regards
Ralph
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Mestor, 03-10-2023, 01:50 AM
|
12 responses
307 views
0 likes
|
Last Post
by z.franck
Today, 04:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
32 responses
267 views
0 likes
|
Last Post
by f.saeidi
Yesterday, 06:49 AM
|
||
Started by Mestor, Today, 03:15 AM
|
0 responses
2 views
0 likes
|
Last Post
by Mestor
Today, 03:15 AM
|
||
Started by Padan, Today, 02:02 AM
|
0 responses
6 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
409 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
Comment