Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Considerations for Compiled Assemblies

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

    Considerations for Compiled Assemblies

    Hi,
    I have to rewrite some indicator code that is to be exported as an assembly. The code does a few things with GannFan draw objects.
    * creates instances of them (draws them on a chart)
    * peruses the DrawObjects collection for GannFans, and may wish to change some of their properties, e.g. GannFan.GannFanDirection

    I'm struggling a bit with the dynamic types and the creation of instances using Reflection.
    Are there any additional code examples for this type of work, other than what is on the Help page at https://ninjatrader.com/support/help...assemblies.htm

    Thanks,
    saltminer

    #2
    Hello saltminer,

    Thanks for your post.

    Below is an example that can demonstrate how a script which programmatiacally draws a GannFan can look for it using a dynamic type and .ToString(). This snippet will work in a compiled assembly.

    Code:
                else if (State == State.Realtime)
                {
                    foreach (dynamic fan in DrawObjects.ToList())
                    {
                        // Use ToString().Equals() to detect the object's Type
                        if (fan.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.GannFan"))
                        {
                            // Access the object by assuming that it is the Type we expect
                            Print(String.Format("GannFan {0} detected!", fan.Tag));
                        }
                    }
                }
            }
    
            protected override void OnBarUpdate()
            {
                Draw.GannFan(this, "tag", true, 0, Close[0]);
            }
    Could you elaborate on your need for Reflection? Please also share what you have attempted and the issue you are experiencing. Usage of Reflection can go beyond our scope of support, but we may be able to point out some parts where Reflection is used in various NinjaScripts which may give some further direction.

    I look forward to assisting.
    Last edited by NinjaTrader_Jim; 06-02-2020, 01:44 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,
      actually in the end it was simpler than I feared. I'd already implemented the required format within the code, (such as the guidance above) but it was a public property that was foiling the import of the DLL.


      [NinjaScriptProperty]
      [Display(Name="GannDirection", Description="internal use only", Order=10, GroupName="z. internal use only")]
      public GannFan.GannFanDirection GannDirection
      {
      get { return gannDirection; }
      set { gannDirection = value; }
      }

      Thanks for your help,
      saltminer

      Comment


        #4
        Hi Jim,
        I spoke too soon. The DLL imports ok, but I'm unsure how to solve the problem of using GannFans both in the NinjaTrader.Custom assembly and in the DLL assembly. I need to be able to treat them as if they are the same thing.
        e.g.
        GannFan myGann = (GannFan)ninjaGann;

        This is the error (I'm sure you are familiar).

        Unhandled exception: [A]NinjaTrader.NinjaScript.DrawingTools.GannFan cannot be cast to [B]NinjaTrader.NinjaScript.DrawingTools.GannFan. Type A originates from 'NinjaTrader.Custom, Version=8.0.21.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\codin\OneDrive\Documents\NinjaTrader 8\bin\Custom\NinjaTrader.Custom.dll'. Type B originates from 'TheCustomAssembly', Version=1.0.2.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\codin\OneDrive\Documents\NinjaTrader 8\bin\Custom\TheCustomAssembly.dll'.

        Thanks in advance,
        saltminer

        Comment


          #5
          Hello saltminer,

          I think we are still looking at an issue where the dynamic type should be used. I would recommend setting up the code so it works in source code, and then to change types to dynamic.

          Instead of casting, we should use ToString to see the object's type and then we can assign to the dynamic variable. I've attached some additional code to demonstrate assigning a found GannFan to a dynamic variable. This can be exported as a DLL and tested.

          We look forward to assisting.
          Attached Files
          JimNinjaTrader Customer Service

          Comment


            #6
            Hi Jim,
            there are multiple indicators in a product suite. They are similar (having to use dynamic types etc on GannFans). They now work fine individually when compiled into an assembly.
            However, when using two at once, I get the following issue. (from within OnRender which has to parse some chart objects for various reasons)

            Error on calling 'OnRender' method on bar 3507: An unexpected exception occurred while binding a dynamic operation

            Would you have any guidance for me on this please?

            Thanks in advance,
            saltminer

            Comment


              #7
              Hello saltminer,

              I can't give any more insight here off the top of my head and would want to make sure I am looking at the same issue you are. Could you attach a small test script that can be used to demonstrate the issue at hand?

              You may also reach out to me over email if you would like.

              I look forward to assisting.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              2 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              38 views
              0 likes
              Last Post love2code2trade  
              Started by alifarahani, Today, 09:40 AM
              2 responses
              14 views
              0 likes
              Last Post alifarahani  
              Started by junkone, Today, 11:37 AM
              3 responses
              20 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by frankthearm, Yesterday, 09:08 AM
              12 responses
              44 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X