Announcement

Collapse
No announcement yet.

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

  • dennho
    replied
    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

    Leave a comment:


  • eDanny
    replied
    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.

    Leave a comment:


  • dennho
    replied
    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.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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.

    Leave a comment:


  • dennho
    replied
    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.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    You're likely running into an issue explained in the following forum post from our Tips section:
    http://www.ninjatrader.com/support/f...ead.php?t=3170


    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.

    Leave a comment:


  • dennho
    replied
    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.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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?

    Leave a comment:


  • 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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by salination2, Yesterday, 07:21 PM
1 response
4 views
0 likes
Last Post s.kinra
by s.kinra
 
Started by aarons34, Yesterday, 08:11 PM
0 responses
6 views
0 likes
Last Post aarons34  
Started by Shiner452, Yesterday, 06:55 PM
0 responses
2 views
0 likes
Last Post Shiner452  
Started by Aquatrade, Yesterday, 06:22 PM
0 responses
3 views
0 likes
Last Post Aquatrade  
Started by trader3000a, Yesterday, 02:04 PM
2 responses
24 views
0 likes
Last Post trader3000a  
Working...
X