Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use Custom Method from Indicators in Strategy scipt

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

    Use Custom Method from Indicators in Strategy scipt

    Hello!

    I've created Custom Method in NinjaTrader.Indicator namespace.
    Could I use this method in a Strategy?

    Thanks
    YB
    Last edited by byi777; 12-02-2010, 05:06 PM.

    #2
    Hello YB,

    Yes, indicator methods are available from a strategy context but not vice versa.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I have line in code that working in Indicator:

      fastEma.Set(fnEMA(fastLength, Input[0],fastEma[1]));

      But in Strategy I got compilation error CS0103 "The name 'fnEMA' does not exist in current context"

      How to fix this issue?

      Thanks
      YB

      Comment


        #4
        YB, you would need to check the indicators name your trying to access, type this. and see under which name it's listed then.

        Comment


          #5
          I know the fully qualified name. It's 'NinjaTrader.Indicator.Indicator.fnEMA'.

          In order to use it from 'NinjaTrader.Strategy' namespace modules I should create Object Instance of Class 'NinjaTrader.Indicator.Indicator' in that module like this:

          NinjaTrader.Indicators.Indicators IndToStClass;
          IndToStClass = new Indicators.Indicators();


          When I tried to create such object reference, system gave me compilation error:
          Compiler Error CS0144

          Cannot create an instance of the abstract class or interface 'interface'.

          Do you know how avoid that problem?

          Later I found solution in Post #5 from Ralph:



          I have created new file containing definition of new namespace , new class and method in question and created following instance:


          NinjaTrader.MyMethods.MyMethods IndToStClass;
          IndToStClass = new MyMethods.MyMethods();

          Call to method looks like IndToStClass.fnEMA(...

          Compilation went through


          Thanks
          YB

          Comment


            #6
            Glad to hear it's working for you. Thanks for the followup.

            The method will belong to one particular indicator, so referencing it in a strategy you use this format:

            Code:
            indicatorName(indicatorInputs).methodName(methodInputs)
            There shouldn't be any need to instantiate objects if you just want this method in a strategy. Make sure the method is declared public for it to be available outside of indicator context.

            You may also want to use UserDefinedMethods file dedicated to either indicator or strategy.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              RyanM,

              Actually, I'm discussing in this post problem I had with UserDefinedMethod.
              I've made trick to use the same method from the same file in both Indicator and Strategy.
              Originally I created it in Indicators namespace and had no problems using it in custom Indicator.
              Later I made few attempts to use the same Method from Strategy and gave up.

              After that I found solution and create the same method in namespace MyMethods.

              I've attached both files.
              Could you try to call method fnEMA created in namespace Indicators from code for Strategy.
              YBMethods.zip


              Thanks
              YB

              Comment


                #8
                If you're using this UserDefinedMethods file, then indicator methods are accessible within indicators and strategy methods available with strategies only. There may be work-arounds available for this but nothing supported.

                You need to place this method within one individual indicator for it to be available within a strategy context. The method should be placed within the scope of this individual indicator, not the broader indicator namespace.

                See attached indicator and strategy for example of this.
                Attached Files
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Very good way how to create and use custom methods.

                  Thank you, RyanM

                  Comment


                    #10
                    Glad it's working for you. Thanks for the feedback.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      RyanM,

                      Could you explain or give me reference source, why you use in the sample call to method as

                      double mydouble = methodMaker().fnEMA(1,1,1); // classname().methodname(,,),

                      but

                      double mydouble = methodMaker.fnEMA(1,1,1); // classname.methodname(,,)

                      Thanks
                      YB

                      Comment


                        #12
                        I'm sorry, not sure what you're looking for here. For additional help in this area, consult MSDN docs or a C# guide.
                        Ryan M.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        601 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        347 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        103 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        559 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        558 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X