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!
See more
See less

Partner 728x90

Collapse

Question for Market Profile Indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Click image for larger version

Name:	MP-Letters.GIF
Views:	1
Size:	51.2 KB
ID:	890949

    Click image for larger version

Name:	MP-Lines.GIF
Views:	1
Size:	35.3 KB
ID:	890950

    #2
    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.

    Comment


      #3
      Originally posted by antonio View Post
      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.
      Difficult to answer. Do you have the impression that your code is consuming to much resources during runtime? Putting code into functions makes the code more readable but may introduce some additional runtime effort. I am coding something similar shown in your pictures but the profile graphics is plotted rather quick to the canvas.

      Regards
      Ralph

      Comment


        #4
        I coded one similar indicator, but my major problem is with the vertical zoom.
        If the difference between high & low in the window are very wide, the indicator is unusable.

        This is an image of the indicator (here the difference is narrow).

        Comment


          #5
          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


            #6
            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:
            1. 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.
            2. Support vertical scrolling in native NT code. This is very important, in my opinion. Even TradeStation has this capability called "Background Dragging".
            Is it possible that these features may become available in the upcoming NT 7.0? Some of the NT limitations starts to become apparent when writing a complex indicator like Market Profile. Please take these comments in the positive manner that they were intended. Thanks.

            Comment


              #7
              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


                #8
                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


                  #9
                  Originally posted by Ralph View Post
                  What methods do you use for plotting? The IndicatorBase.Draw-Methods? Or the Graphics-Functions in Plot()?
                  Hi Ralph, I'm using DrawText() and DrawLine().

                  Comment


                    #10
                    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


                      #11
                      Thanks Ralph, your suggestion and sample code helps me out a lot. Much appreciated.

                      Comment


                        #12
                        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


                          #13
                          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


                            #14
                            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


                              #15
                              Originally posted by Ralph View Post
                              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
                              Thank you Ralph. Now I understand it a little better.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bmartz, 03-12-2024, 06:12 AM
                              4 responses
                              31 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              12 views
                              0 likes
                              Last Post Aviram Y  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              3 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by cls71, Today, 04:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X