Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

exception

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

    exception

    Hi,

    I have a drawline statement i use in a custom method which throws the following exception:

    Index was out of range. Must be non negative and less than the size of the collection. Parameter name: index

    Using the same code of block in e.g. on bar update works fine.

    whats the reason for this behaviour?

    regards

    #2
    Hello keepsimple,

    Thank you for your post.

    I would not expect that error at all. You should be able to use the NinjaScript call to Draw.Line() . Are you calling DrawLine() from SharpDX or Draw.Line() from NinjaScript? Can you provide a code snippet to demonstrate the custom method and it's use?

    Comment


      #3
      i am calling draw.line from ninjascript.

      i am using it in a foreach iteration, which loops through a collection called via the custom method.

      the drawline statement draws a line for each element in the collection.

      foreach(KeyValuePair<double, Item> item in Pair.Value)
      {
      Draw.Line(this, "" + item.Key, 10, item.Key,0, item.Key, Brushes.Blue); < exception
      Print("" + item.Key); < works perfectly
      }

      the rest of the code works fine. if i change the statement through a print statement, code works perfectly. so the exception is only thrown using the drawstatement,
      Last edited by keepsimple; 03-17-2016, 10:37 AM.

      Comment


        #4
        I created a new method and removed completely the rest of the code to check what the reason for this is.

        calling the method still produces the same exception.

        private void DrawLine()
        {
        Draw.Line(this, "Line", false, 10, 2000, 0, 2000, Brushes.Blue);
        }

        when I give startbar and endbar a negative value, it does not throw the exception, but draws a line at the first bar of the chart.

        regards

        Comment


          #5
          Hello keepsimple,

          I tested this with my own and see no errors. My code is below. What am I missing here that you are doing?
          Code:
          		protected override void OnBarUpdate()
          		{
          			if (CurrentBar <= 10)
          				return;
          			
          			TestDraw();
          		}
          		
          		private void TestDraw()
          		{
          			Draw.Line(this, "hello", 0, Close[0], 10, Close[10], Brushes.White);
          		}

          Comment


            #6
            calling the method from on bar update works on my end too.

            in my script i call the method from an mouse event, maybe thats causing the issue.

            is that somehow related? do i have to check something before calling the method?

            Comment


              #7
              I created a testindicator to narrow the issue down. see attached code.

              the code contains two ways of calling the drawline() method.

              calling from onbarupdate works fine.

              using the mouseevent the above mentioned exception is thrown.

              looking forward to your suggestions.

              regards

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Indicator here.";
              Name = "MyTestIndicator";
              Calculate = Calculate.OnBarClose;
              IsOverlay = true;
              DisplayInDataBox = true;
              DrawOnPricePanel = true;
              DrawHorizontalGridLines = true;
              DrawVerticalGridLines = true;
              PaintPriceMarkers = true;
              ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
              IsSuspendedWhileInactive = false;
              }
              else if (State == State.Configure)
              {

              }
              else if (State == State.Historical)
              {
              if (ChartPanel != null)
              ChartPanel.MouseDoubleClick += OnMouseDown;
              }
              else if (State == State.Terminated)
              {
              if (ChartPanel != null)
              ChartPanel.MouseDoubleClick -= OnMouseDown;
              }
              }

              private void OnMouseDown(object sender, MouseButtonEventArgs e)
              {
              DrawLine();
              }

              private void DrawLine()
              {
              if (CurrentBar < 10)
              return;
              Draw.Line(this, "hello", 0, Close[0], 10, Close[10], Brushes.White);
              }

              protected override void OnBarUpdate()
              {
              // if (CurrentBar < 10)
              // return;
              // DrawLine();
              }

              Comment


                #8
                Hello keepsimple,

                Thank you for your patience.

                We need to ensure there is a value to pass to the Draw.Line() method for the close values. I used the following system and it worked:
                Code:
                		private void OnMouseDown(object sender, MouseButtonEventArgs e)
                		{
                			if (draw) DrawLine();
                		}
                
                		private void DrawLine()
                		{
                		Draw.Line(this, "hello", 0, zero, 10, ten, Brushes.White);
                		}
                
                		protected override void OnBarUpdate()
                		{
                		 if (CurrentBar > 10)
                			 draw = true;
                		 else return;
                		 
                		 zero = Close[0];
                		 ten = Close[10];
                		}

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                213 views
                1 like
                Last Post PaulMohn  
                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                4 responses
                544 views
                0 likes
                Last Post PaulMohn  
                Started by GLFX005, Today, 03:23 AM
                0 responses
                3 views
                0 likes
                Last Post GLFX005
                by GLFX005
                 
                Started by XXtrader, Yesterday, 11:30 PM
                2 responses
                12 views
                0 likes
                Last Post XXtrader  
                Started by Waxavi, Today, 02:10 AM
                0 responses
                7 views
                0 likes
                Last Post Waxavi
                by Waxavi
                 
                Working...
                X