Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a running 2nd strategy from another one

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

    Creating a running 2nd strategy from another one

    I would like to know how to create a strategy inside another strategy (for whatever reason) and making both run properly at the same time.

    The issue is that parent strategy receive all events as expected, but the 2nd do not receive OnBarUpdate() events.

    As 2nd strategy really receive OnStateChange() events I guess I missing to add the underlying instrument or something similar.

    Can anyone give a light on this please?

    Code:
    namespace NinjaTrader.NinjaScript.Strategies  {
        
        // 1st Strategy
        public class AggregateStrategy : Strategy {
            
            protected override void OnStateChange() {
                Print(">> AggregateStrategy.OnStateChange: | " + State + " | " + Category);
    
                if (State == State.SetDefaults) {
                    Description = @"Aggregate Strategy";
                    Name = "AggregateStrategy";
                }
                else if (State == State.Configure) {
                }
            }
    
            protected override void OnBarUpdate() {
                Print(">> AggregateStrategy.OnBarUpdate()");
    
            }
        }
    
        // 2nd Strategy that uses the 1st one
        public class ParentStrategy : Strategy {
            
            protected AggregateStrategy st;
    
            protected override void OnStateChange() {
                Print(">> ParentStrategy.OnStateChange: | " + State + " | " + Category);
    
                if (State == State.SetDefaults) {
                    Description = @"The ParentStrategy";
                    Name = "ParentStrategy";
                }
                else if (State == State.Configure) {
                    ClearOutputWindow();
                    st = new AggregateStrategy();
                    Print("Create another strategy");
                }
            }
    
            protected override void OnBarUpdate() {
                Print(">> ParentStrategy.OnBarUpdate()");
    
            }
        }
    }

    #2
    Hello asterio,

    This would be outside of what is supported by NinjaScript Support, however, this thread will remain open for any community members that would like to assist.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.


    That said, from the code you have posted, I would expect these to be completely separate scripts that would run as independent instances.

    OnStateChange() is called for all scripts with State as State.SetDefaults when the Strategy window is opened.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank your for your reply ChelseaB,

      The sample code was only to "describe" the problem. As you said, each Strategy are in different files.

      I was looking for something like this idea, in order to have full control of them, however it seems to be for prior versions of NT.

      Maybe another approach will be easier.

      What I pretend is to have some strategies working together like under the same Chart, like the user has been adding them in the Strategies Panel of a Chart (CTRL+S), but some strategies may be disabled until some condition would be reached, so I need a inter-strategy mechanism in order the strategies can cooperate under the same chart.

      Using static variables could be a solution but this approach affects to all running Strategies instances, making collaboration hard using different Instruments or time frames.

      Is there another simply way to inter-communicate some strategies grouped together (e.g under the same Chart, or sharing the same custom-property value)?

      I do really appreciate any light on this.

      Thanks in advance.
      --
      Asterio
      Last edited by asterio; 03-05-2018, 12:25 AM.

      Comment


        #4
        Hello asterio,

        Strategies are not designed to be enabled programmatically any resulting behavior would be outside of NinjaScript Support.

        However, you could have a dictionary with the instrument symbol in a static class to have one value per instrument.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Strategies are not designed to be enabled programmatically any resulting behavior would be outside of NinjaScript Support.
          Ok, I'm going to use a dictionary to create running strategies groups.

          Thanks for the info.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X