Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Range displayed in ticks

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

    Range displayed in ticks

    Looking in the forum, i created an indicator to have the range expressed in ticks.

    I did what i read in the forum:

    To create a copy of the Range indicator, open a New > NinjaScript Editor window, open the Indicators folder, double-click the Range file, right-click in the code and select 'Save as', name the copy, and click OK. Once a copy is made, you could modify the copy.

    For example, the code may look something like this.

    Value[0] = (High[0] - Low[0]) / TickSize;

    I did it, i see the new indicator in Ninjascript editor window, but if i try to insert this new indicator in a chart (right click - indicators) i can't find it in "available window".

    ​Did i do something wrong?

    #2
    Hello Fra12,

    Thank you for your post.

    If your indicators are not showing up in the Available list then that suggests there is an issue with the indicators themselves. Specifically, there is likely an error in OnStateChange().

    Keep in mind that while it may compile successfully, the compiler cannot check "run time" logic errors, which can only occur when you run (or load) the strategy.

    A good first step here is to check the "Log" tab of the Ninjatrader Control center and look for any errors related to the indicators as if there is a run time error is would show in the log tab.

    If there are no log errors, check (in the Ninjascript editor open each strategy) to see if the indicators have the same name (IE you made a copy of the strategy and made your changes but unintentionally left the name the same as an existing one).

    In general, you want the filename of the strategy (this is what Ninjascript editor uses to open the script) to be the same as the public class name and most importantly that inside OnStateChange and within State.SetDefaults, the Name = field (This is what the drop-down or strategy selector uses) shows the same name as the public class name.

    Please let us know if you need further assistance.​

    Comment


      #3
      Hi Fra12,

      In "State.SetDefaults", you just need to set the "Name" to whatever you want. In this example, I set the "Name" to "Range_Tick". After that, you can find it in the "Indicator Settings" window.

      Please refer to the picture and the attached file below.

      Regards,
      William
      Attached Files
      Last edited by ninZa; 08-08-2024, 07:52 AM.
      ninZa
      NinjaTrader Ecosystem Vendor - ninZa.co

      Comment


        #4
        I opened Range indicator, save as RANGETICKS, changed formula, saved, i see the correct name in scripteditor list but i still can't see when i try to add it in a chart
        Attached Files

        Comment


          #5
          Hello Fra12,

          Are there any errors in the Log tab of the Control Center when you open the Indicators window from the chart?

          Comment


            #6
            No errors in The Log Tab

            Comment


              #7
              Hello Fra12,

              Would you mind sharing the script with us for testing?

              Comment


                #8
                Here it is:

                //
                region Using declarations
                using System;
                using System.Collections.Generic;
                using System.ComponentModel;
                using System.ComponentModel.DataAnnotations;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows;
                using System.Windows.Input;
                using System.Windows.Media;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Gui;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Gui.SuperDom;
                using NinjaTrader.Data;
                using NinjaTrader.NinjaScript;
                using NinjaTrader.Core.FloatingPoint;
                using NinjaTrader.NinjaScript.DrawingTools;
                #endregion

                // This namespace holds indicators in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Indicators
                {
                /// <summary>
                /// Calculates the range of a bar.
                /// </summary>
                public class RANGETICKS : Indicator
                {
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionRange;
                Name = "RANGETICKS";
                BarsRequiredToPlot = 0;
                IsSuspendedWhileInactive = true;

                AddPlot(new Stroke(Brushes.Goldenrod, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.RangeValue);
                }
                }

                protected override void OnBarUpdate()
                {
                Value[0] = (High[0] - Low[0])/TickSize;
                }
                }
                }

                region NinjaScript generated code. Neither change nor remove.

                namespace NinjaTrader.NinjaScript.Indicators
                {
                public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                {
                private RANGETICKS[] cacheRANGETICKS;
                public RANGETICKS RANGETICKS()
                {
                return RANGETICKS(Input);
                }

                public RANGETICKS RANGETICKS(ISeries<double> input)
                {
                if (cacheRANGETICKS != null)
                for (int idx = 0; idx < cacheRANGETICKS.Length; idx++)
                if (cacheRANGETICKS[idx] != null && cacheRANGETICKS[idx].EqualsInput(input))
                return cacheRANGETICKS[idx];
                return CacheIndicator<RANGETICKS>(new RANGETICKS(), input, ref cacheRANGETICKS);
                }
                }
                }

                namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
                {
                public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                {
                public Indicators.RANGETICKS RANGETICKS()
                {
                return indicator.RANGETICKS(Input);
                }

                public Indicators.RANGETICKS RANGETICKS(ISeries<double> input )
                {
                return indicator.RANGETICKS(input);
                }
                }
                }

                namespace NinjaTrader.NinjaScript.Strategies
                {
                public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                {
                public Indicators.RANGETICKS RANGETICKS()
                {
                return indicator.RANGETICKS(Input);
                }

                public Indicators.RANGETICKS RANGETICKS(ISeries<double> input )
                {
                return indicator.RANGETICKS(input);
                }
                }
                }

                #endregion

                Comment


                  #9
                  Hello,

                  This code you've posted is throwing several compile errors.

                  Since the actual code is very simple (one line in OnBarUpdate), I recommend simply creating a new indicator script by clicking the '+' button in the Editor > New Indicator.

                  From there, you can add your plot in the NinjaScript Wizard 'Plots and Lines' section. Click Generate, and then just add Value[0] = (High[0] - Low[0])/TickSize; into OnBarUpdate and compile.

                  Please let us know if you have any further questions.

                  Comment


                    #10
                    GREAT! Now it works, i can add it in the chart. I have last question: is it possible to see range value of last bar on the right of it as a number? See in attached, you can see tick counter (i use tick charts). Something like it.
                    Would be great!
                    Attached Files

                    Comment


                      #11
                      Hello Fra12,

                      We kindly ask that if you have a new inquiry unrelated to your initial post, that you instead post a new thread instead of replying the original thread. This will allow us to properly track each issue, and in the future people searching the forum people will be able to read relevant information for the post.

                      Any time you create a new thread, this will create a new inquiry and a new case ticket, which will be answered by the first person available and may not be the person you are previously working with. Create a new thread instead of a reply when you have a new question that is unrelated to a previous inquiry.

                      Thanks for your understanding.

                      Comment


                        #12
                        Just created new thread. Thank you very much.
                        Regards

                        Comment

                        Latest Posts

                        Collapse

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