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

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 GussJ, 03-04-2020, 03:11 PM
          12 responses
          3,239 views
          0 likes
          Last Post Leafcutter  
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          4 views
          0 likes
          Last Post AveryFlynn  
          Started by RubenCazorla, 08-30-2022, 06:36 AM
          3 responses
          79 views
          0 likes
          Last Post PaulMohn  
          Started by f.saeidi, Yesterday, 12:14 PM
          9 responses
          25 views
          0 likes
          Last Post f.saeidi  
          Started by Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Working...
          X