Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest with Multiple Strategies

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

    Backtest with Multiple Strategies

    Hi everyone,

    I am trying to create a strategy where I can instantiate other strategies and have them run.

    This is my code. It actually gives an error but after ignoring it, it runs but only with the saved default settings. I should be able to change them.

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    namespace NinjaTrader.Strategy
    {
        public class MultiStrategyTest : Strategy
        {
            protected override void Initialize()
            {
                CalculateOnBarClose 		= false;
                Unmanaged 					= true;
                MaximumBarsLookBack 		= MaximumBarsLookBack.Infinite;
                BarsRequired 				= 0;
                IncludeCommission 			= true;
                Slippage 					= 1;
                ConnectionLossHandling 		= ConnectionLossHandling.KeepRunning;
    			RealtimeErrorHandling 		= RealtimeErrorHandling.TakeNoAction;
                ExitOnClose 				= false;
    			MultiThreadSupport			= false;
            }
    		
    		public StrategyBase st1;
    		
    		protected override void OnStartUp()
    		{
    			if (st1 == null)
    			{
    				st1 					= new NinjaTrader.Strategy.CoreOne();
    				st1.Account 			= this.Account;
    				st1.CalculateOnBarClose = this.CalculateOnBarClose;
    				st1.BarsRequired 		= this.BarsRequired;
    				st1.FillType 			= this.FillType;
    				st1.Slippage 			= this.Slippage;
    				st1.BackTestFrom 		= this.BackTestFrom;
    				st1.BackTestTo 			= this.BackTestTo;
    				st1.BackTestMode		= this.BackTestMode;
    				st1.IncludeCommission	= this.IncludeCommission;
    				st1.MaximumBarsLookBack = this.MaximumBarsLookBack;
    				st1.ExitOnClose			= this.ExitOnClose;
    				st1.TimeInForce			= this.TimeInForce;			
    				st1.Instrument 			= this.Instrument;
    				st1.SetBarsPeriodInstrument(this.Bars.Period, this.Instrument);
    				st1.SetUp();				
    				
    			}			
    			if (!st1.Enabled) st1.Enabled = true;
    			if (!st1.Running) st1.Running = true;
    		}
    		
    		protected override void OnTermination()
            {
                if (st1 != null)
                {
                    st1.Dispose();
                    st1 = null;
                }
            }
    		
            protected override void OnBarUpdate()
            {}
    		
    		
        }
    }
    What am I doing wrong here?

    I'll be waiting for your suggestions, thanks in advance.

    #2
    Hi stylusdotnet,

    Just a heads up this is extremely unsupported.

    However, we will leave the thread open in case another forum member has an answer for you.

    You may want to ask this in the unsupported thread.
    http://ninjatrader.com/support/forum...ad.php?t=22435
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply.

      I am aware that it is unsupported but since it is for testing purposes, the worst thing that can happen is to get wrong backtest results. So it is quite OK.

      Comment


        #4
        Run Multiple strategies on a basket of instruments

        I'm also trying to code to run multiple strategies on a basket of instruments. Does Ninja support this yet? Or offer an UI that does?

        Comment


          #5
          Did you ever get past your error stylusdotnet?

          Comment


            #6
            Hello yubo27,

            It is possible to add an instance of your strategy to multiple instruments at the same time.

            To do this:
            • Right-click the blank area under the Strategies tab of the Control Center
            • Select New Strategy...
            • In the drop-down for instruments(s) select Instrument List -> select the instrument list
            • Click OK
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No, I was referring to running multiple strategies on multiple instruments, not one strategy on multiple instruments.

              This is a common use case in quant trading: you combine multiple strategies together to run at the same time, to look at the over all performance. Not sure why Ninja doesn't have this basic functionality supported.
              Last edited by yubo27; 09-18-2014, 11:27 AM. Reason: modify

              Comment


                #8
                Hi yubo27,.

                Yes, you can run different strategies on different instruments.

                The instructions from my last post are to add multiple instances of the same strategy on different instruments.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I need to run strategy A on instrument 1, strategy B on instrument 2.....at the same time, and look at over all performance.

                  Does Ninja support this?

                  Comment


                    #10
                    Hi yubo27,

                    You can run strategy A on instrument 1, and strategy B on instrument 2, but these will have separate strategy performance.
                    (In the Strategies tab right-click a strategy -> select Strategy Performance -> select Real-time)

                    All real-time trades will be visible in the Account Performance tab from both strategies, but this will also include all manual trades as well..
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I'm not running strategy in real-time. This is for "Backtest with Multiple Strategies", as the title of this thread reads.

                      Does Ninja support running two different strategies on separate instruments, each with its own parameters, and produce over-all performance?

                      **This is basic functionality needed for portfolio management.***

                      Comment


                        #12
                        Hi yubo27,

                        NinjaTrader does not support backtesting different strategies on different instruments and putting these in the same backtest results summary.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok. If there is no native support. Is there anything wrong with stylusdotnet's approach, of coding to launch strategy in code?

                          Comment


                            #14
                            yubo27, we could unfortunately not really comment on that, it may or may not work as it's 'playing' deeply outside the documented NinjaScript.

                            Comment


                              #15
                              Please test it and provide us your results.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X