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

add a date to the time axis by the cursor

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

    add a date to the time axis by the cursor

    Hello,

    Is it possible to add a date to the time axis by the cursor (for minute charts)? I know it's not possible by default, my question is if it can be programmed?

    Thank you

    #2
    Hello emuns,

    It is not possible to draw in the scales but you could use an indicator to render text on the chart at various locations. You could in theory have an indicator use OnRender to draw times right above the scale.


    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Oh, yeah, I hadn't thought of that. Great idea! Thank you for your answer. And you mean put dates under each candle? Or could it be linked to the cursor movement, so the relevant text would only appear under the cursor (as it is with the default NT cursor)? But that would again be much more complicated...

      Comment


        #4
        Hello emuns,
        And you mean put dates under each candle?
        I had understood the question as by the mouse position but you could also put the dates under candles as well. You can get the cursor position using OnRender like the following: https://ninjatrader.com/support/help...lightsub=mouse
        Using the mouse click would be the best way to do that because a click makes the chart render to update the view. Moving the mouse is not necessarily something which OnRender could track along with to visualize as it moves because it has a variable refresh rate.



        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello emuns,

          It is not possible to draw in the scales

          Hello Jesse,

          I have a few more comments on the subject.

          1) You write that it is not possible to draw to scale, which was not my goal. My point is to be able to substitute the time for the date in the cursor, see the figure below. Would this be possible to program?

          2) Feature request - if not I would like the development team to think about it. This is useful for charts like 1440 minutes or 450 minutes (RTH sessions).

          3) I have attempted an indicator that would show the date below each bar, but unfortunately I get an error message in the Log, see below including that part of the script.Could I ask for help? I have no idea where the error could be. I seem to have everything OK...
          Indicator 'Datum': Error on calling 'OnRender' method on bar 327: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)

          {
          for (int index = Math.Max(1,ChartBars.FromIndex); index <= CurrentBars[0]; index++)
          {

          double widthOfPartBar1 = chartControl.GetBarPaintWidth(ChartBars) / 2.3;
          float offsetWidth1 = Math.Max(2f,(int)widthOfPartBar1);
          float xStart = chartControl.GetXByBarIndex(ChartBars, index);
          float xoff1 = xStart - offsetWidth1;
          float yStart = ChartPanel.H - 20;

          DateTime timeValue = Bars.GetTime(index);

          int day = (int)Time[index].Day;
          string dayString = day.ToString();
          int month = (int)Time[index].Month;
          string monthString = month.ToString();
          string dateString = dayString+"."+monthString+".";

          //TextLayouts

          // define the point for the text to render
          SharpDX.Vector2 startPoint1 = new SharpDX.Vector2(xoff1, yStart);

          // construct the text format with desired font family and size
          SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.Direct WriteFactory, "Arial", 18);

          // construct the text layout with desired text, text format, max width and height
          // SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory, timeValue, textFormat, ChartPanel.W, ChartPanel.H);
          SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory, dateString, textFormat, ChartPanel.W, ChartPanel.H);

          // create a rectangle which will automatically resize to the width/height of the textLayout
          SharpDX.RectangleF rectangleF1 = new SharpDX.RectangleF(xoff1, yStart, textLayout1.Metrics.Width, textLayout1.Metrics.Height);

          // define the brush used for the text and rectangle
          SharpDX.Direct2D1.SolidColorBrush customDXBrush1 = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.White);

          // execute the render target text layout command with desired values
          RenderTarget.DrawTextLayout(startPoint1, textLayout1, customDXBrush1);

          // always dispose of textLayout, textFormat, or brush when finished
          textFormat.Dispose();
          textLayout1.Dispose();
          customDXBrush1.Dispose();

          }
          }

          Comment


            #6
            Hello emuns,

            1) You write that it is not possible to draw to scale, which was not my goal. My point is to be able to substitute the time for the date in the cursor, see the figure below. Would this be possible to program?
            What you pictured is the scale which is not editable. You cannot render in that area or change the exiting renderings.

            2) Feature request - if not I would like the development team to think about it. This is useful for charts like 1440 minutes or 450 minutes (RTH sessions).
            What specifically are you requesting? That the date is listed in addition to the time always in the green area of the image?

            3) I have attempted an indicator that would show the date below each bar, but unfortunately I get an error message in the Log, see below including that part of the script.Could I ask for help? I have no idea where the error could be. I seem to have everything OK...
            The error is because you are trying to use BarsAgo instead of GetTime or GetValueAt on the series. The following which uses GetTime is correct where using Time[index] is not correct:

            DateTime timeValue = Bars.GetTime(index);

            int day = (int)Time[index].Day;

            Time[BarsAgo] would not work in OnRender, you could instead use Bars.GetTime(index); or Time.GetValueAt(index)

            The same applies to any series you use, you need to use GetValueAt to get a value in that series. The BarsAgo system is only applicable to OnBarUpdate, when using OnRender you are using indexes instead.


            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse,

              Originally posted by NinjaTrader_Jesse View Post
              What you pictured is the scale which is not editable. You cannot render in that area or change the exiting renderings.
              The reason I asked about the scale change was that it was possible in NT7, so I thought that in the more flexible 8s it would be possible too...

              Originally posted by NinjaTrader_Jesse View Post
              What specifically are you requesting? That the date is listed in addition to the time always in the green area of the image?
              Actually, two possibilities come to mind. Add the date to the time, or have the option if I want to display the time or the date. In fact, displaying the time on the charts I mentioned above makes no sense at all, as it is always the end time of a given session.

              Originally posted by NinjaTrader_Jesse View Post
              The error is because you are trying to use BarsAgo instead of GetTime or GetValueAt on the series. The following which uses GetTime is correct where using Time[index] is not correct:

              DateTime timeValue = Bars.GetTime(index);

              Time[BarsAgo] would not work in OnRender, you could instead use Bars.GetTime(index); or Time.GetValueAt(index)
              That is the problem. I have also tried GetTime (see above commented line), but the result is the same. In the indicator dialog in the InputSeries column, I still see Close instead of the instrument (see figure)...
              Attached Files

              Comment


                #8
                Hello,

                could I ask for help please? see above... thank you.

                Comment


                  #9
                  Hello emuns,

                  Thank you for your reply.

                  Jesse is currently out of the office, but I'm happy to assist.

                  As far as an option for the crosshairs to show the date, I've added a vote on your behalf to an existing feature request to have this option. This request is being tracked under the number SFT-606.

                  As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                  Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                  As far as your code goes, I think you may have misunderstood what Jesse was saying.

                  The following works for me and prints the date under each bar. I've bolded the lines I've changed:

                  Code:
                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {
                  for (int index = Math.Max(1,ChartBars.FromIndex); index <= CurrentBars[0]; index++)
                  {
                  
                  double widthOfPartBar1 = chartControl.GetBarPaintWidth(ChartBars) / 2.3;
                  float offsetWidth1 = Math.Max(2f,(int)widthOfPartBar1);
                  float xStart = chartControl.GetXByBarIndex(ChartBars, index);
                  float xoff1 = xStart - offsetWidth1;
                  float yStart = ChartPanel.H - 20;
                  
                  [B]DateTime timeValue = Time.GetValueAt(index);[/B]
                  
                  [B]int day = timeValue.Day;[/B]
                  string dayString = day.ToString();
                  [B]int month = timeValue.Month;[/B]
                  string monthString = month.ToString();
                  string dateString = dayString+"."+monthString+".";
                  
                  //TextLayouts
                  
                  // define the point for the text to render
                  SharpDX.Vector2 startPoint1 = new SharpDX.Vector2(xoff1, yStart);
                  
                  // construct the text format with desired font family and size
                  SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.Direct WriteFactory, "Arial", 18);
                  
                  // construct the text layout with desired text, text format, max width and height
                  // SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory, timeValue, textFormat, ChartPanel.W, ChartPanel.H);
                  SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory, dateString, textFormat, ChartPanel.W, ChartPanel.H);
                  
                  // create a rectangle which will automatically resize to the width/height of the textLayout
                  SharpDX.RectangleF rectangleF1 = new SharpDX.RectangleF(xoff1, yStart, textLayout1.Metrics.Width, textLayout1.Metrics.Height);
                  
                  // define the brush used for the text and rectangle
                  SharpDX.Direct2D1.SolidColorBrush customDXBrush1 = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.White);
                  
                  // execute the render target text layout command with desired values
                  RenderTarget.DrawTextLayout(startPoint1, textLayout1, customDXBrush1);
                  
                  // always dispose of textLayout, textFormat, or brush when finished
                  textFormat.Dispose();
                  textLayout1.Dispose();
                  customDXBrush1.Dispose();
                  
                  }
                  }
                  Basically, you were getting the error trying to reference Time[0] in the code. You'd have to instead use either Bars.GetTime(index) to actually get the time value or Time.GetValueAt(index) - both should return the same values.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, 04-17-2024, 06:40 PM
                  6 responses
                  49 views
                  0 likes
                  Last Post algospoke  
                  Started by arvidvanstaey, Today, 02:19 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  61 views
                  0 likes
                  Last Post samish18  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  21 views
                  0 likes
                  Last Post traderqz  
                  Working...
                  X