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

DrawingTool Bug

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

    DrawingTool Bug

    Hi,

    I have been working on a drawing tool. In that effort I have found 2 issues that I think are bugs. I modified the NinjaTrader @shapes drawing tool to include a few debug lines. See NinjaScript output panel for details.

    Issue #1: Draw a shape (rectangle). Then change the bar period (i.e. switch from 5 min to 15 min bars). While the new bars are "loading", the rectangle will disappear. This is because the Anchor point X value is set to -0.5. While loading the new bars, I can still change the zoom scale of the panel and indicators and bars work normally. Once the new bars load, the panel updates, drawn shapes and indicators update to the new bars. The issue is that the X value is set to -0.5 (off the left side of the panel) during the loading process. From the instant the bar period is changed. The X value should be defined based on the Anchor.Time value and its associated X value on the panel. If this was done, the Triangle, Rectangle and Ellipse shapes would not disappear while loading the new bar period.

    Issue #2: This issue is related to Issue Home and is intermittent (not consistent). When doing Market Replay, I found that the occasionally (don't know how to reproduce), the Start/End Anchor X value become negative (i.e. -1000 or other similar large negative number).


    I have traced both these issues back to the ChartAnchor dataPoint sent into the OnMouseDown, OnMouseMove & OnMouseUp methods.

    Any comments, help would be greatly appreciated.

    Thanks,

    JeffCO
    Attached Files

    #2
    Hello, thanks for writing in. Im not seeing any behavior here that is affecting the usability of the chart or drawing tool. This is a video of me switching the chart time frame and the Rectangle is being drawn with no issue.

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris,

      Thanks for looking into this.

      Try a timeframe that you don't have loaded and will take multiple seconds to load like 20000 Volume with 1000 bars data. During the time that the new data is loading the rectangle disappears. This is because the .X attribute of the point is set to -0.5 during this time.

      I have gone to effort to limit the effect of this behavior. However, it would be better if the X pixel value in the panel did not get set to an invalid number.

      If you run the shapeDB (debug) version I attached, you will see the temporary transition to -0.5 in the debug print to the output screen. Your screen loaded new data almost instantly since you had such limited historical data. Therefore, you did not see the behavior since there was no time that the data was "loading....".

      Thanks JeffCO

      Here is the video of the issue. I used the standard Rectangle tool



      Video using the Rectangle Debug version of the tool. This has the output screen showing the assignment of -0.5 to the X value during the load.

      Last edited by JeffCO7; 03-07-2023, 12:58 AM.

      Comment


        #4
        Hello, thanks for the follow up. This is expected to happen when loading the chart data. If the chart bars have yet to render, the indicator plots and drawing tools will not render because there is no available data.

        Kind regards,
        -ChrisL​
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Chris,

          Thank you.

          However, this is odd, expected behavior because:
          1. I can still zoom in/out of charts and bars and indicators still work and scale in and out of the panel while loading new data.
          2. It is just the drawing tools that don't work because of the odd value of X
          The Price, Time and Y Values are fine. It is just the X value that is corrupted.

          Q1: Is there a design reason that Drawing tools are disabled in this way during loading?


          In addition, I have a second unrelated question. I can break it into a separate post if necessary. Please advise.

          Q2: Is it possible to access the list of DrawObjects (DrawObjects.ToList() )in the OnRender method? When I try to compile it says the in OnRender I get an error: "The name DrawObjects does not exist in the current context"

          These are the lines I added to onRender.

          foreach (DrawingTool draw in DrawObjects.ToList())
          {
          if (draw is DrawingTools.JF_Zones)
          {
          DrawingTools.JF_Zones dzone = draw as DrawingTools.JF_Zones;

          // Indicates if this is a manually drawn or script generated line
          Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.IsUserDrawn);
          Print("Start: " + dzone.StartAnchor.SlotIndex + " End: " + globalLine.EndAnchor.SlotIndex);
          }
          }


          I have other code wrapping this to limits it execution to only when the Chartscale changes.

          JeffCO
          Last edited by JeffCO7; 03-08-2023, 12:17 AM.

          Comment


            #6
            Hello, thanks for the follow up.

            The Chart will destroy the current draw object in order to get ready to draw the object on the chart that is about to load. Since the chart time frame or instrument has been changed and removed everything on the chart is first destroyed.

            I am able to use the DrawObject collection from OnRender. I attached my test script. It is just a copy of the SampleCustomRender indicator and I added the foreach to the top of OnRender.

            Kind regards,

            -ChrisL
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chris,

              I do not see that you are using DrawObject.ToList(). It is the DrawObject call that gives me an error.

              I get the same error when I paste the lines of code from above in the OnRender section in your MyCustomRender.

              ​As a note: your MyCustomRender is an Indicator and not a DrawingTool. But hopefully that should not make a difference. I just don't know how Indicators and Drawing tools inherit differently from NT and if that makes a difference in what I can do in each. Probably not in this case.

              My goal/objective is to determine if manually drawn objects are above/below the edge of the chart panel (out of visibility and thus not drawn). If so, then I need to pull information from the nearest object (if more than one out of range) and use it to populate a label on the current chart panel.

              How do you suggest I access this information. I thought looking through DrawObject.ToList() was the way to go.

              Thanks JeffCO
              Last edited by JeffCO7; 03-08-2023, 10:15 AM.

              Comment


                #8
                Hello, thanks for the follow up. If you hover over the DrawObjects collection, the editor will show that it is part of the IndicatorRenderBase class, so this is not going to be available from a DrawingObject. The best practice would be to create your custom drawing tool, then use that drawing tool in an Indicator that has access to all other drawing tools on the chart.

                Kind regards,
                -ChrisL​
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Chris,

                  Is there any way to get information about other manually drawn objects from within the DrawingTool Class? Can I access other drawing tools in some way from within my current DrawingTool?

                  What I want to do is:
                  1. In my current DrawingTool, see if it is inside/outside the visible region of the panel (I can do this)
                  2. if outside, then I need to see if it is the closest DrawingTool to the panel. In this case I think I need to check all the manually drawn tools of my desired type (i.e. drawingtool.line) and, check its upper or lower price, then see if the current drawing tool is the closest to the edge of the panel. If so, I can draw a text label at the upper/lower edge of the panel with the upper or lower price of the current drawing tool.
                    1. Say for example I am drawing horizontal lines and label each line with the price. If a number of lines are above the highest price on the current chart view, then I would like to draw a text label at the upper edge of the chart with the price of the nearest out of range line. If I draw a label for all the lines, then they just draw on top of each other and the result is useless. "Trader Jim" did something similar in his labeled lines drawing tool. (see https://ninjatraderecosystem.com/use...s-drawing-tool) He put a background behind the label so it obscured any other labels. I would like to make sure the label displayed is only the closest line and not a random one of the offscreen lines.
                  All this depends on being able to query other manually drawn DrawingTools from within the current DrawingTool and determining their Min or max value (price).

                  Per your suggestion, I don't see how doing this in an indicator would help unless I created some type of global variable available between indicators and drawing tools on a chart. Not sure how to do that.

                  Any suggestions?

                  Thanks JeffCO
                  Last edited by JeffCO7; 03-08-2023, 12:45 PM.

                  Comment


                    #10
                    Hi Jeff, I found that you can use chartControl.ChartObjects collection to get all the objects on the chart. This includes all of the drawing objects so you can use this like you would use the DrawObjects collection:


                    One single indicator would be able to read all the draw objects on the chart using the DrawObjects collection, and indicators are also able to draw draw objects themselves so this would be a fairly straightforward solution for one chart (an indicator can only read data of the chart it is applied to).

                    Kind regards,
                    -ChrisL​
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Chris,

                      Thank you. That is awesome. I will give it a try. Thanks for sticking with me on this issue.

                      Thanks,

                      JeffCO

                      Comment


                        #12
                        Chris,

                        Sorry. This leads to an additional question. I don't see how to return the actual object to inspect.


                        Code:
                        // Loops through the DrawObjects collection via a threadsafe list copy
                        foreach (var x in chartControl.ChartObjects.ToList() )
                        {
                           Print( String.Format( "--- Chart Objects {0} Type: {1} Name: {2} " +
                               "Max: {3} Min: {4} ZOrder: {5} " +
                               "CPanel: {6} IsVisible: {7} x: {8}",
                             RenderCount, x.GetType(), x.Name,
                               x.MaxValue, x.MinValue, x.ZOrder.ToString(),
                               x.ChartPanel.ToString(), x.IsVisible.ToString(), x.ToString() ) );
                        }


                        I used the code above to pull the chart objects in a threadsafe list copy. I get the same information regardless if I use the ToLIst() or not. How do I access the actual chart object to inspect. Do I do some type of object transformation on x. Sorry, this may be where my lesser C# experience shows through.

                        Basically, if the GetType() returns "NinjaTrader.NinjaScript.DrawingTools.MyType" then I want to access that object and inspect some values.


                        Thanks,

                        JeffCO
                        Last edited by JeffCO7; 03-08-2023, 02:45 PM.

                        Comment


                          #13
                          Hi Jeff, you should be able to do it in the same way shown here with the DrawObject collection

                          https://ninjatrader.com/support/help...gtools_drawobj ects.htm

                          Try:
                          Code:
                          foreach(var x in chartControl.ChartObjects)
                          {
                           if (x is DrawingTools.HorizontalLine)
                           {
                            DrawingTools.HorizontalLine hLine = x as DrawingTools.HorizontalLine;
                          
                            Print("Found the line " + hLine.Name);
                          
                           }
                          }

                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Chris,

                            Thank you. That got me there. I tried a couple tests and found I can access each object properties. So I can cycle through and find if object are outside the chart view and if so, what is the closest value. This works. I appreciate all your help and going the extra mile.

                            Thanks,

                            JeffCO

                            Comment


                              #15
                              Hi Jeff, I'm happy to help take care.
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Started by Davidtowleii, Today, 12:15 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Davidtowleii  
                              Working...
                              X