NexusFi: Find Your Edge


Home Menu

 





Creating a running 2nd strategy from another one


Discussion in NinjaTrader

Updated
    1. trending_up 728 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
Search this Thread

Creating a running 2nd strategy from another one

  #1 (permalink)
 asterio 
San Jose/Costa RIca
 
Experience: Beginner
Platform: NinjaTrader
Trading: Emini ES
Posts: 2 since Mar 2018
Thanks Given: 0
Thanks Received: 1

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 strategy do not receive events such OnBarUpdate().

I also check that the value of Instrument is not set for 2nd strategy.
 
Code
namespace NinjaTrader.NinjaScript.Strategies  {
    
    // 2nd 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()");

        }
    }

    // main Strategy 
    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()");
        }
    }
}
As the 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?

Thanks in advance
--
Aster

Started this thread Reply With Quote




Last Updated on March 4, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts