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

Calling Draw.Line and Draw.Ray from an external class

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

    Calling Draw.Line and Draw.Ray from an external class

    Hi there. How can I call Draw.Line and Draw.Ray from an external class? I currently have code that successfully calls Draw.ArrowUp, Draw.ArrowDown, Draw.Diamond, etc. from an external class however Draw.Line and Draw.Ray do not resolve/compile. I ask because I have a considerable amount of custom line and ray drawing logic that works correctly when executed directly within an indicator however I want to replicate that logic across many indicators without creating copies of the logic (in other words, only have it within the external class). Thanks!

    #2
    Hello caryc123,

    Thanks for your post.

    An AddOn script could be created if you want to use a method or variable that can be used within multiple indicators or strategies. You would create the variables and/or methods using a partial class that can be accessed from all indicators and strategies.

    You could find information about partial classes and sample code on the help guide page below.


    Information about creating partial classes in C# could also be found on the forum thread linked below.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your helpful links. I resolved my issue however have have follow-on questions to make sure I don't create long-term issues.

      My issue was not related to creating an external class (I already have that successfully working), instead my issue related to basic draw methods such as Draw.ArrowUp or Draw.Text fully resolving correctly however more advanced draw methods such as Draw.Line and Draw.Ray didn't fully resolve (the Draw part resolved however Line and Ray didn't resolve).

      I created a basic external class (detailed below) and noticed that when its file is placed within NinjaTrader's AddOns folder Draw.Ray and Draw.Line fully resolve correctly. That led me to think I must be missing a dependency/reference within my shared custom project that houses my custom/external class. I then compared dependencies/references within the NinjaTrader.Custom project and my shared custom project and noticed that although my shared custom project referenced NinjaTrader.Vendor.dll there was no reference to NinjaTrader.Custom.dll. After adding a reference to NinjaTrader.Custom.dll to my shared custom project the Line and Ray methods resolved however Visual Studio (my IDE) complained Draw existed within both NinjaTrader.Custom.dll and NinjaTrader.Vendor.dll. I then removed the reference to NinjaTrader.Vendor.dll from my shared custom project and Draw.Line and Draw.Ray fully resolved correctly. So, my issue has been resolved, and moral of the story, to use Draw.Line and Draw.Ray from an external class, make sure the shared custom project references NinjaTrader.Custom.dll and not NinjaTrader.Vendor.dll.

      My questions:
      1) Can you think of any long-term concerns with referencing NinjaTrader.Custom.dll and not NinjaTrader.Vendor.dll?
      2) Can you share best practices on referencing NinjaTrader assemblies from external projects?


      Test code:

      using System.Windows.Media;
      using NinjaTrader.Gui;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.NinjaScript.DrawingTools;

      namespace MyNamespace
      {
      public class MyMethods
      {
      public void Test(NinjaScriptBase owner)
      {
      Draw.Text(owner, "tag", "text", 0, 0, Brushes.Green);
      Draw.Ray(owner, "tag", false, 10, 0, 0, 0, Brushes.Green, new DashStyleHelper(), 1, false);
      Draw.Line(owner, "tag", false, 10, 0, 0, 0, Brushes.Green, new DashStyleHelper(), 1);
      }
      }
      }

      Thanks!​

      Comment


        #4
        Hello caryc123,

        Unfortunately, this would be out of the realm of what our Support is able to assist with.

        This thread will remain open for any community members that would like to provide advice or sample code for working with an external project.

        I do want to note the NinjaTrader.Custom.dll is rebuilt on each compile. I wouldn't be able to say if this will cause issues, but it's something to be aware of.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NM_eFe, Today, 06:14 AM
        0 responses
        1 view
        0 likes
        Last Post NM_eFe
        by NM_eFe
         
        Started by sgordet, Today, 06:04 AM
        0 responses
        4 views
        0 likes
        Last Post sgordet
        by sgordet
         
        Started by bc24fl, 08-30-2019, 01:58 PM
        4 responses
        260 views
        0 likes
        Last Post PaulMohn  
        Started by sugalt, Today, 04:02 AM
        0 responses
        6 views
        0 likes
        Last Post sugalt
        by sugalt
         
        Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
        6 responses
        30 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X