Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling Strategy methods from another class

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

    Calling Strategy methods from another class

    Hello,

    I'm new to NinjaTrader and NinjaScript, but have some programming background in c#.
    As far as I can see all the methods are incapsulated into Strategy class
    I wonder if I can do something like:
    Code:
    public class MyStrategy : Strategy
    {
        protected override void Initialize()
        {
              Class1 c1 = new Class1(this);
              c1.DoSmth();
        }
    }
    
    public class Class1 
    {
        private readonly Strategy _strategy;
        public Class1(Strategy strategy)
        {
            _strategy = strategy;
        }
    
        public void DoSmth()
        {
              _strategy.EnterLong();
        }
    }

    #2
    Hello qwerty_2004,
    Welcome to the forum and I am happy to assist you.

    NinjaScript is essentially C# and you will be able to use any method/rules which are applied to C#.

    You can take reference to this member submitted code;



    However please do note, we offer support for documented NinjaScript codes only (as found in our help guide) and any advanced C# concepts is not officially supported by us.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_Joydeep for example code,
      But this is not exactly what i wanted to know.

      I want to figure out if NinjaScript API functions are declared as 'public' (so I can use them from external classes)

      Comment


        #4
        Hello qwerty_2004,
        NinjaScript strategies are public classes and you will be able to call them from external classes.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks a million!
          Will carry on involving

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          332 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
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X