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

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 f.saeidi, Yesterday, 12:14 PM
      9 responses
      23 views
      0 likes
      Last Post f.saeidi  
      Started by Tim-c, Today, 03:54 AM
      0 responses
      3 views
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by FrancisMorro, Today, 03:24 AM
      0 responses
      3 views
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,772 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      31 views
      0 likes
      Last Post Max238
      by Max238
       
      Working...
      X