• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

B6 - DrawObjects and OnRender

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

    B6 - DrawObjects and OnRender

    I'm experiencing several new issues in B6 when trying to use DrawObjects in OnRender..

    1st Issue..
    DrawObjects no longer in ChartObject Collection after compile and Refresh NinjaScript

    http://www.screencast.com/t/pyu0xqxcLKu


    a follow-up and yet another issue
    OnRender Drawings Selectable and Allow Deletion which Removes Indicator

    http://www.screencast.com/t/UkZnkWp8nnqo


    and yet another issue just as bad, or worse
    DrawObjects get transferred across Charts when changing Instruments

    http://www.screencast.com/t/IVNMJflxpgFk


    Please Advise


    -=Edge=-
    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

    #2
    This post was meant to be placed in the Issues and Bugs Thread.. If you would be so kind as to move it there please..


    -=Edge=-
    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

    Comment


      #3
      Hello,

      I'm on the case -- I'm going to dig in to these issues this afternoon, and I will post back with any updates.
      Dave I.NinjaTrader Product Management

      Comment


        #4
        I am not able to reproduce the first issue, but perhaps I'm going about it differently than you are. Here is how I am testing:

        Code:
                protected override void OnBarUpdate()
                {
                    foreach (var obj in ChartControl.ChartObjects)
                    {
                        Print(obj.GetType().ToString());
                    } 
                }
        
                protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                {
                    base.OnRender(chartControl, chartScale);
                    TextFixed myTF = Draw.TextFixed(this, "line1", "hello", TextPosition.BottomLeft);
        
                    NinjaTrader.NinjaScript.DrawingTools.Line myLine = Draw.Line(this, "line", 10, High[10], 5, High[5], Brushes.Green);
                }
        Using that code, the drawing objects remain in the collection after a compile + refresh, and I can filter based on drawing object type to detect only the objects I'm looking for. If you are going about it a different way, can you share a snippet that shows your process?

        For the second item, you can set the AllowRemovalOfDrawObjects property to True in State.SetDefaults to prevent the NS object from being terminated.

        For the third item, this is to be expected, although it is understandable how it can be confusing at first, since the behavior appears to be inconsistent with manually drawn objects at first glance. When you draw an object manually, it is attached to an instrument, but when you draw an object in NinjaScript, it is actually attached to a chart panel. The logic involved in drawing an object in NinjaScript relies on whatever instrument/bars may be on the chart panel, rather than any specific instrument.

        Consider the way that drawing objects are often used as buy/sell indications as an example of why this is important. If someone writes a script which draws a dot above each doji bar, as a very simple example, then it would be desirable for these objects to be redrawn each time a new instrument is loaded. When drawing objects are conditional (such as a dynamically drawn trend channel), then they should be serving their purpose on any instrument on which the script is configured.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          I believe there was a little confusion on the issues I was trying to outline in my original post above. These have since been discussed, and I wanted to follow up with the response I received in order to possibly get the views and opinions of others that might have the same concerns as myself on these issues.

          Everything I was trying to point out has to do with Manually Drawn Objects, finding those objects in an indicators OnRender, and then manipulating and/or using them, and/or their anchors. (Example: to RederTarget.Draw?? something (Text Labels, Parallel Lines, Extensions, Ranges, whatever) in OnRender using SharpDX).. This same type of concept was provided as a possible work around solution to adding alerts to manually drawn objects thru an indicators code in another thread as well.


          But to try and keep this as simple as possible.. Let's consider a very simple indy that finds and labels all manually drawn horizontal lines on a chart.. Code Sample Provided..

          Issue 1:
          Any indicator like this (using this concept to find and use manually drawn objects) Will No Longer Work after Re-Compiling Any Script and Refreshing NinjaScript on the Chart it is applied to!

          NT's Response:
          This is expected behavior. After a recompile of any script, a brand new custom.dll is loaded and any new drawing tools (manually drawn objects in this case) are coming from the new dll. But, any old or existing drawing tools are still and remain instances from the old dll. These old instances although having the same type name, are actually of a different type that is neither assignable nor castable.


          To get a better idea of what this means to you, Download and apply the enclosed indicator to a any chart. Open an Output window so you can observe the printed problem. Draw a horizontal line anywhere on your chart and you'll notice it now has a price label on the far right. Now reload ninjascript on that chart, or add another indy, or do almost anything and Notice all is still good and fine, with everything working as expected.

          But Now recompile any script in the editor (doesn't matter what one) and then refresh ninjascript on the chart you applied the indy too, or switch back and forth between instruments, or change the charts interval, or open the indicators property window and click ok, or anything that would cause the chart's scripts to refresh..

          Notice now the labels for any pre-existing horizontal lines are now gone! and notice the print statement in the output window (the object is still found in the drawing objects collection, it's just no longer castable).. Now Draw another horizontal line on your chart.. Notice it does label any new horizontal lines drawn.. But the only way to get those old labels back, is to either close your workspace and/or ninjatrader and reopen. (or I guess you could also delete every existing manually drawn object and redraw them all )..

          This is a ball buster for me personally, and will be for many many of my customers as well... I use and manipulate manually drawn objects extensively thru script for all types of things.. (to label, dynamically change color/styles, custom draw extensions, fibs, harmonics, ranges, dynamic profiles, and really just to many things to list). With the way things currently are, anyone using this type of code on a chart is pretty much being forced Not to make any type of code changes what so ever (for any reason), if that chart might ever need refreshed, instrument/interval changed, add/change indy or its properties, etc.. and you want your indy to continue to work and function properly..


          NT: Please Please consider changing and/or finding a solution to this behavior now before it's too late and/or it's to much work to do so in the future..


          As you might can tell, I'm rather passionate about this particular issue, and would really like to hear any comments others in the community might have as well..

          If I'm alone in my concerns regarding this, so be it, I'll just have to figure out a way to personally work around this issue, and put out a disclaimer to my customers for any product I have using this type of code, so that they fully understand the new limitations of NT8..




          Edit: Added Code to Indy as suggested by Dave to Solve Issue 2
          Attached Files
          Last edited by -=Edge=-; 11-05-2015, 12:36 PM.
          -=Edge=-
          NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

          Comment


            #6
            Issue 2:
            Objects Drawn with SharpDX in OnRender (RenderTarget.Draw??) of an indicator can be selected and deleted!

            NT's Response:
            Still Waiting..


            It was not possible to select and/or delete an object that was drawn in NT7's Plot Override. Nor do I believe this is possible thru anything drawn in onrender of a NT8 drawing tool.. Although Currently this is not the case with a NT8 indicator and OnRender..

            Take the horizontal line label indy from the previous post.. Apply it to a chart and draw a horizontal line.. Click on the text label that is created on the far right and then hit your delete key.. Not only does the Render drawn text object get deleted, but the entire indicator gets removed from the chart without any type of notice and/or confirmation..

            Very Much Undesirable.. You'll notice in the indy code that AllowRemovalOfDrawObjects is set to false in state.defaults.. But even changing this to true still allows the removal of the indy without notice.. But then I'm still not sure why that property would make any difference to a RenderDrawn object anyway..

            I can see some uses and possible benefits to allowing onrender drawn objects from an indicator to be manually deleted, but not to the detriment of removing the indy, and something like this would also definitely have to have the ability to be set to either allow or not allow selection/deletion.. As personally, in most or the majority of cases, I do not want users to have any type of access to these type of drawn objects at all..



            Issue 3:
            I solved this by using the IsVisible property in the if clause of the provided indy..



            -=Edge=-
            NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

            Comment


              #7
              Thank you. I do have some good news on Item # 2. (I should note firstly that a SharpDX drawn item cannot be selected and deleted like a NinjaScript Drawing Object on my end, but it can be double-clicked to open the Indicators window).

              There is a bool named IsInHitTest which will return True when a user has clicked one of your SharpDX drawn items. There is an example you can see in our @VolumeProfile indicator, on line 179, in which IsInHitTest is checked, and if true, the code returns out of OnRender. This prevents the item from being double clicked to open the Indicators window (or interacted with in any way). Here is a sample that is working for me from an Indicator:

              Code:
              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                      {
                          if (IsInHitTest) return;
              
                          RenderTarget.DrawLine(point0, point1, Brushes.Blue.ToDxBrush(RenderTarget));   
                      }
              On the main point #1, we are currently investigating a potential solution for this, so please stay tuned.
              Dave I.NinjaTrader Product Management

              Comment


                #8
                Originally posted by NinjaTrader_Dave View Post
                Thank you. I do have some good news on Item # 2. (I should note firstly that a SharpDX drawn item cannot be selected and deleted like a NinjaScript Drawing Object on my end, but it can be double-clicked to open the Indicators window).
                Thanks Dave, It doesn't show, reflect, or in no way can you tell it's selected, but from my end, if I just click on the text, assume it's selected, and hit delete.. both the text and indy were removed..

                But here nor there, your provided solution worked like a champ, and issue 2 can be considered resolved..

                Since others might find this indy usefull, I've both modified/replaced the code in my original post with the appropriate code fix..So if you previously downloaded it, just Re-Download again from the original post above and overwrite the one you grabbed earlier..


                Originally posted by NinjaTrader_Dave View Post
                On the main point #1, we are currently investigating a potential solution for this, so please stay tuned.

                Thank You So Much! Any type of resolution to this issue would be greatly appreciated!


                -=Edge=-
                NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                Comment


                  #9
                  I'm happy to report that we've resolved the primary issue with existing drawing objects not being included in a newly generate Custom.dll, and you should see the fix applied in the upcoming Beta 7 build. Please keep this issue in mind to test when Beta 7 is released.
                  Dave I.NinjaTrader Product Management

                  Comment


                    #10
                    Originally posted by NinjaTrader_Dave View Post
                    I'm happy to report that we've resolved the primary issue with existing drawing objects not being included in a newly generate Custom.dll, and you should see the fix applied in the upcoming Beta 7 build. Please keep this issue in mind to test when Beta 7 is released.
                    It would only let me give you one thanks.. so let me say this..

                    Thank You, Thank You, .. Thank You, Thank You... And Thank You Again!!!



                    -=Edge=-
                    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                    Comment


                      #11
                      Originally posted by -=Edge=- View Post
                      It would only let me give you one thanks.. so let me say this..

                      Thank You, Thank You, .. Thank You, Thank You... And Thank You Again!!!



                      Well folks, let us pile on the thanks for this one!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by PatrickM, Today, 08:43 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post PatrickM  
                      Started by horace chow, Today, 04:00 PM
                      3 responses
                      16 views
                      0 likes
                      Last Post bltdavid  
                      Started by PrimoItch, Today, 04:35 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post PrimoItch  
                      Started by Serge A, Today, 04:03 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post Serge A
                      by Serge A
                       
                      Started by JBTrader2005, Today, 03:57 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post JBTrader2005  
                      Working...
                      X