Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple strategy Framework

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

    Multiple strategy Framework

    Hi,

    I'm trying to join multiple strategies into a single file. I've started to code a Framework to make adding new strategies easy, and to make sure I can check between position dependencies, etc..

    The strategy compiles OK, but when I run it an alert pops up with an error saying:
    Failed to execute DB job 'StrategyUpdateJob': There was an error generating the XML document: The type NinjaTrader.Srtategy.MultipleStrategy+Test was not expected. Use XMLInclude or SoapINclude attribute to specify types that are not known statically.
    This is the code I've got so far. Any idea what I'm doing wrong. Seeing my code can you think of a better approach?

    Thanks!

    Code:
    #region Using declarations
    using System;
    using System.Collections;
    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
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Framework with to integrate multiple strategies with COBC true for entries and tickdata to emulate COBC false for exits
        /// </summary>
        [Description("Framework with to integrate multiple strategies with COBC true for entries and tickdata to emulate COBC false for exits")]
        public class MultipleStrategy : Strategy
        {
            #region Strategy Framework Stuff
    		
    		#region Strategy Framework Variables
     		public ArrayList sfStrategies = new ArrayList();
        	#endregion
    		
            #region Strategy Framework Classes
    		
    		[XmlInclude(typeof(SubStrategy))]
    		public class SubStrategy		
    		{
    			public virtual void OnBarCloseUpdate(){}
    		}
            #endregion
    
    		
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            }
    		
    		protected override void OnStartUp()
    		{
    			sfStrategies.Add( new Test());
    		}
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			foreach ( SubStrategy st in sfStrategies )
    			{
    				st.OnBarCloseUpdate();
    			};
            }
    		
    		public class Test:SubStrategy		
    		{
    			public const string Name = "Test";
    			
    			public void OnBarCloseUpdate()
    			{
    			}
    			public Test(){}
    		}
    		
            #region Properties
            #endregion
        }
    }

    #2
    Hello,

    This error indicates that your strategy could not be Serialized by .NET and unfortunately outside of the scope of NinjaScrpit that we can support.

    I would suggest reviewing the User Defined Color Inputs for an example of how to ensure your properties are being serialized properly:



    MatthewNinjaTrader Product Management

    Comment


      #3
      Just in case anybody else has this problem:

      This error is due to the fact that I declared the "ArrayList sfStrategies" public and because it's public NT needs to serialize it as it belongs to Strategy class but it doesn't know how. As Matthew pointed out, this creates a serialization error.

      SOLUTION: make ArrayList sfStrategies private so it doesn't need to be serialized. (I don't know why I made it public anyway )

      Thanks for your help.

      Comment


        #4
        Thanks for following up with your solution - we appreciate it!
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        637 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X