• 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

Trying to create a Draw.Text from within another drawing tool

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

    Trying to create a Draw.Text from within another drawing tool

    Hello everyone,

    I am an experienced programmer, but I am new to Ninjatrader development and I am trying to add additional Text-Boxes to the newly added "Path" drawing tool. An example mock-up of what I want to achieve can be seen here.


    So I have created my own drawing tool and basically copied the code of the Path tool over to my new tool and changed it's name appropriately. Everything is working fine so far. My new drawing tool behaves exactly like the Path tool and works fine.
    Now I wanted to add the automatic drawing of the text to it by using one of the Draw.Text constructors.
    However, the Text class needs an 'Owner' parameter, and since DrawingTools are apparently not derived from NinjaScriptBase, I was trying to just pass along the owner of my own drawing tool by using this.DrawnBy

    This is the exact line of code that I am using:
    Code:
    Draw.Text(this.DrawnBy, "Test", dataPoint.Price.ToString("0.00000"), 10, dataPoint.Price);
    Sadly, this doesn't work and throws an Assertion for a Null-Argument.


    After some digging, I found out that this.DrawnBy is always NULL.

    So here are my questions:
    - Why is the DrawnBy attribute of my DrawingTool never set?
    - Is there another way to get an appropriate NinjaScriptBase reference from within a drawing tool?
    - Is there any easier way to effectively chain two DrawingTools together so I can combine their functionality (just like I want to do with this tool)
    - Any general guidance in what I should do to achieve this?


    I appreciate any help you can provide


    (Also a short hint: Draw.Text seems to be the only DrawingTool from the Draw-Class that does NOT check weather Owner is NULL or not in it's Core constructor. All other classes check for it. Probably a tiny oversight?)

    #2
    Hello Laviic,

    In this case the Draw. partial class would only be for use in Indicators or Strategies, from the context of a DrawingTool you have OnRender. You would need to copy the SharpDX logic from the Draw.Text scripts OnRender into your script in order to draw text.

    - Why is the DrawnBy attribute of my DrawingTool never set?
    If you drew the tool manually, this should be null. This is only set if you have created a Draw. method of your own as a partial class, similar to the existing objects. When another script such as an indicator calls your object from code, it would be set to the instance of that NinjaScript object.

    - Is there another way to get an appropriate NinjaScriptBase reference from within a drawing tool?
    No, the suggestion would be instead to write your own OnRender logic. If you needed to call a DrawingTool, that should be done from an indicator or strategy.

    - Is there any easier way to effectively chain two DrawingTools together so I can combine their functionality (just like I want to do with this tool)
    No, you can use an indicator or strategy for this type of purpose. When working in a drawing object, you are at the lowest point in the chain, only the tools later in the chain would be able to mix using them together. An indicator would generally be where you see mixing of unique tools, you could draw text and draw a line for example.

    - Any general guidance in what I should do to achieve this?
    Really the best solution is to just copy/paste the parts of the text tool that you need. You can also see the indicator SampleCustomRender for some simplified examples of rendering text, its about 5 lines of code to render simple text in SharpDX. This would avoid having to pass the required bar data values that the Draw. syntax requires along with an owner.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the very quick and useful reply!
      I was initially trying to prevent copying the rendering parts from the Text tool over because I wanted to prevent "re-inventing the wheel" but if there is no other appropriate way of calling into that pre-existing code, I will just copy it over as well.
      Maybe I'll try playing around with some indicators too and see if that works for my use-case.

      Thank you very much!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by tricrland, Today, 12:58 AM
      0 responses
      1 view
      0 likes
      Last Post tricrland  
      Started by SAITON, Yesterday, 09:03 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by magnatauren, 07-12-2020, 02:20 PM
      4 responses
      29 views
      0 likes
      Last Post samcuran  
      Started by darkgreen, Yesterday, 03:35 PM
      1 response
      21 views
      0 likes
      Last Post lmatiukas  
      Started by imalil, Yesterday, 09:46 PM
      1 response
      10 views
      0 likes
      Last Post Epistemophilic  
      Working...
      X