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

Floating tick counter

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

    Floating tick counter

    Is there any way to fix this indicator to work on NT8?
    I keep getting errors and I'm still learning ninjascript.

    Thanks in advance

    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.NinjaScript.Indicators
    {
        /// <summary>
        /// Count down tick counter
        /// </summary>
        [Description("Count down tick counter")]
        public class sbTickCounter : Indicator
        {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            private double tickCount = 0;
            private double alertCntDn = 0;
    
            #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()
            {
            ChartOnly                = true;
            Overlay                    = true;
            CalculateOnBarClose     = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
            if (Bars == null)
                return;
    
    
            if (Bars.Period.Id == PeriodType.Tick)        //Check period ID = tick
    
            {
                int periodValue    = Bars.Period.Value;
                tickCount    =  periodValue - Bars.TickCount;
                alertCntDn = 0.05* Bars.Period.Value;                //set tick cont down threshold to change color of text display
    
                string sTicCnt = string.Format( "{0:####0}", tickCount);
    
                if ( tickCount >= alertCntDn )
                    DrawText("Count down",true, sTicCnt, -3, Close[0] + 3 * TickSize, 3, Color.Black, myFont, StringAlignment.Center, Color.Transparent, Color.Transparent,0);
                else
                    DrawText("Count down",true, sTicCnt, -3, Close[0] + 3 * TickSize, 3, Color.Red, myFont, StringAlignment.Center, Color.Transparent, Color.Transparent,0);
    
            }
                else
                DrawText("error text",true, "ERROR" , -3, Close[0] + 2 * TickSize, 3, Color.Red, myFont, StringAlignment.Center, Color.Transparent, Color.Transparent,0);
    
            }
    
            #region Properties
    
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private sbTickCounter[] cachesbTickCounter;
            public sbTickCounter sbTickCounter()
            {
                return sbTickCounter(Input);
            }
    
            public sbTickCounter sbTickCounter(ISeries<double> input)
            {
                if (cachesbTickCounter != null)
                    for (int idx = 0; idx < cachesbTickCounter.Length; idx++)
                        if (cachesbTickCounter[idx] != null &&  cachesbTickCounter[idx].EqualsInput(input))
                            return cachesbTickCounter[idx];
                return CacheIndicator<sbTickCounter>(new sbTickCounter(), input, ref cachesbTickCounter);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.sbTickCounter sbTickCounter()
            {
                return indicator.sbTickCounter(Input);
            }
    
            public Indicators.sbTickCounter sbTickCounter(ISeries<double> input )
            {
                return indicator.sbTickCounter(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.sbTickCounter sbTickCounter()
            {
                return indicator.sbTickCounter(Input);
            }
    
            public Indicators.sbTickCounter sbTickCounter(ISeries<double> input )
            {
                return indicator.sbTickCounter(input);
            }
        }
    }
    
    #endregion
    ​

    #2
    Hello oshri17,

    What errors are you seeing when using the script?
    JesseNinjaTrader Customer Service

    Comment


      #3
      Please see attached picture

      Comment


        #4
        Hello oshri17,

        It looks like you are missing most of the standard references at the top of the script. Please open the ADL indicator and copy the using statements from that script and replace the using statements you have in your script, then recompile. You may still have additional errors but that would be a starting point toward working through the errors. You generally need all of the standard using statements so it is not suggested to edit the using statements in the region Using declarations.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply.
          after doing that I got a lot more errors, most of them are the same.
          please let me know how to fix those
          Attached Files

          Comment


            #6
            Hello oshri17,

            It looks like the code you originally posted is for NT7, you would have to convert each of the items that are having errors to nt8 equivalent code. You can find a lot of these items on the code breaking changes guide: https://ninjatrader.com/support/help...ng_changes.htm

            I would suggest to remove this indicator and get back to a compiled state then create a new empty indicator using the NinjaScript editor. From there you can go line by line and copy 1 line at a time into the new script resolving each error as you go. One item to note is NT8 does not use the initialize override, that is replaced with OnStateChange and is listed in the code breaking changes guide. Another note is that Color.Black would be Brushes.Black.

            Drawing objects are also different now, it would be best to get the syntax from the help guide for the object in question and re code those parts.


            You can view NT8's built in TickCounter code for a lot of the other concepts that this is using.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you. I got this to work

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,611 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              6 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              22 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X