Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 josh18955, 03-25-2023, 11:16 AM
          6 responses
          435 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          3 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          18 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frslvr, 04-11-2024, 07:26 AM
          9 responses
          126 views
          1 like
          Last Post caryc123  
          Started by selu72, Today, 02:01 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Working...
          X