Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RangeBarSinceSession

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

    RangeBarSinceSession

    Please check this pic ,I want to see Points instead of ticks which is 20 ticks= 1 point also want data to be 1 digit after decimal

    HTML Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("Enter the description of your new custom indicator here")]
        public class RangeBarsSinceSession : Indicator
        {
            #region Variables
            int barcount = 1;
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                
                Overlay				= true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
               	if (BarsArray[0].FirstBarOfSession)
    			{
    				barcount = 1;
    			}
    			double price;
    			if (barcount % 2 == 0)
    			{
    				price = High[0] + TickSize * 2;
    			}
    			else {price = Low[0] - TickSize * 2;}
    			
    			base.DrawText("txt" + CurrentBar,(Range()[0]/TickSize).ToString(),0,price,Color.Black);
            	barcount += 1;
    		}
    
            #region Properties
            
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        public partial class Indicator : IndicatorBase
        {
            private RangeBarsSinceSession[] cacheRangeBarsSinceSession = null;
    
            private static RangeBarsSinceSession checkRangeBarsSinceSession = new RangeBarsSinceSession();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public RangeBarsSinceSession RangeBarsSinceSession()
            {
                return RangeBarsSinceSession(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public RangeBarsSinceSession RangeBarsSinceSession(Data.IDataSeries input)
            {
                if (cacheRangeBarsSinceSession != null)
                    for (int idx = 0; idx < cacheRangeBarsSinceSession.Length; idx++)
                        if (cacheRangeBarsSinceSession[idx].EqualsInput(input))
                            return cacheRangeBarsSinceSession[idx];
    
                lock (checkRangeBarsSinceSession)
                {
                    if (cacheRangeBarsSinceSession != null)
                        for (int idx = 0; idx < cacheRangeBarsSinceSession.Length; idx++)
                            if (cacheRangeBarsSinceSession[idx].EqualsInput(input))
                                return cacheRangeBarsSinceSession[idx];
    
                    RangeBarsSinceSession indicator = new RangeBarsSinceSession();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    RangeBarsSinceSession[] tmp = new RangeBarsSinceSession[cacheRangeBarsSinceSession == null ? 1 : cacheRangeBarsSinceSession.Length + 1];
                    if (cacheRangeBarsSinceSession != null)
                        cacheRangeBarsSinceSession.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheRangeBarsSinceSession = tmp;
                    return indicator;
                }
            }
        }
    }
    
    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
        public partial class Column : ColumnBase
        {
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.RangeBarsSinceSession RangeBarsSinceSession()
            {
                return _indicator.RangeBarsSinceSession(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.RangeBarsSinceSession RangeBarsSinceSession(Data.IDataSeries input)
            {
                return _indicator.RangeBarsSinceSession(input);
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.RangeBarsSinceSession RangeBarsSinceSession()
            {
                return _indicator.RangeBarsSinceSession(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.RangeBarsSinceSession RangeBarsSinceSession(Data.IDataSeries input)
            {
                if (InInitialize && input == null)
                    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
    
                return _indicator.RangeBarsSinceSession(input);
            }
        }
    }
    #endregion

    #2
    Hello SLASH,

    Thank you for your note.

    You would need to format the value before drawing it on the chart. Such as using Math.Round: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Comment


      #3
      Please can anybody help me with this,I don't know about coding ?

      Comment


        #4
        Here is your modified code with an option to use whole ticks or points to one decimal place.

        Dan
        Attached Files
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 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