Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

freeze text in sample display bars ago

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

    freeze text in sample display bars ago

    Hi,

    In the example indicator sampledisplaybarsago the text move on the chart as you click on it. Is there a way i can create in the proprieties a choice that would allow me to freeze the text at a specific place in the chart?

    TY

    #2
    Hello frankduc,

    I'm not certain which reference sample this is. May I have a link to the help guide page in the reference samples where you have downloaded this?

    Draw.TextFixed() will draw text in a fixed location.


    You can also custom render text in OnRender() anywhere you would like.

    Simple script that adds a background watermark of the instrument symbol (and expiry if a future) to the chart. (Updated July 10th, 2018 ‐ The opacity needed to be casted as a double and divided by 100 to be between 0 and 1) (Update: August 24th, 2021 – Subtracted the ChartPanel.Y so indicator can be […]
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB,

      I dont have the original file anymore but there is that part of the script in the code:

      Code:
      else if (State == State.Configure)
      {
      //add event handler
      if (ChartControl != null) ChartControl.MouseUp += ChartControl_MouseUp;
      }
      {
      //remove event handler
      if (ChartControl != null) ChartControl.MouseUp -= ChartControl_MouseUp;
      }

      Code:
      private void ChartControl_MouseUp(object sender, MouseButtonEventArgs e)
      {
      //cause a refresh to poll after up click
      ForceRefresh();
      }

      Code:
      public override void OnRenderTargetChanged()
      {
      textBrush = Brushes.Lime.ToDxBrush(RenderTarget);
      }


      Code:
      if (IsInHitTest) return;
      if (ChartBars != null)
      {
      //get the X and Y point of the cursor and convert them to pixels
      int cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);
      int cursorPointY = ChartingExtensions.ConvertToVerticalPixels(chartCo ntrol.MouseDownPoint.Y, chartControl);
      Code:
      NinjaTrader.Gui.Tools.SimpleFont simpleFont = chartControl.Properties.LabelFont ?? new NinjaTrader.Gui.Tools.SimpleFont("Verdana.ttf", 12);
      
      // the advantage of using a SimpleFont is they are not only very easy to describe
      // but there is also a convenience method which can be used to convert the SimpleFont to a SharpDX.DirectWrite.TextFormat used to render to the chart
      // Warning: TextFormat objects must be disposed of after they have been used
      SharpDX.DirectWrite.TextFormat textFormat1 = simpleFont.ToDirectWriteTextFormat();
      
      // Once you have the format of the font, you need to describe how the font needs to be laid out
      // Here we will create a new Vector2() which draws the font according to the to top left corner of the chart (offset by a few pixels)
      SharpDX.Vector2 upperTextPoint = new SharpDX.Vector2(cursorPointX, cursorPointY);
      // Warning: TextLayout objects must be disposed of after they have been used
      
      //make a string of text
      string textString = "\nTime:" + timeValue.ToString("H:mm:ss");
      
      SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory, textString, textFormat1, ChartPanel.X + ChartPanel.W, textFormat1.FontSize);
      
      // With the format and layout of the text completed, we can now render the font to the chart
      RenderTarget.DrawTextLayout(upperTextPoint, textLayout1, textBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

      It allows to create a text in the chart that move when you click on any part of the chart.

      //make a string of text
      string textString = "\nTime:" + timeValue.ToString("H:mm:ss");

      I want to create something in proprieties that will freeze the text where i want in the chart. So i can use my indicator more than once in the chart. Right now the indicators superimpose on each other.


      TY

      Comment


        #4
        Hello frankduc,

        Unfortunately, I am not recognizing this reference sample.

        The mention of cursorPointX looks like it is involving the mouse cursor somehow so might be designed to react the mouse?

        That said, you do now have a working example of custom rendering text in a fixed location above.

        With Draw.TextFixed(), you can add "\r\n" to the string to add new lines.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        626 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        359 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        562 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        567 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X