Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with using a custom indicator(exported as assembly)

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

    Problem with using a custom indicator(exported as assembly)

    Hi,

    Situation:
    1. I have an indicator that I would like to share as assembly. Note my indicator uses inbuilt ATR indicator.
    2. I also have a strategy that uses above indicator, that I would like to share the source(not as assembly)

    What I have done:
    1. Export the Indicator as assembly(it included ATR also and there was no option to proceed without that), imported it in the destination computer
    2. Then copy the Strategy source code to the respective folder in the destiantion computer

    Problem:
    The Stratgey shows build error: Cannot convert from 'NinjaTrader.NinjaScript.Indicator.ATR[C:\Users\soman\Documents\NinjaTrader 8\bin\Custom\Indicators\@ATR.cs(35)]' to 'NinjaTrader.NinjaScript.Indicator.ATR["C:\Users\Administrator\Documents\NinjaTrader 8\bin\Custom\MyCustomeIndicator.dll]'

    This is probably because while export the MyCustomeIndicator.dll also exported another version of ATR, but the strategy is using the inbuilt ATR

    Question:
    What is the solution to this problem? How can I share the Indicator as compiled assembly and Strategy as code?
    Note: I do not want to change my STrategy to use the ATR from dll - that woudl significantly delay the development work.​

    #2
    Hello somanko,

    Thank you for your post.

    Can you please test out the following:
    • Create a new strategy using the Strategy Builder that uses the ATR in a condition (can be any condition). Then export this strategy as source code.
    • Create a new indicator that uses the same code for the ATR that the strategy used (you can click 'View Code' in the Strategy Builder to see the code generated). Then, export this indicator script as a compiled assembly.
    • Import the compiled indicator and test if this has the same issue (if you're importing it back onto the same computer, remove the source-code version of the indicator prior to importing the compiled assembly version to prevent any duplicate method errors upon importing).
    Let me know the results of the test.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3

      Hi Gaby,

      Thanks for your prompt response, appreciate it!

      Need some clarification on steps 2 you mentioned:
      Create a new indicator that uses the same code for the ATR that the strategy used
      Here is the Strategy code I created from step 1 :
      Create a new strategy using the Strategy Builder that uses the ATR in a condition
      Code:
      public class ExportTest : Strategy
      {
          ATR atr;
          protected override void OnStateChange()
          {
              if (State == State.SetDefaults)
              {
                  Description                                    = @"Enter the description for your new custom Strategy here.";
                  Name                                        = "ExportTest";
                  Calculate                                    = Calculate.OnBarClose;
                  EntriesPerDirection                            = 1;
                  EntryHandling                                = EntryHandling.AllEntries;
                  IsExitOnSessionCloseStrategy                = true;
                  ExitOnSessionCloseSeconds                    = 30;
                  IsFillLimitOnTouch                            = false;
                  MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                  OrderFillResolution                            = OrderFillResolution.Standard;
                  Slippage                                    = 0;
                  StartBehavior                                = StartBehavior.WaitUntilFlat;
                  TimeInForce                                    = TimeInForce.Gtc;
                  TraceOrders                                    = false;
                  RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                  StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                  BarsRequiredToTrade                            = 20;
                  // Disable this property for performance gains in Strategy Analyzer optimizations
                  // See the Help Guide for additional information
                  IsInstantiatedOnEachOptimizationIteration    = true;
              }
              else if (State == State.Configure)
              {
                  atr = ATR(14);
              }
          }
      
          protected override void OnBarUpdate()
          {
              if (atr[0] > 5)
              {
                  Print("ATR > 5");
              }
          }
      }​
      Question 1. How do I create an Indicator that that uses the same code for the ATR that the strategy used?
      Is the below Indicator code ok for your testing?
      Code:
      public class TestExportIndicator : Indicator
      {
          ATR atr;
          
          protected override void OnStateChange()
          {
              if (State == State.SetDefaults)
              {
                  Description                                    = @"Enter the description for your new custom Indicator here.";
                  Name                                        = "TestExportIndicator";
                  Calculate                                    = Calculate.OnBarClose;
                  IsOverlay                                    = false;
                  DisplayInDataBox                            = true;
                  DrawOnPricePanel                            = true;
                  DrawHorizontalGridLines                        = true;
                  DrawVerticalGridLines                        = true;
                  PaintPriceMarkers                            = true;
                  ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                  //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                  //See Help Guide for additional information.
                  IsSuspendedWhileInactive                    = true;
              }
              else if (State == State.Configure)
              {
              }
              else if (State == State.DataLoaded)
              {
                  atr = ATR(14);
              }
          }
      
          protected override void OnBarUpdate()
          {
              if (atr[0] > 5)
              {
                  Print("ATR > 5");
              }
          }
      }​
      Question 2. Also Should I import both the Strategy (as code) and the Indicator(as assembly) into the target computer? Note: My target comupter is different than the development computer.

      Also, just wanted to mention that my scenario is little different than what you are asking to test. In my case:
      • The Indicator uses ATR
      • The Strategy uses the indicator and also uses ATR
      Is there a way to schedule a call with you? Its much easier to show than describe!

      Comment


        #4
        Just noticed that the error is not coming from the indicator, its coming from a custom AddOns code.
        Code:
        public class MyAddOn
        {
            public static int myMethod(Indicators.ATR atr, ... other arguments)
            {
        
            }
        }​
        Strategy code that produces the error:
        Code:
            int i = MyAddOn.myMethod(ATR(BarsArray[2], 14), .....)
        Looking at the error:
        Code:
        Cannot convert from 'NinjaTrader.NinjaScript.Indicator.ATR[C:\Users\soman\Documents\NinjaTrader 8\bin\Custom\Indicators\@ATR.cs(35)]' to 'NinjaTrader.NinjaScript.Indicator.ATR["C:\Users\Administrator\Documents\NinjaTrader 8\bin\Custom\MyCustomAddOn.dll]
        '
        Looks like the AddOn while exported as assembly also included ATR and the myMethod is expecting that version of ATR,
        But the Strategy is trying to pass the inbuilt version of ATR

        Comment


          #5
          Please note static classes are not supported.

          You could try using the fully qualified namespace, but keep in mind this code is not officially supported.
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            The class is not static, the method is. Static method is also not supported? So if I just use non static method, the issue would be resolved?

            Comment


              #7
              Hello,

              Correct, static methods and classes are not supported. Yes you could try altering the code to use non-supported methods. We could then assist further if needed.
              Gaby V.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Pointtoni, Yesterday, 11:41 PM
              0 responses
              7 views
              0 likes
              Last Post Pointtoni  
              Started by DayTradingDEMON, Yesterday, 02:10 PM
              2 responses
              20 views
              0 likes
              Last Post DayTradingDEMON  
              Started by Marble, 03-20-2025, 05:00 AM
              7 responses
              34 views
              0 likes
              Last Post Marble
              by Marble
               
              Started by laketrader, 03-10-2025, 07:20 AM
              6 responses
              59 views
              0 likes
              Last Post laketrader  
              Started by clintonbullocks15, Yesterday, 07:47 PM
              0 responses
              5 views
              0 likes
              Last Post clintonbullocks15  
              Working...
              X