Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Text not showing to right

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

    Text not showing to right

    I've developed an indicator to draw lines. However, the text is displayed on the left side of the chart instead of to the right side of the line/chart.
    Below is the snippet of the code. Any idea what am I missing?

    if (double.TryParse(priceStr, out double levelPrice))
    {

    // Draw horizontal line
    NinjaTrader.NinjaScript.DrawingTools.Draw.Horizont alLine(
    this,
    label + "_" + levelPrice,
    levelPrice,
    Brushes.DarkOrange
    );

    // Draw label at the last bar (to the right)
    NinjaTrader.NinjaScript.DrawingTools.Draw.Text(
    this,
    "label_" + levelPrice,
    label,
    CurrentBar, // Position the label at the last bar
    levelPrice,
    Brushes.Red
    );​

    #2
    Draw.Text(NinjaScriptBaseowner,stringtag,stringtext,intbarsAgo,doubley,BrushtextBrush)​

    barsAgo is an offset from CurrentBar. When it's 0 the position is CurrentBar.

    Comment


      #3
      so, what is wrong? I had set as CurrentBar which is 0. Shouldnt it display the text on current bar?

      Comment


        #4
        No. From the article below,

        A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.

        If the CurrentBar is bar number 100, you are telling it to go back 100 bars ago.



        Comment


          #5
          how do i fix it? what should i specify for the barsAgo ?

          Comment


            #6
            Originally posted by ark321 View Post
            how do i fix it? what should i specify for the barsAgo ?
            CurrentBar is always the right most bar (newest). Since barsAgo is the offset (towards the oldest) from CurrentBar, when barsAgo is 0, it's pointing where CurrentBar is at.

            Comment


              #7
              what do i need to do display the text to the right?

              Comment


                #8
                sorry, got it.. let me try

                Comment


                  #9
                  actually, my code already has CurrentBar as an argument but the text is displayed on the left side

                  // Draw label at the last bar (to the right)
                  NinjaTrader.NinjaScript.DrawingTools.Draw.Text(
                  this,
                  "label_" + levelPrice,
                  label,
                  CurrentBar, // Position the label at the last bar
                  levelPrice,
                  Brushes.Red
                  );​​

                  Comment


                    #10
                    I tried with zero as barsago, as you see the label is displayed on the left. Something I'm missing here
                    Attached Files

                    Comment


                      #11
                      Ok, so barsAgo is an offset, but CurrentBar is the right most (Bars.Count-1) only in realtime state. I suppose you'd need to draw your label when State==State.Realtime or CurrentBar = Bars.Count-1.

                      Even if you make it work - it may not be what you want since once the label is drawn - it will be attached to that bar location. As new bars come in, the text will no longer be at the right side. To address that, you could delete old label and draw a new one above new CurrentBar once IsFirstTickOfBar​=true

                      Drawing in OnRender() via SharpDX would be more appropriate but more complicated.
                      Last edited by MiCe1999; 05-05-2025, 07:07 AM.

                      Comment


                        #12
                        is there a sample code for it?

                        Comment


                          #14
                          You can use this for reference: https://ninjatraderecosystem.com/use...belhorizlines/

                          Comment

                          Latest Posts

                          Collapse

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