Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawDot not compiling

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

    #16
    I have figured out the areas that are not allowing the dot to be drawn, but in so doing, I think I found a more foundational error. The dot placement is WAY off.

    It appears that it has something do the calculation for "rangeHigh". If I hardcode a standard price in their, then the dot draws exactly where I code it to draw.

    I have taken this code from a sample that was generously made for me by Chelsea. It works great for the indicator, but apparently there needs to be something else if it is a strategy.

    This is supposed to find the highest high between the hours of 0200 & 0900.

    Variables:
    Code:
    		// Range Variables
            private DateTime startRange = DateTime.Today.AddHours(2); // Hour that the range will start
           	private int endRange = 090000; // Hour that the range will end
    		private int removeOrderTime = 2200; // Hour that unfilled orders will be removed
    		private double rangeHigh = 0; // High of range
    		private double rangeLow; // Low of range
    OnBarUpdate
    Code:
    rangeHigh = HighestBar(High, CurrentBar-Bars.GetBar(startRange));
    
    if(........)
    {
    DrawDot("EnterLongStop", true, 0, rangeHigh + pipBuffer, Color.Orange);
    }

    Comment


      #17
      I would then suggest printing the return you get from the rangeHigh calculation and see if you get your expected value - I suspect not, since the HighestBar method would return you no price based value (like MIN / MAX for example) but instead an integer value how many bars back that High / Low was found - you would then need to plug that value into the your price series to get an actual value you could plot alongside price that would then be meaningful.

      Comment


        #18
        You are definitely right.

        I am looking through the code that is used for the indicator and I can't really figure out what is happening differently, because this code works just fine:

        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;
        using System.Timers;
        #endregion
        
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
            [Description("Enter the description of your new custom indicator here")]
            public class HighBetweenTimesExample : Indicator
            {
                //#region Variables
        		private DateTime startTime = DateTime.Today.AddHours(2);
        		private DateTime endTime = DateTime.Today.AddHours(9);
        		private int highBarAgo = 0;
        		private int lowBarAgo = 0;
                //#endregion
        
                protected override void Initialize()
                {
                    Overlay				= true;
                }
        
        		protected override void OnStartUp()
        		{
        			ClearOutputWindow();
        		}
        
                protected override void OnBarUpdate()
        		{
        			if (CurrentBar != Bars.GetBar(endTime))
        				return;
        			
        			highBarAgo = HighestBar(High, CurrentBar-Bars.GetBar(startTime));
        			DrawDot("highestBar", true, highBarAgo, High[highBarAgo]+3*TickSize, Color.Green);
        			Print(CurrentBar-Bars.GetBar(startTime));
        			lowBarAgo = LowestBar(Low,CurrentBar-Bars.GetBar(startTime));
        			DrawDot("lowestBar", true, lowBarAgo, Low[lowBarAgo]-3*TickSize, Color.Red);
        		}
        
                //#region Properties
        		[XmlIgnore()]
        		[GridCategory("Parameters")]
        		[Gui.Design.DisplayNameAttribute("1 Start Time")]
        		public DateTime StartTime 
        		{
        			get { return startTime; }
        			set { startTime = value; }
        		}
        		
        		[Browsable(false)]
        		public string StartTimeSerialize 
        		{
        			get { return startTime.ToString("yyyy-MM-ddTHH:mm:sszzz"); }
        			set { startTime = DateTime.Parse(value); }
        		}
        		
        		[XmlIgnore()]
        		[GridCategory("Parameters")]
        		[Gui.Design.DisplayNameAttribute("2 End Time")]
        		
        		public DateTime EndTime 
        		{
        			get { return endTime; }
        			set { endTime = value; }
        		}
        		
        		[Browsable(false)]
        		public string EndTimeSerialize 
        		{
        			get { return endTime.ToString("yyyy-MM-ddTHH:mm:sszzz"); }
        			set { endTime = DateTime.Parse(value); }
        		}
                //#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 HighBetweenTimesExample[] cacheHighBetweenTimesExample = null;
        
                private static HighBetweenTimesExample checkHighBetweenTimesExample = new HighBetweenTimesExample();
        
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public HighBetweenTimesExample HighBetweenTimesExample(DateTime endTime, DateTime startTime)
                {
                    return HighBetweenTimesExample(Input, endTime, startTime);
                }
        
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public HighBetweenTimesExample HighBetweenTimesExample(Data.IDataSeries input, DateTime endTime, DateTime startTime)
                {
                    if (cacheHighBetweenTimesExample != null)
                        for (int idx = 0; idx < cacheHighBetweenTimesExample.Length; idx++)
                            if (cacheHighBetweenTimesExample[idx].EndTime == endTime && cacheHighBetweenTimesExample[idx].StartTime == startTime && cacheHighBetweenTimesExample[idx].EqualsInput(input))
                                return cacheHighBetweenTimesExample[idx];
        
                    lock (checkHighBetweenTimesExample)
                    {
                        checkHighBetweenTimesExample.EndTime = endTime;
                        endTime = checkHighBetweenTimesExample.EndTime;
                        checkHighBetweenTimesExample.StartTime = startTime;
                        startTime = checkHighBetweenTimesExample.StartTime;
        
                        if (cacheHighBetweenTimesExample != null)
                            for (int idx = 0; idx < cacheHighBetweenTimesExample.Length; idx++)
                                if (cacheHighBetweenTimesExample[idx].EndTime == endTime && cacheHighBetweenTimesExample[idx].StartTime == startTime && cacheHighBetweenTimesExample[idx].EqualsInput(input))
                                    return cacheHighBetweenTimesExample[idx];
        
                        HighBetweenTimesExample indicator = new HighBetweenTimesExample();
                        indicator.BarsRequired = BarsRequired;
                        indicator.CalculateOnBarClose = CalculateOnBarClose;
        #if NT7
                        indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                        indicator.MaximumBarsLookBack = MaximumBarsLookBack;
        #endif
                        indicator.Input = input;
                        indicator.EndTime = endTime;
                        indicator.StartTime = startTime;
                        Indicators.Add(indicator);
                        indicator.SetUp();
        
                        HighBetweenTimesExample[] tmp = new HighBetweenTimesExample[cacheHighBetweenTimesExample == null ? 1 : cacheHighBetweenTimesExample.Length + 1];
                        if (cacheHighBetweenTimesExample != null)
                            cacheHighBetweenTimesExample.CopyTo(tmp, 0);
                        tmp[tmp.Length - 1] = indicator;
                        cacheHighBetweenTimesExample = 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.HighBetweenTimesExample HighBetweenTimesExample(DateTime endTime, DateTime startTime)
                {
                    return _indicator.HighBetweenTimesExample(Input, endTime, startTime);
                }
        
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.HighBetweenTimesExample HighBetweenTimesExample(Data.IDataSeries input, DateTime endTime, DateTime startTime)
                {
                    return _indicator.HighBetweenTimesExample(input, endTime, startTime);
                }
            }
        }
        
        // 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.HighBetweenTimesExample HighBetweenTimesExample(DateTime endTime, DateTime startTime)
                {
                    return _indicator.HighBetweenTimesExample(Input, endTime, startTime);
                }
        
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.HighBetweenTimesExample HighBetweenTimesExample(Data.IDataSeries input, DateTime endTime, DateTime startTime)
                {
                    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.HighBetweenTimesExample(input, endTime, startTime);
                }
            }
        }
        #endregion
        Anyway, it leaves me now at a bit of a loss. I am sure that MIN/MAX should be used in this equation somehow and have gone through and read their documentation to see if it could give me some insight. Basically I am not able to figure out, though, how I would actually say, "return the highest high within a particular range of time" I have also gone through the entire NinjaScript keyword library word for word to see if there is something there that would help me along the way. Undoubtedly I have missed something, or am making it harder than it actually is, but I can not find anything that will help me get that value.

        Comment


          #19
          Hello Jg123,

          What you would want to do is check when the Bar Time is at the end range. You could then run the HighestBar test for the range back to the start time.

          if(Time[0] == endTime)
          {
          //run highest bar calculations here
          }
          Cal H.NinjaTrader Customer Service

          Comment


            #20
            Thank you

            Here is my new update.

            I created a new int called theHigh
            Code:
            			if (ToTime(Time[0]) == endRange)
            			{
            				theHigh = HighestBar(High, CurrentBar-Bars.GetBar(startRange));
            				rangeHigh = MAX(High, theHigh)[endRange];
            			}
            With this I am attempting to say, "find the highest bar between the startRange & endRange and name it theHigh. After that, find the high of the 'theHigh' and name assign that to the double of 'rangeHigh'"

            When I run this code, the Output window is giving me this:

            **NT** Error on calling 'OnBarUpdate' method for strategy 'LondonBreakout/0773bca4a71446b0bdd7dd9354706f48': 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.
            With that, I assume that I need to check to make sure there are enough bars to insure that the code will properly run. Therefore, I added this:

            Code:
            			if (Time[0] != endRange)
            				return;
            I attempted to say, "if the time is not equal to endRange, then move on to the next bar. But if it is equal, then continue to run the code."

            With this, I get this error:

            Operator '!=' cannot be applied to operands of type 'System.DateTime' and 'int'
            I then tried to change it to a ToTime() in order to get around the System.DateTime but that returned the same error message.

            Now I am at a wall. Can you help me with where to go next? Could you also please let me know if I am thinking through these correctly so that I can improve my debugging skills (and hopefully pester you guys even less in the nearer future *smile*)?

            Comment


              #21
              jg123, I'm surprised the code you have posted would have even compiled, since GetBar would always need a DateTime to work on, perhaps you changed from prior versions.

              I think you more seek a snippet like the below to work this condition out -

              if (ToTime(Time[0]) == endRange)
              {
              startTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 5, 0, 0);
              theHigh = HighestBar(High, CurrentBar - Bars.GetBar(startTime));
              rangeHigh = High[theHigh];
              }

              The MAX in your code would not be really needed, since we already get HighestBar index back to work with, we just have to plug it into the High series as index to get / convert this info to a price based value then.

              Debugging in art and skill formed during the time you spent with various codes, you really want to make sure to isolate things as finely as needed (and if it means getting that one very basic print confirmation of a value), as oftentimes we introduce our expectations into code processing that shouldn't be there unless confirmed 100%. As this can get very time consuming and involved working with custom scripts and the infinities of C# and NinjaScript there's limited support we can offer in that area, as it would create bandwidth issues for our team assisting our wide client base equally well and with the efficiency you've come to expect from us.

              Comment


                #22
                The code that you gave me worked but as I got to adjusting other things, it stopped working. I have no idea why and did everything I could think of to go back to they way it originally way.

                Anyway, I figured out a different way of making it work too. Had to change the variables in order to do so. Plus, I spent some time figuring out how to do more with the charts. Attached is a pic of that. It puts an arrow over the bar that was the High or the Low of the range and gives the theoretical entry price.

                There is another issue that is coming up in the code, but that is a different topic so will post that in another forum.
                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 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