Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Previous Bar size (Need simple indicator)

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

    Previous Bar size (Need simple indicator)

    Hi guys I just need a simple indicator to show the size (in ticks or in points) of the previous bar. I have an indicator to show the size of the CURRENT bar (Blue circle).
    However, I would like to see the size of PREVIOUS BAR imprinted (orange circle) (and eventually disappear once a new "previous bar" formed, if that makes sense).

    I cannot edit this indicator as I can't access the script and I don't know how to code Please help. Thank you very much.

    Click image for larger version

Name:	Capture.png
Views:	2253
Size:	2.3 KB
ID:	1221831

    #2
    Hi AnnaM, thanks for posting. Can you please Export and post the indicator you are using to draw the value on the current bar? See here for instructions on exporting:



    Kind regards,
    -ChrisL

    Comment


      #3
      Hello Anna,

      For a quick programming challenge, I threw something together for you. Please see attached. I believe you can import this but you might need to compile it. I'm sure Chris can provide the proper instructions as I'm new to exporting/sharing NT code.

      There are three Properties:
      1. Number of Bars to show the bar size, including the current bar.
      2. Offset (in ticks) to show the bar size above the high of the bar.
      3. Font size (the font used is Arial).

      Below is the class code for anyone interested.

      Hope that helps!
      Matt

      ======================

      Code:
      public class AnnaBarSize : Indicator
      {
        private SimpleFont theFont;
        private const string BAR_SIZE_TAG = "barSize";
      
        protected override void OnStateChange()
        {
          if (State == State.SetDefaults)
          {
            Description = @"Displays the size of the last X bars.";
            Name = "AnnaBarSize";
            Calculate = Calculate.OnPriceChange;
            IsOverlay = true;
            DisplayInDataBox = false;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            PaintPriceMarkers = false;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
            //Disable this property if your indicator requires custom values that cummulate with each new market data event.
            //See Help Guide for additional information.
            IsSuspendedWhileInactive = true;
      
            NumberBars = 2;
            DisplayOffset = 4;
            FontSize = 10;
          ​}
          else if (State == State.Configure) {}
          else if (State == State.DataLoaded) {
              theFont = new SimpleFont("Arial", FontSize);
          }
       }
      
      protected override void OnBarUpdate()
      {
          if (IsFirstTickOfBar) {
              int barNumToRemove = CurrentBar - NumberBars;
              string barTagToNumRemove = BAR_SIZE_TAG + barNumToRemove;
              RemoveDrawObject(barTagToNumRemove);
          } else {
              int barSize = (int)(((High[0] - Low[0])) / TickSize);
              Draw.Text(this, BAR_SIZE_TAG + CurrentBar , true, barSize.ToString(), 0, High[0] + (DisplayOffset * TickSize), 0, Brushes.LightGray, theFont, TextAlignment.Center, Brushes.Transparent,         Brushes.Transparent, 0);
          }
      }
      
      [HASHTAG="t3322"]region[/HASHTAG] Properties
      [NinjaScriptProperty]
      [Range(1, 100)]
      [Display(Name="Number of Bars", Description="Including the current bar, how many bars to show the size. Max 100", Order=1, GroupName="Parameters")]
      public int NumberBars
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Display Ticks Offset", Description="Number of ticks from the bar high to display the bar size.", Order=2, GroupName="Parameters")]
      public int DisplayOffset
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Font Size", Description="Size of the font.", Order=3, GroupName="Parameters")]
      public int FontSize
      { get; set; }
      
      
      #endregion
      
      }
      
      ​
      Attached Files

      Comment


        #4



        Originally posted by StealthM93 View Post
        Hello Anna,

        For a quick programming challenge, I threw something together for you. Please see attached. I believe you can import this but you might need to compile it. I'm sure Chris can provide the proper instructions as I'm new to exporting/sharing NT code.

        There are three Properties:
        1. Number of Bars to show the bar size, including the current bar.
        2. Offset (in ticks) to show the bar size above the high of the bar.
        3. Font size (the font used is Arial).

        Below is the class code for anyone interested.

        Hope that helps!
        Matt

        ======================

        Code:
        public class AnnaBarSize : Indicator
        {
        private SimpleFont theFont;
        private const string BAR_SIZE_TAG = "barSize";
        
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Displays the size of the last X bars.";
        Name = "AnnaBarSize";
        Calculate = Calculate.OnPriceChange;
        IsOverlay = true;
        DisplayInDataBox = false;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = false;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cummulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        
        NumberBars = 2;
        DisplayOffset = 4;
        FontSize = 10;
        ​}
        else if (State == State.Configure) {}
        else if (State == State.DataLoaded) {
        theFont = new SimpleFont("Arial", FontSize);
        }
        }
        
        protected override void OnBarUpdate()
        {
        if (IsFirstTickOfBar) {
        int barNumToRemove = CurrentBar - NumberBars;
        string barTagToNumRemove = BAR_SIZE_TAG + barNumToRemove;
        RemoveDrawObject(barTagToNumRemove);
        } else {
        int barSize = (int)(((High[0] - Low[0])) / TickSize);
        Draw.Text(this, BAR_SIZE_TAG + CurrentBar , true, barSize.ToString(), 0, High[0] + (DisplayOffset * TickSize), 0, Brushes.LightGray, theFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
        }
        }
        
        [HASHTAG="t3322"]region[/HASHTAG] Properties
        [NinjaScriptProperty]
        [Range(1, 100)]
        [Display(Name="Number of Bars", Description="Including the current bar, how many bars to show the size. Max 100", Order=1, GroupName="Parameters")]
        public int NumberBars
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="Display Ticks Offset", Description="Number of ticks from the bar high to display the bar size.", Order=2, GroupName="Parameters")]
        public int DisplayOffset
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="Font Size", Description="Size of the font.", Order=3, GroupName="Parameters")]
        public int FontSize
        { get; set; }
        
        
        #endregion
        
        }
        
        ​
        Thank you so much!! This worked perfectly! Is there a way for me to change the font color though? As the light grey is barely visible on a white background
        But thank you very much. Appreciate this!

        Comment


          #5
          Hi Anna,

          Here's an updated version with a Points or Ticks selection and a font color option.

          It's the same name so I hope it will just replace the previous one when you load it.

          Kind regards,
          Matt

          ====

          Code:
          public enum AnnaBarSizePointsOrTicks { Points, Ticks };
          
          public class AnnaBarSize : Indicator {
             private SimpleFont theFont;
             private const string BAR_SIZE_TAG = "barSize";
             private double ptsOrTicksDivisor;
          
             protected override void OnStateChange() {
                if (State == State.SetDefaults) {
                   Description = @"Displays the size of the last X bars.";
                   Name = "AnnaBarSize";
                   Calculate = Calculate.OnPriceChange;
                   IsOverlay = true;
                   DisplayInDataBox = false;
                   DrawOnPricePanel = true;
                   DrawHorizontalGridLines = true;
                   DrawVerticalGridLines = true;
                   PaintPriceMarkers = false;
                   ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                   //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                   //See Help Guide for additional information.
                   IsSuspendedWhileInactive = true;
                   NumberBars = 2;
                   DisplayOffset = 4;
                   FontSize = 10;
                   PtsOrTicks = AnnaBarSizePointsOrTicks.Ticks;
                }
                else if (State == State.Configure) {}
                else if (State == State.DataLoaded) {
                   theFont = new SimpleFont("Arial", FontSize);
                   ptsOrTicksDivisor = PtsOrTicks == AnnaBarSizePointsOrTicks.Ticks ? TickSize : 1.0;
                }
          }
          
          protected override void OnBarUpdate() {
             if (IsFirstTickOfBar) {
                int barNumToRemove = CurrentBar - NumberBars;
                string barTagToNumRemove = BAR_SIZE_TAG + barNumToRemove;
                RemoveDrawObject(barTagToNumRemove);
             }
             else {
                double barSize = (High[0] - Low[0]) / ptsOrTicksDivisor;
                string barSizeDisplay = PtsOrTicks == NinjaTrader.NinjaScript.Indicators.AnnaBarSizePoin tsOrTicks.Ticks ? barSize.ToString("0") : barSize.ToString("0.00");
                Draw.Text(this, BAR_SIZE_TAG + CurrentBar, true, barSizeDisplay, 0, High[0] + (DisplayOffset * TickSize), 0, FontColor, theFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
             }
          }
          
          [HASHTAG="t3322"]region[/HASHTAG] Properties
          [NinjaScriptProperty]
          [Range(1, 100)]
          [Display(Name = "Number of Bars", Description = "Including the current bar, how many bars to show the size. Max 100", Order = 1, GroupName = "Parameters")]
          public int NumberBars { get; set; }
          
          [NinjaScriptProperty]
          [Display(Name = "Display Value", Description = "Select to show Points or Ticks", Order = 2, GroupName = "Parameters")]
          public NinjaTrader.NinjaScript.Indicators.AnnaBarSizePoin tsOrTicks PtsOrTicks { get; set; }
          
          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name = "Display Ticks Offset", Description = "Number of ticks from the bar high to display the bar size.", Order = 3, GroupName = "Parameters")]
          public int DisplayOffset { get; set; }
          
          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name = "Font Size", Description = "Size of the font.", Order = 4, GroupName = "Parameters")]
          public int FontSize { get; set; }
          
          [NinjaScriptProperty]
          [Display(Name = "Font Color", Description = "Color of the font.", Order = 5, GroupName = "Parameters")]
          public Brush FontColor { get; set; }
          
          #endregion
          
          }​
          Attached Files

          Comment


            #6
            Thank you so much Matt!

            Originally posted by StealthM93 View Post
            Hi Anna,

            Here's an updated version with a Points or Ticks selection and a font color option.

            It's the same name so I hope it will just replace the previous one when you load it.

            Kind regards,
            Matt

            ====

            Comment


              #7
              You're welcome, Anna! You and anyone else, let me know if there are any issues.

              Comment


                #8
                Hello I am interested in this indicator is there a way I can access it?

                Comment


                  #9
                  Hi deshawn, welcome in. I re-attached the sample that Stealth posted in case you can not download it from his post:


                  Kind regards,
                  -ChrisL
                  Attached Files

                  Comment


                    #10
                    Hi deshawn,

                    Glad your interested! Let me know if you have any issues or questions.

                    Thanks, NinjaTrader_ChrisL, for the re-post!

                    Kind regards,
                    Matt

                    Comment


                      #11
                      Originally posted by StealthM93 View Post
                      You're welcome, Anna! You and anyone else, let me know if there are any issues.
                      Can I bug you to make some updates to this?
                      My friend made this for Tradovate. It calculates the risk in $$ and changes colors based on high vs low risk. It also has a feature to add ticks. He adds 2 ticks, one for his stop entry and one for "one tick above" the signal bar.
                      Thoughts?
                      Attached Files
                      Last edited by spiketrades9; 04-10-2024, 05:43 PM.

                      Comment


                        #12
                        Hi spiketrades9,

                        Looks like you're asking for more of a strategy than indicator. For what you have in the screenshot, the indicator would need to know the trade sizing and $/point. Also, it appears that it is identifying the local tops/bottoms (or pivots). That's a rather involved request, more than a simple freebie to post here on the forum, in my opinion.

                        I wish you well,
                        Matt

                        Comment


                          #13
                          Originally posted by StealthM93 View Post
                          Hi spiketrades9,

                          Looks like you're asking for more of a strategy than indicator. For what you have in the screenshot, the indicator would need to know the trade sizing and $/point. Also, it appears that it is identifying the local tops/bottoms (or pivots). That's a rather involved request, more than a simple freebie to post here on the forum, in my opinion.

                          I wish you well,
                          Matt
                          For what its worth, I am unaware of the amount of work necessary. Thanks for letting me know. Can you help me understand why my NT freezes while adding the indicator to charts? It did not happen when I first downloaded but I can not load it anymore with out crashing.
                          Thanks
                          Last edited by spiketrades9; 04-13-2024, 09:47 AM. Reason: spelling

                          Comment


                            #14
                            Hello spiketrades9,

                            Assuming you mean my indicator above, I have no idea why that would cause NT8 to freeze or crash. The indicator is simple, straightforward.
                            You'll need to NT Support to help. Perhaps NinjaTrader_ChrisL?

                            Kind regards,
                            Matt

                            Comment


                              #15
                              Originally posted by StealthM93 View Post
                              Hello spiketrades9,

                              Assuming you mean my indicator above, I have no idea why that would cause NT8 to freeze or crash. The indicator is simple, straightforward.
                              You'll need to NT Support to help. Perhaps NinjaTrader_ChrisL?

                              Kind regards,
                              Matt
                              thank you for the help

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              579 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 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
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X