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 Objects Programmatically

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

    Drawing Objects Programmatically

    Hi quick question for an expert,

    I'm trying to use the DrawRay() method in a NinjaScript class to draw lines on a chart like so;

    Code:
     
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=black]IRay ray = DrawRay("tag1", 10, 1000, 0, 1001, Color.LimeGreen)[/COLOR][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

    but on compilation I get the error

    "The name DrawRay does not exist in the current context"

    I have the following using statements at the top of the code


    Code:
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.ComponentModel;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Diagnostics;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Drawing;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Drawing.Drawing2D;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Xml.Serialization;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Cbi;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Data;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Gui.Chart;[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT]
    and the following references

    Code:
     
    [FONT=Calibri][COLOR=#000000]Assembly[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Core.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Drawing.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Windows.Forms.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.XML.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Program Files (x86)\NinjaTrader 7\bin\NinjaTrader.Core.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Program Files (x86)\NinjaTrader 7\bin\WilsonORMapper.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\NinjaTrader.Vendor.dll[/COLOR][/FONT]

    Given that this is a Class definition and not an indicator is it possible to use the NinjaScript drawing objects in the way I propose. Have I missed a reference or using statement? Do I need to declare an Interface in some way? Could someone please show me how to use this drawing object.

    Thanks

    #2
    Hello Riskybiz,


    Can you send a toy* NinjaScript code replicating the behavior to support [at] ninjatrader [dot] com so that I may take a look at it? In the subject line put: ATTN: JC with reference to this thread.


    Happy to be of further assistance.

    *Toy - basically a stripped down version of code that isn't necessarily the whole logic. Making it easier to identify lines of code.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi,

      I have the same problem, but I do not see an answer posted to the original question.

      I am trying to use drawing methods in classes that I have created, like "DrawText". But I keep getting errors that "DrawText" is not found. I have included in the class definitions every using statement I that could think of.

      To work around the problem, I have been passing data from objects back up to their creator so that I can do drawing functions on the data in the indicator's OnBarUpdate method (drawing functions that really belong in lower level objects). This is getting real 'old'.

      What am I misssing? Can you help please?

      Tx!

      Comment


        #4
        Hello,

        Can you please attach your NinjaScript source code or simplified version which replicates the issue.

        File located in: (MY)Documents\NinjaTrader 7\bin\Custom\Indicator or Documents\NinjaTrader 7\bin\Custom\Strategy

        I look forward to assisting you further.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Originally posted by Riskybiz View Post
          Hi quick question for an expert,

          I'm trying to use the DrawRay() method in a NinjaScript class to draw lines on a chart like so;

          Code:
           
          [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=black]IRay ray = DrawRay("tag1", 10, 1000, 0, 1001, Color.LimeGreen)[/COLOR][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

          but on compilation I get the error

          "The name DrawRay does not exist in the current context"

          I have the following using statements at the top of the code


          Code:
           
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.ComponentModel;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Diagnostics;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Drawing;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Drawing.Drawing2D;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] System.Xml.Serialization;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Cbi;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Data;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] NinjaTrader.Gui.Chart;[/COLOR][/SIZE][/FONT]
          [/SIZE][/FONT]
          and the following references

          Code:
           
          [FONT=Calibri][COLOR=#000000]Assembly[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Core.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Drawing.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.Windows.Forms.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]System.XML.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Program Files (x86)\NinjaTrader 7\bin\NinjaTrader.Core.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Program Files (x86)\NinjaTrader 7\bin\WilsonORMapper.dll[/COLOR][/FONT][FONT=Calibri][COLOR=#000000]C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\NinjaTrader.Vendor.dll[/COLOR][/FONT]
          Given that this is a Class definition and not an indicator is it possible to use the NinjaScript drawing objects in the way I propose. Have I missed a reference or using statement? Do I need to declare an Interface in some way? Could someone please show me how to use this drawing object.

          Thanks
          You probably need to use the Indicator base class.

          Code:
           
          using NinjaTrader.Indicator;
          or else, use the SledgeHammer approach of calling the method by its fully qualified name:

          Code:
          [FONT=Courier New]
          NinjaTrader.Indicator.IndicatorBase.DrawRay([]parameters)
          [/FONT]
          Last edited by koganam; 01-07-2013, 04:37 PM.

          Comment


            #6
            Below is a graphic showing a simple indicator with an added test class and an attempt to draw text from the test class. The offending line is highlighted in yellow. The actual file for the simple indicator is attached as well.

            Attached Files
            Last edited by doctore; 01-07-2013, 06:44 PM. Reason: Add test indicator file

            Comment


              #7
              Hello,

              Thank you for providing the source code.

              While technically the use of your custom class is not something we support you could get around this by doing the following in your TestClass

              Code:
                  public class TestClass : Indicator
                  {
                      protected override void Initialize()
                      {
                      }
                      
                      protected override void OnBarUpdate()
                      {
                          DrawText    ("Tag", "Hello", 0, Low   [0], Color.Blue);
                      }
                  }
              Please let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by habeebft, Today, 07:27 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_ChristopherS  
              Started by AveryFlynn, Today, 04:57 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Max238, Today, 01:28 AM
              4 responses
              37 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by r68cervera, Today, 05:29 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by geddyisodin, Today, 05:20 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X