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

Draw Arrows not displaying on chart anymore, USED TO WORK! Now it doesn't!

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

    Draw Arrows not displaying on chart anymore, USED TO WORK! Now it doesn't!

    Alright so I was using this indicator to draw arrows for a rising condition checking if the Close was higher than the previous for green arrows, and if the close was lower than the previous, it would draw a red arrow. Also, I tagged on some other helpful conditions like Average Time per bar, if the average time per bar was very fast, then it would make the overall condition true.

    Anyways this code was working very well, then eventually it would disappear from my charts. I tried recompiling the charts and reloading the ninjascript by pressing F5. It wouldn't work. I even tried a reset and repair of the database. I removed all ninja script assemblies so the list is clear.

    Can anyone chime in on this?
    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 Breakout : Indicator
        {
        //    #region Variables
            // Wizard generated variables
            
                
                
            // User defined variables (add any user defined variables below)
         //   #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()
            {
         //       Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
        //        Overlay            = true;
            
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // go long condition
                if (Close[0] > Close[1])
                {
                    if( Close[1] > Close[2] &&
                         Stochastics(7, 21, 3).K[0] > Stochastics(7, 21, 3).D[0]
                        && AvgTimePerBar(.5,2).AverageTime[0] <=0.196
                        )
                    {
                               DrawArrowUp("Go long arrow" + CurrentBar, true, 0, Low[0] - 1, Color.Lime);
                    //        DrawLine("Go long line" + CurrentBar, 3, Low[0], 0, Low[0], Color.Lime);
                            if ( AvgTimePerBar(.5,2).AverageTime[0] < 0.196)
                            {    
                                DrawSquare("Go long" + CurrentBar, true, 0, Low[0] - 1, Color.Green);    
                            }    
                    }
                }//if
                // go short condition
                else if (Close[0] < Close[1])
                {
                     if     (Close[1] < Close[2]
                        && Stochastics(7, 21, 3).K[0] < Stochastics(7, 21, 3).D[0]
                        && AvgTimePerBar(.5,2).AverageTime[0] <=0.196
                        )
                    {
                        DrawArrowDown( "Go short?" + CurrentBar, false, 0, High[0]+1 , Color.DarkRed);
                //        DrawLine("Go short line"+CurrentBar,3,GetCurrentBid(),0,GetCurrentBid(),Color.DarkRed);
                        if ( AvgTimePerBar(.5,2).AverageTime[0] < 0.196)
                        {
                            DrawSquare( "Go short square?" + CurrentBar, false, 0, High[0] + 1, Color.Orange);    
                        }    
                    }
                }//else
            }//on barupdate
    
            #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 Breakout[] cacheBreakout = null;
    
            private static Breakout checkBreakout = new Breakout();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Breakout Breakout()
            {
                return Breakout(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Breakout Breakout(Data.IDataSeries input)
            {
                if (cacheBreakout != null)
                    for (int idx = 0; idx < cacheBreakout.Length; idx++)
                        if (cacheBreakout[idx].EqualsInput(input))
                            return cacheBreakout[idx];
    
                lock (checkBreakout)
                {
                    if (cacheBreakout != null)
                        for (int idx = 0; idx < cacheBreakout.Length; idx++)
                            if (cacheBreakout[idx].EqualsInput(input))
                                return cacheBreakout[idx];
    
                    Breakout indicator = new Breakout();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    Breakout[] tmp = new Breakout[cacheBreakout == null ? 1 : cacheBreakout.Length + 1];
                    if (cacheBreakout != null)
                        cacheBreakout.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheBreakout = 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.Breakout Breakout()
            {
                return _indicator.Breakout(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.Breakout Breakout(Data.IDataSeries input)
            {
                return _indicator.Breakout(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.Breakout Breakout()
            {
                return _indicator.Breakout(Input);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.Breakout Breakout(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.Breakout(input);
            }
        }
    }
    #endregion
    Keep in mind in the indicator properties, the panel is of course "same as input series".

    Perhaps I made a change to the code and was forgetful about it. I feel like I don't know what I'm doing, but I have been testing this indicator on different settings and charts. It would always work up until now.

    #2
    Hello,

    Are you receiving any errors on the Log tab of the Control Center related to this indicator? If so, what do these errors report?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Yes, it does seem that I'm getting yellow error lines that state:

      "Error on calling 'OnBarUpdate' method for indicator 'Breakout' on bar 0: You are accesing an index with a value that is invalid since its out of range."

      I wish I could copy paste it, would be easier but oh well.

      Comment


        #4
        You're likely running into an issue explained in the following forum post from our Tips section:



        Please try adding the following snippet to the beginning of your code in OnBarUpdate()
        Code:
        if (CurrentBar < 1)
        return;

        You need to ensure you have enough bars on the chart to calculate correctly.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Ok , I entered it like this:
          Code:
          protected override void OnBarUpdate()
          {
                      if (CurrentBar < 1)
                          return;
                      // go long condition
                      if (Close[0] > Close[1])
                      {
                          if( Close[1] > Close[2] &&
                               Stochastics(7, 21, 3).K[0] > Stochastics(7, 21, 3).D[0]
                              && AvgTimePerBar(.5,2).AverageTime[0] <=0.196
                             &nbsp;)
                          {
                                     DrawArrowUp("Go long arrow" + CurrentBar, true, 0, Low[0] - 1, Color.Lime);
                          //        DrawLine("Go long line" + CurrentBar, 3, Low[0], 0, Low[0], Color.Lime);
                                  if ( AvgTimePerBar(.5,2).AverageTime[0] < 0.196)
                                  {    
                                      DrawSquare("Go long" + CurrentBar, true, 0, Low[0] - 1, Color.Green);    
                                  }    
                          }
                      }//if
          ...
          I still don't see the draw objects, I recompiled the code and pressed F5 in the chart w/ the indicator still loaded. I don't understand why I still can't see the arrows, however I don't see any error messages in the log.

          Comment


            #6
            Hello,

            Did that resolve the error that was reported earlier?

            Do you see the other draw objects drawn?

            What symbol are you running this on? Are you sure of your calculation of Low[0] - 1? You may want to try converting that to 1 tick by using Low[0] - 1 * TickSize.
            MatthewNinjaTrader Product Management

            Comment


              #7
              No, there are still no arrows. There are no new errors in the log.
              I am using YM 03-12 on a 3 range candlestick chart.

              I guess I would have to convert to range? It is so odd that this code used to work on my range based chart all along, up until now.

              Edit: In the output window (not log tab), I still get the error:

              Error on calling 'OnBarUpdate' method for indicator 'Breakout' on bar 1: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

              Now I see where to copy/paste it from. Sorry I should have known this all earlier. Anyways I don't understand why I'm still getting this error despite the if (CurrentBar < 1) check.
              Last edited by dennho; 01-03-2012, 11:08 AM.

              Comment


                #8
                Try this:

                if (CurrentBar < 2)
                return;

                You are trying to look back to a bar when it is still not available.

                Dan
                Last edited by eDanny; 01-03-2012, 01:58 PM.
                eDanny
                NinjaTrader Ecosystem Vendor - Integrity Traders

                Comment


                  #9
                  Alright I got it to work from the slight change to '2'.

                  Thank you very much for your assistance.

                  I must be occasionally "defying logic" here, since I didn't have this check before... or I must have made some careless changes to my own code.

                  Alright take care then

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by proptrade13, Today, 11:06 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post proptrade13  
                  Started by kulwinder73, Today, 10:31 AM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by RookieTrader, Today, 09:37 AM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by terofs, Yesterday, 04:18 PM
                  1 response
                  24 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Started by CommonWhale, Today, 09:55 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Working...
                  X