Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DLL Strategy - including partial cs file

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

    DLL Strategy - including partial cs file

    Hello,

    I am developing quite complex tool. Solutions consists of lot of file which are
    partial public partial class Golem: Strategy

    I want to hide source code - so I am thinking to export it to dll.

    But there is other think. I need to be able to run code like this, which customer can write himself code is like:
    Code:
    using GolemApp;
    
    using GolemApp.Entity;
    
    
    
    
    namespace NinjaTrader.NinjaScript.Strategies
    
    {
    
    public partial class Golem: Strategy
    
    {
    
    /// <summary>
    
    /// Limitní vstup
    
    /// </summary>
    
    /// <param name="filter"></param>
    
    /// <returns></returns>
    
    public FilterResult Filter_fil1ec4b04dfc3(Filter filter)
    
    {
    
    int bipFilter = filter.BarsArrayIndex;
    
    string placeTo = filter.GetParamValue<string>(0);
    
    int offset = filter.GetParamValue<int>(1);
    
    bool toLastCandle = filter.GetParamValue<bool>(2);
    
    bool counterLastCandle = filter.GetParamValue<bool>(3);
    
    
    
    
    double entryPrice = double.MinValue;
    
    
    
    
    if (placeTo == "close")
    
    {
    
    entryPrice = Closes[bipFilter][lastCandleEntry];
    
    }
    
    
    
    
    Helpers.Enum_CandleDirection lastDirection = h.CandleDirection(bipFilter, lastCandleEntry);
    
    Helpers.Enum_CandleDirection tradeDirection = Helpers.Enum_CandleDirection.Undefined;
    
    
    
    
    // Vstup ve směru poslední svíčky
    
    if (toLastCandle) {
    
    if (lastDirection != Helpers.Enum_CandleDirection.Doji)
    
    {
    
    tradeDirection = lastDirection;
    
    }
    
    }
    
    
    
    
    // Vstup proti směru poslední svíčky
    
    if (counterLastCandle)
    
    {
    
    if (lastDirection == Helpers.Enum_CandleDirection.Long)
    
    {
    
    tradeDirection = Helpers.Enum_CandleDirection.Short;
    
    }
    
    if (lastDirection == Helpers.Enum_CandleDirection.Short)
    
    {
    
    tradeDirection = Helpers.Enum_CandleDirection.Long;
    
    }
    
    }
    
    
    
    
    if (tradeDirection == Helpers.Enum_CandleDirection.Long)
    
    {
    
    // Vstup na low poslední svíčky
    
    if (placeTo == "hi_lo")
    
    {
    
    entryPrice = Lows[bipFilter][lastCandleEntry];
    
    }
    
    
    
    
    entryPrice = entryPrice - offset * TickSize;
    
    }
    
    
    
    
    if (tradeDirection == Helpers.Enum_CandleDirection.Short)
    
    {
    
    // Vstup na high poslední svíčky
    
    if (placeTo == "hi_lo")
    
    {
    
    entryPrice = Highs[bipFilter][lastCandleEntry];
    
    }
    
    
    
    
    entryPrice = entryPrice + offset * TickSize;
    
    }
    
    
    
    
    FilterResult result = new FilterResult();
    
    result.State = Helpers.Enum_ResultState.Undefined;
    
    result.AddPair("TradeDirection", tradeDirection.ToString());
    
    result.AddPair("EntryPrice_Expected", entryPrice.ToString());
    
    result.AddPair("OrderLong", "EnterLongLimit");
    
    result.AddPair("OrderShort", "EnterShortLimit");
    
    
    
    
    return result;
    
    }
    
    }
    
    }
    ​
    Is there to way to have compiled Golem into dll - without this method Filter_fil1ec4b04dfc3. This method customer writes himself, so i need to compile it if it is available along with provided Golem.DLL file.

    Or is there other way, to move logic out of partial Golem Strategy?

    Thanks a lot for any advices

    Paul

    #2
    Hello Paul,

    You can split the code into separate files.

    If you need one file as assembly dll, export this by itself as an assembly.
    Temporarily exclude the originals from compilation, then import the assembly.
    Reference the first assembly when exporting the second file.
    Manually drag this into the export .zip file once exported.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      thank you for video. I think that i want something little different.
      I see demonstration. In Example.cs - there is code which should be compiled in DLL library...
      There can be multiple files like ExampleSource, which contain methods, which will be called from DLL (if they) exist.
      I thought i can export Example.cs into dll a then import it. (i exclude Example.cs from compilation).

      But it does not work this way and method is not called (no output).

      Can you give me an advice?

      I hope it's clear what i need. I want to give access to customer to be able to create simple methods, but do not want to show him the whole source code.

      Thanks a lot
      Paul
      Attached Files

      Comment


        #4
        To be more clear i have many snippets, see folder Filters. These snippets use things such as various BarsArray data Highs, Low, also indicators added into class Golem. I want to have these snippets called dynamically from code which is compiled in DLL...
        Click image for larger version  Name:	image.png Views:	0 Size:	595.6 KB ID:	1300740

        Comment


          #5
          Hello kujista,

          Thank you for the simplified files.

          I think I understand the issue. I'll need to research this further.

          I appreciate your patience.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            O.K. Thanks a lot...
            I was also thinking to have
            Code:
            public partial class ExampleStrategy : Strategy {
            which will have complete logic and then
            Code:
            public partial class ExampleFiltersStrategy : Strategy {
            which will contain only snippets and then "somehow" pass these methods into ExampleStrategy.

            But I am not sure. I will wait for your reply.

            Comment


              #7
              Hello kujista,

              Just an update with this, after much research I haven't been able to figure this out.

              Exporting a partial class as an assembly and importing this not within the available context and I'm not understanding why.

              I've put in a report to our development to investigate further.

              I'll let you know any information I receive and I appreciate your patience.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                hello, thank you for update. i have to wait for another updates

                Comment


                  #9
                  Hello Chelsea, wil be there a progress in this issue?

                  Comment


                    #10
                    Hello kujista,

                    The information I received back from our development was:
                    "You cannot have two partial classes referring to the same class in two different assemblies (projects). Once the assembly is compiled, the meta-data is baked in, and your classes are no longer partial. Partial classes allows you to split the definition of the same class into two files."

                    I'm currently attempting to build an example of shared classes that are not partial but haven't had much progress at this point.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    557 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    324 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    545 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X