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

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 ScottW, Today, 06:09 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ScottWalsh, Today, 06:52 PM
        0 responses
        4 views
        0 likes
        Last Post ScottWalsh  
        Started by ftsc2022, 10-25-2022, 12:03 PM
        5 responses
        256 views
        0 likes
        Last Post KeyonMatthews  
        Started by Board game geek, 10-29-2023, 12:00 PM
        14 responses
        244 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Waxavi, 04-19-2024, 02:10 AM
        4 responses
        56 views
        0 likes
        Last Post sonia0101  
        Working...
        X