Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Rectangle error

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

    Draw.Rectangle error

    Hello,

    I am using a variable: DateTime Start; to draw a line through an indicator. When I use the same variable to draw a rectangle, I get this error message and I don't understand why: Indicator 'MyIndicator': Error on calling 'OnBarUpdate' method on bar 0: "NinjaTrader.NinjaScript.DrawingTools.Rectangl e startTime must be greater than the minimum Date but was 01/01/0001 00:00:00".

    Here is the syntax:
    Draw.Line(this, "MyLine ", false, Start, Price1, End, Price1, IsGlobal, template);
    Draw.Rectangle(this, "Myrectangle ", Start, Price1, End, Price2, IsGlobal, template);

    Thank you​

    #2
    Hello amart74,

    Thanks for your post.

    This indicates that your Draw.Rectangle() startTime parameter (Start) is returning a date/time of 01/01/0001 00:00:00 and you must use a time greater than the minimum Date.

    How are your Start and End time inputs being defined in the script?

    I have attached an example script for your to view that creates a user-defined StartTime and EndTime input and uses the input for the startTime and endTime parameter when calling Draw.Rectangle(). You could compare this script to yours to see where the differences might be.

    Draw.Rectangle(): https://ninjatrader.com/support/help...=draw.rectangl e
    Time: https://ninjatrader.com/support/help...eries_time.htm

    Let me know if I may assist further.​
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Here's how I define the inputs:

      if(Bars.GetDayBar(1) != null)
      {
      Start = Bars.GetDayBar(1).Time;
      End = Time[0].AddDays(1);
      }

      That's where I don't understand because the variables are correctly assigned when I draw a line but the problem occurs for the rectangle even though it's the same.

      Comment


        #4
        Hello amart74,

        Thanks for your note.

        After looking investigating this behavior we have found that the Draw.Line() method that places a Line Drawing Object on the chart has an inconsistency that does not throw the error message when a time before 1/1/1800 12:00:00 AM is used.

        The @Sha​pes Drawing Tool that defines a Rectangle Drawing Object when Draw.Rectangle() is called has better logic and an error message when a time before 1/1/1800 12:00:00 AM is used.

        This inconsistency has been reported to the Development team so that they may work on a fix for this. The ticket number for this is QA-6003.

        To correctly use Draw.Line() and Draw.Rectangle() you must provide a Start/End time that is greater than the minimum date 1/1/1800 12:00:00 AM.

        Please let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your response.

          However, I want to emphasize that my variable has no prior assignment before 1/1/1800 12:00:00 AM when I draw a line ! For example, today it should correspond at the date to the last candle of yesterday at 07/02/2023 23:00:00. That's the case so the line works correctly because the date is greater than 1/1/1800 12:00:00 AM. When i display the date/time it is the good one but when i use rectangle with the same value i get an error. Would it not be better to use what you call the inconsistency of the Draw.Line() method in the Draw.Rectangle() method because it works very well...

          Thank you.
          Last edited by amart74; 02-08-2023, 07:49 AM.

          Comment


            #6
            Hello amart74,

            Thanks for your note.

            When adding the code you shared in post # 3 into a test script and printing out those values before calling the Draw.Line and Draw.Rectangle methods, once the script is added to the chart the print shows these values are evaluating as Start: 1/1/0001 12:00:00 AM | End: 1/1/0001 12:00:00 AM. You would need to ensure that a valid time is being assigned to these variables before using them in your Draw methods.

            See this attached screenshot.

            You could print out the Start and End time variables 1 line above your Draw methods to see how the Start and End DateTime variables are evaluating in your script.

            Let me know if I may assist further.
            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hello and thank you for your attention to my problem.

              We don't understand each other. I have already printed the variables and they are valid (greater than 1/1/1800 12:00:00 AM).​

              My code with 5 Days load :

              if(Bars.GetDayBar(1) != null)
              {
              start = Bars.GetDayBar(1).Time;
              Print("START "+start);
              end = Time[0].AddDays(1);
              Print("END "+end);
              }

              See this attached screenshot for output.

              I then use these variables for the Draw.Line() method :

              Draw.Line(this, "MyLine ", false, Start, Price1, End, Price1, IsGlobal, template);
              See this attached screenshot for result.

              The start and end are the same in the last two lines of the output as the Start Y and End Y for my line.
              Now when I use Draw.Rectangle(this, "Myrectangle ", Start, Price1, End, Price2, IsGlobal, template); with same variables and same assignment I get this error message.

              Im confused.


              Attached Files

              Comment


                #8
                Hello amart74,

                Thanks for your note.

                I have tested the code you shared and added a CurrentBar print to your Start and End prints. I have also added a print 1 line above the Draw methods to see how the Start and End times are evaluated before the Draw methods are called. The Draw methods are commented out for initial testing purposes.

                if(Bars.GetDayBar(1) != null)
                {
                start = Bars.GetDayBar(1).Time;
                Print("START "+start + " " + CurrentBar);
                end = Time[0].AddDays(1);
                Print("END "+end + " " + CurrentBar);
                }​

                Print("Before calling Draw methods " + " Start: " + start + " | End: " + end + " " + CurrentBar);
                //Draw.Line(this, "Line", true, start, Close[10], end, Close[0], Brushes.DodgerBlue, DashStyleHelper.Solid, 2);
                //Draw.Rectangle(this, "Rectangle", start, Close[10], end, Close[0], Brushes.DodgerBlue);​


                When looking at the prints in the Output window, we can see that the first print that appears indicates that the 'start' and 'end' variables are evaluating with a time of 1/1/0001 12:00:00 AM up to bar 1379 on an ES 03-23 1-Minute Chart.

                On bar 1380, the condition to assign a value to the 'start' and 'end' variables triggers on bar 1380 and the prints show:

                Before calling method Start: 1/1/0001 12:00:00 AM | End: 1/1/0001 12:00:00 AM 1379
                START 2/3/2023 3:00:00 PM 1380
                END 2/6/2023 4:01:00 PM 1380


                See the attached screenshot.

                ​This means that when the script is applied to a chart, the 'start' and 'end' variables are not assigned a valid time value until bar 1380 in this case which is causing the error to occur.

                Something you could consider doing to ensure these variables are assigned a valid time to use for Draw.Rectangle() and Draw.Line() is creating a condition that checks if start.ToString() != "1/1/0001 12:00:00 AM" and checks that end.ToString() != "1/1/0001 12:00:00 AM". See below.

                if (start.ToString() != "1/1/0001 12:00:00 AM" && end.ToString() != "1/1/0001 12:00:00 AM")
                {
                Draw.Line(this, "Line", true, start, Close[10], end, Close[0], Brushes.DodgerBlue, DashStyleHelper.Solid, 2);
                Draw.Rectangle(this, "Rectangle", start, Close[10], end, Close[0], Brushes.DodgerBlue);
                }


                Let me know if I may assist further.​
                Attached Files
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  Using the impressions you used in your last answer, I was able to find the solution. As my indicator does not have a new day on the bar 0 the problem came from the following test :

                  if(Bars.GetDayBar(1) != null)
                  {
                  Start = Bars.GetDayBar(1).Time;
                  End = Time[0].AddDays(1);
                  }​

                  I fixed it by adding :

                  else
                  {
                  Start = Bars.GetTime(1);
                  }

                  Thanks for your help, it's always frustrating to not want to do what you want as you want and when you want in coding !

                  Thanks for your help​​

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Net_Trader, 03-15-2023, 03:17 PM
                  16 responses
                  174 views
                  0 likes
                  Last Post Net_Trader  
                  Started by Vern10, Today, 10:51 AM
                  4 responses
                  25 views
                  0 likes
                  Last Post Vern10
                  by Vern10
                   
                  Started by HalTech, Today, 02:11 PM
                  2 responses
                  31 views
                  0 likes
                  Last Post HalTech
                  by HalTech
                   
                  Started by Gianpiero, Today, 01:41 PM
                  1 response
                  13 views
                  0 likes
                  Last Post NinjaTrader_Ray  
                  Started by josh18955, Today, 11:16 AM
                  1 response
                  16 views
                  0 likes
                  Last Post Leeroy_Jenkins  
                  Working...
                  X