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

Drawing on Multi Instrument Charts

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

    Drawing on Multi Instrument Charts

    I have developed (with a great deal of help from Ninja support) an indicator which draws rectangles on the price panel. The indicator makes use of Lists to manage when and where the rectangles are drawn (eg where they stop drawing in time).

    The indicator has worked fine for some time, and now I wish to employ the indicator on a chart containing more than one data series (ie multiple instruments). When I add the indicator to such a chart, no rectangles are drawn at all.

    Any hints about where I might start looking for problems? The code is only a dozen lines or so. I have a hunch the issue has to do with telling the indicator which pane/instrument is being processed. Ultimately, if possible, I'd like the rectangles to be drawn for each instrument.

    EDIT: Upon closer inspection, I just noticed something that might be useful in troubleshooting. When the indicator is running properly, the rectangles will redraw and extend themselves to the right on each bar update, until some logic is met which stops the drawing. What is actually happening now is that each rectangle does draw, but only for a single bar and then it stops drawing, never extending.
    Last edited by coolmoss; 02-01-2013, 04:25 PM.

    #2
    Hello Coolmoss,

    Thank you for your post.

    I recommend using Print statements for each condition with time stamps to indicate to you which condition is causing this item.

    For information on debugging your NinjaScript code please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3418

    For information on using Time in your code please visit the following link: http://www.ninjatrader.com/support/h...s/nt7/time.htm

    For information on multiple instrument s and time frames in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Hello and thanks for your help, Patrick. I'm familiar with the usual debugging approaches and using print statements liberally, but in this case I don't even know where to begin, as there doesn't appear to be anything wrong with the very few lines of code present. I've placed the entire code of a "toy indicator" below to show you the issue. This toy plots rectangles starting at the first bar of the session and extends them all the way to current bar. It works just fine with only one instrument in the chart. Add a second instrument and the rectangles stop after one bar.

      Code:
       protected override void OnBarUpdate()
              {
      			if (CurrentBar < 6)
      				return;
      			
                  foreach (IRectangle draw in rects)
      			{
      					draw.EndBarsAgo = 0;
      			}
      			
      			if (Bars.FirstBarOfSession)   
      			{
      				temp = DrawRectangle(CurrentBar.ToString(),false,1,Open[1],0,Close[1],Color.Empty,Color.Blue,1);
      				rects.Add(temp);
      			}
      			return;
              }

      Comment


        #4
        I tried placing a Print statement in the For Each loop, printing out the properties of each rect object. I compared the x and y coordinates, and the StartBar and EndBar numbers with and without 2 data series in a chart.

        The output window showed identical output. So, to be clear: the output window shows rectangle objects with different properties than those actually being drawn. Does this not suggest a bug?

        Comment


          #5
          Still working on it, and found this post (http://www.ninjatrader.com/support/f...37&postcount=5)

          which related to DrawRegion. Can someone from Ninja post the correct parameter signature for DrawRectangle when using multiple data series? Thanks.
          Last edited by coolmoss; 02-02-2013, 02:14 PM.

          Comment


            #6
            Hello,

            The drawn object will plot to the primary series. Because of this it's typically a good idea to isolate the draw object to the primary series so that your values are correct (not required though)

            Whenever you want to draw the object
            Code:
            DrawRectangle("myTag"+CurrentBar, false,1,Open[1],0,Close[1],Color.Empty,Color.Blue,1);
            There isn't reason to use a loop as this will get called each time there is a bar update

            Please let me know if I can be of further assistance.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Lance View Post
              Hello,

              The drawn object will plot to the primary series. Because of this it's typically a good idea to isolate the draw object to the primary series so that your values are correct (not required though)

              Whenever you want to draw the object
              Code:
              DrawRectangle("myTag"+CurrentBar, false,1,Open[1],0,Close[1],Color.Empty,Color.Blue,1);
              There isn't reason to use a loop as this will get called each time there is a bar update

              Please let me know if I can be of further assistance.
              Lance, thanks, I have read what you suggest but it really doesn't address my problem. First, I need to use the loop because what I sent you is only a subset of my actual code, but a subset that illustrates the problem. Also, each drawing object needs to be updated each bar in order to extend the draw object to the current bar. The approach I'm using was provided to my by Ninja Support Adam.

              Secondly, while what you say regarding the object being plotted to the primary series may be correct, if that were the case then my code would function correctly; which it does not.

              To reiterate: the code works perfectly fine as is, IF the chart contains only one data series. If I add a second data series, the draw objects do not redraw correctly.

              So, I need further instruction as to what might be wrong. At this point, it appears that there is a bug.
              Last edited by coolmoss; 02-04-2013, 12:46 PM.

              Comment


                #8
                Hello,

                Every time any one of your added series calls the OnBarUpdate() it appears the draw is being called



                DrawRectangle(CurrentBar.ToString(),false,1,Open[1],0,Close[1],Color.Empty,Color.Blue,1);

                CurrentBar.ToString() will work when dealing with a single series but in this case you will end up having multiple rectangles with the same name if you are not isolating it to a single BIP

                Try changing this to "my tag"+CurrentBar

                Additionally don't use
                Code:
                if (CurrentBar < 6)
                    return;
                In a multi-series script
                Use something like

                Code:
                // Checks to ensure all Bars objects contain enough bars before beginning
                     if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired)
                          return;
                LanceNinjaTrader Customer Service

                Comment


                  #9
                  Lance,

                  This is NOT a multi series indicator. It's simply an indicator in a chart with more than one data series. Again, I stress the indicator works perfectly fine with a single series in the chart. I did try changing the draw parameters as you suggested, but that made no change.

                  So, I'm still stuck where I was before: indicator works just fine in chart with a single data series, but draws incorrectly when a second series is added.

                  Comment


                    #10
                    Hello,

                    I apologize for the misunderstanding. Do you have a complete .cs file that I may test which replicates the error?

                    Located in: (MY) Documents\NinjaTrader 7\bin\Custom\Indicator
                    LanceNinjaTrader Customer Service

                    Comment


                      #11
                      TestDraw.csNo need for apology, I'm most thankful for your help. I know it's not always easy communicating accurately online. I've attached the .cs file.

                      First, run it with a single series and you'll see the rectangles will draw to the current bar. Make sure you have at least a few days of data in chart, the rectangles will draw a zone from first bar of session to current bar.Then add a second data series. What you'll see (might have to really zoom in) is that the rectangles only draw for a single bar.

                      I've tried every trick I know and experimented with changing how the parameters are constructed and even how I create the chart, all to no avail. I'm really stumped on this one.

                      Comment


                        #12
                        Hello,

                        I have tested this on my end and I have replicated your issue.

                        I believe this is a limitation of the way in which NinjaTrader adds additional series by using existing chart series to save memory.

                        I know you could work around this by overriding the Plot()
                        This would be unsupported by us but you can view some examples within some of our system indicators: http://www.ninjatrader.com/support/h...om_drawing.htm

                        I have not tested but I would suspect this could also be worked around by making this a multi series script so that it handled the bar spacing properly. (this would not be optimal as the script would have to be designed for the added series)

                        I am going to forward this to development and let you know when I hear back from them and if they think my assumption is correct.
                        LanceNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,235 views
                        0 likes
                        Last Post sidlercom80  
                        Started by thread, Yesterday, 11:58 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post thread
                        by thread
                         
                        Started by jclose, Yesterday, 09:37 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,415 views
                        0 likes
                        Last Post Traderontheroad  
                        Working...
                        X