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

x-value of current bar

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

    x-value of current bar

    Is it possible to get the x value of the current bar to us in order to plot text just to the right of the current bar? I have programming set up so the text is floating with price for the y-value but can't get it to scroll left and right as I scroll the chart left and right. The text is staying on the right side of the screen. Any ideas?

    #2
    Hello jhowinvest,

    Yes, this would be possible by overriding the plot method inside of NinjaTrader. This is not something that we can support but you can view the following references to help you get started with this.

    1. You may go to Tools -> Edit NinjaScript -> Indicators -> CustomPlotSample.

    2. Our File Sharing Section does have a few indicators that do this as well, one of which is at the following link.


    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks but I am still having trouble. This is a variation of the tick counter 3 in the file sharing section. The float with price is great for the y-value but I would like it to slide left and right as I manually scroll the chart. I did set up a private int called "marginValue" that will allow a person to change how far from the right margin the text prints but it is not dynamic like the y-value is.

      Here is the section of code if anyone wants to tackle this.

      // calculate x,y location for text display
      float x;
      float y;
      switch (DispLocation)
      {
      case DisplayLocation3.Float_with_price: //the x = line did say x = bounds.X + bounds.Width - ChartControl.BarMarginRight + 5;
      x = bounds.X + bounds.Width - ChartControl.BarMarginRight + marginValue;
      y = (int)(((bounds.Y + bounds.Height) - ((Close[0] - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height) - textHeight*0.4);
      if(ChartControl.BarMarginRight < textWidth-12)
      graphics.DrawString("Increase chart Properties - Right side margin", TextFont, textBrush, bounds.X + bounds.Width - noTickTextWidth, bounds.Y + bounds.Height - noTickTextHeight, stringFormat);
      break;

      Comment


        #4
        Hello jhowinvest,

        Thank you for your response.

        The ChartControl.BarMarginValue is based on the right side margin as you know, this means if you set the x value to this it will stay static in correlation to the bounds on the right side of the chart. If you would like the x value to stay at a point such as a bar on the chart does you will need to use something such as the bar it's self as the reference point and not the right side margin.

        Comment


          #5
          Thanks Patrick. I changed things around because I was making it too complicated. I used your advice and have it working now. I used draw text to keep the tick counter right near the current price bar. Thanks again. Basic code is below:

          int ticksRemaining = Bars.Period.Value - Bars.TickCount;
          Font textFont = new Font("Arial", textSize, FontStyle.Bold);

          if (Bars.Period.Id == PeriodType.Tick && printSymbol == true)
          {
          DrawText("tag1", false, "<" + ticksRemaining, 0 - counterOffset, Close[0], 0, textColor, textFont, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);

          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by stafe, 04-15-2024, 08:34 PM
          7 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          20 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Working...
          X