Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mash Trading Systems

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

    Mash Trading Systems

    Hello Ninjatrader Team,

    I have about 4 different trading systems that I have worked on. I was wondering is it possible to mash all 4 systems into one system. I tried using the AND (&&) function and adding all of them together but it seems not to work. Any suggestions on how to set this up.

    #2
    Originally posted by wallsteetking View Post
    Hello Ninjatrader Team,

    I have about 4 different trading systems that I have worked on. I was wondering is it possible to mash all 4 systems into one system. I tried using the AND (&&) function and adding all of them together but it seems not to work. Any suggestions on how to set this up.
    How do you mean "4 different trading systems" ? 4 different strategies, each in one file?

    Comment


      #3
      Yes, For example
      Strategy 1: MA Cross Over
      Strategy 2: Stochastic
      Strategy 3: MACD
      Strategy 4: Volume
      ================================================== ================
      Sometimes all of the systems fire a Long position on the same BAR.. see pic. What I want to see is, If I mash all of the systems together and they all fire a long position on the same bar how profitable is it historically.
      Attached Files
      Last edited by wallsteetking; 12-28-2012, 10:23 AM.

      Comment


        #4
        Originally posted by wallsteetking View Post
        Yes, For example
        Strategy 1: MA Cross Over
        Strategy 2: Stochastic
        Strategy 3: MACD
        Strategy 4: Volume
        ================================================== ================
        Sometimes all of the systems fire a Long position on the same BAR.. see pic. What I want to see is, If I mash all of the systems together and they all fire a long position on the same bar how profitable is it historically.
        In that case, you will have to concatenate the files, section by section, then write the glue code to bind the order system together. Instead of each substrategy placing an order, let is set a boolean flag. Place the order when all the flags are set, and reset all flags when flat.

        Comment


          #5
          can you direct me on how to do this. My coding skills are average. I have no idea what boolean flag means or how to glue the codes together. is there an example that I can fallow or help page???

          Comment


            #6
            Hello,

            We really do not have any specific examples, but here is a link to some basic programming concepts to help you:



            A boolean flag is going to be a true/false variable that you can set when the condition is true.

            For example

            Code:
            if(yourMACDCondition)
            {
                macdFlag = true;
            }
            
            if(yourStochasticCondition)
            {
                stochFlag = true;
            }
            Then for you entry condition, you can have this check when these flags are true and to take action at that time

            Code:
            if(stochFlag  == true && macdFlag  == true)
            {    
                //do something
            }
            MatthewNinjaTrader Product Management

            Comment


              #7
              Hi, I keeping getting error message please see picture
              here is the code (A1 And A2 are my personal 2 strategies)
              Code:
                protected override void Initialize()
                      {
                          CalculateOnBarClose = true;
              			
              			
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
              			Add(A1)());
              			Add(A2)());
              			
                          // Condition set 1
                          if (A1)
                          {
                              A1Flag =true;
                          }
              			if (A2)
              			{
              				A2Flag =true;
              			}
              			
              			if (A1Flag == true && A2Flag == true)
              			{
              				EnterLong(DefaultQuantity, "");
              			}
                      }
              Attached Files

              Comment


                #8
                Hello wallsteetking,
                You cannot use the Add in the OnBarUpdate event. Furthermore, you cannot add a strategy using the Add methods.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  what is the correct way of doing it?

                  Comment


                    #10
                    You will need to expose the series from your original strategy to be read by this new strategy.

                    Please see our Reference Sample on Exposing values that are not plots for an example of how to do this:

                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Originally posted by wallsteetking View Post
                      what is the correct way of doing it?
                      NT is event driven, so to concatenate files, you cut-and-paste like sections into one class.
                      You then replace your orders as necessary. Using 2 strategies as source for example, you might declare new class Boolean variables:
                      Code:
                       
                      private bool EnterLongStrat1 = false;
                      private bool EnterShortStrat1 = false;
                      private bool EnterLongStrat2= false;
                      private bool EnterShortStrat2 = false;
                      You copy the code out of each section in each Strategy and paste it into the same section in your concatenated file.

                      Then where you have EnterLong(...) in Strategy1, you will replace it with
                      Code:
                       
                      EnterLongStrat1 = true;
                      et.c.,

                      You then enter long if all the EnterLongStratx values are true, and short if all the EnterShortStratx are true.

                      Use the OnPositionUpdate() event handler to reset all the bools when you go flat. The example in the NT help details exactly that scenario.
                      Last edited by koganam; 01-16-2013, 04:19 PM.

                      Comment


                        #12
                        I am having a very hard time figure this out. please help me resolve this issue.
                        TO BE CLEAR I WANT TO MASH 2 of my strategies. NOT indicators.
                        Strategy 1 is called A1
                        I want to put strategy A1 into my MASHALL <-( mashall will be the main strategy)
                        For now I will NOT worry about strategy A2. I just want to add A1 into MASHALL

                        ALSO Both strategies are LONG never short

                        Here is the code for A1
                        Code:
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                            /// <summary>
                            /// Enter the description of your strategy here
                            /// </summary>
                            [Description("Enter the description of your strategy here")]
                            public class A1 : Strategy
                            {
                                #region Variables
                                // Wizard generated variables
                                private int myInput0 = 1; // Default setting for MyInput0
                        		
                        		private BoolSeries a1bear;
                        		private BoolSeries a1bull;
                        		
                                // User defined variables (add any user defined variables below)
                        		private double exposedVariable;
                        		
                                #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()
                                {
                                    a1bear			= new BoolSeries(this);
                        	    a1bull	     	        = new BoolSeries(this);
                        			
                                    CalculateOnBarClose	= true;
                        			
                                    
                        			
                                }
                        
                                /// <summary>
                                /// Called on each bar update event (incoming tick)
                                /// </summary>
                                protected override void OnBarUpdate()
                                {
                        			
                        		if (Close[0] >= EMA(20)[0]
                                        && Close[0] >= Close[1] + 15 * TickSize
                                        && Close[0] >= Open[0])
                                    {
                                      			a1bull.Set(true);
                        				a1bear.Set(false);
                        				
                                    }
                        			
                        			exposedVariable = Close[0];
                                }
                        
                                #region Properties
                                [Description("")]
                                [GridCategory("Parameters")]
                                public int MyInput0
                                {
                                    get { return myInput0; }
                                    set { myInput0 = Math.Max(1, value); }
                        			
                                }
                        		
                        	[Browsable(false)]
                                [XmlIgnore()]
                                public BoolSeries A1bull
                                {
                                    get { return a1bull; }	// Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
                                }
                        		
                        	[Browsable(false)]
                                [XmlIgnore()]
                                public BoolSeries A1bear
                                {
                                    get { return a1bear; }	// Allows our public BullIndication BoolSeries to access and expose our interal bullIndication BoolSeries
                                }
                        		
                                #endregion
                            }
                        When I compile this all works fine.

                        The issue becomes when I try to put this in MASHALL
                        Code:
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                            /// <summary>
                            /// Enter the description of your strategy here
                            /// </summary>
                            [Description("Enter the description of your strategy here")]
                            public class MASHALL : Strategy
                            {
                                #region Variables
                                // Wizard generated variables
                                private int myInput0 = 1; // Default setting for MyInput0
                                // User defined variables (add any user defined variables below)
                                #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;
                        	    Add(A1());
                                }
                        
                                /// <summary>
                                /// Called on each bar update event (incoming tick)
                                /// </summary>
                                protected override void OnBarUpdate()
                                {
                        
                                 {
                                        EnterLong(DefaultQuantity, "");
                                  }
                                }
                        I also tried [ ] instead of ()
                        Code:
                        CalculateOnBarClose = true;
                        	    Add(A1[]);
                        The error i get with Add(A1());[/CODE]
                        'NinjaTrader.Strategy.A1' is a 'type' but is used like a 'variable'
                        does not work.


                        The error I get with Add(A1[]);[/CODE]

                        Argument expected.
                        'NinjaTrader.Strategy.A1' is a 'type' but is used like a 'variable'
                        Statement expected.
                        Syntax error; value expected


                        How to i Fix this issue?????

                        Comment


                          #13
                          Originally posted by wallsteetking View Post
                          I am having a very hard time figure this out. please help me resolve this issue.
                          TO BE CLEAR I WANT TO MASH 2 of my strategies. NOT indicators.
                          Strategy 1 is called A1
                          I want to put strategy A1 into my MASHALL <-( mashall will be the main strategy)
                          For now I will NOT worry about strategy A2. I just want to add A1 into MASHALL

                          ALSO Both strategies are LONG never short

                          Here is the code for A1
                          Code:
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                              /// <summary>
                              /// Enter the description of your strategy here
                              /// </summary>
                              [Description("Enter the description of your strategy here")]
                              public class A1 : Strategy
                              {
                                  #region Variables
                                  // Wizard generated variables
                                  private int myInput0 = 1; // Default setting for MyInput0
                          		
                          		private BoolSeries a1bear;
                          		private BoolSeries a1bull;
                          		
                                  // User defined variables (add any user defined variables below)
                          		private double exposedVariable;
                          		
                                  #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()
                                  {
                                      a1bear			= new BoolSeries(this);
                          	    a1bull	     	        = new BoolSeries(this);
                          			
                                      CalculateOnBarClose	= true;
                          			
                                      
                          			
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                          			
                          		if (Close[0] >= EMA(20)[0]
                                          && Close[0] >= Close[1] + 15 * TickSize
                                          && Close[0] >= Open[0])
                                      {
                                        			a1bull.Set(true);
                          				a1bear.Set(false);
                          				
                                      }
                          			
                          			exposedVariable = Close[0];
                                  }
                          
                                  #region Properties
                                  [Description("")]
                                  [GridCategory("Parameters")]
                                  public int MyInput0
                                  {
                                      get { return myInput0; }
                                      set { myInput0 = Math.Max(1, value); }
                          			
                                  }
                          		
                          	[Browsable(false)]
                                  [XmlIgnore()]
                                  public BoolSeries A1bull
                                  {
                                      get { return a1bull; }	// Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
                                  }
                          		
                          	[Browsable(false)]
                                  [XmlIgnore()]
                                  public BoolSeries A1bear
                                  {
                                      get { return a1bear; }	// Allows our public BullIndication BoolSeries to access and expose our interal bullIndication BoolSeries
                                  }
                          		
                                  #endregion
                              }
                          When I compile this all works fine.

                          The issue becomes when I try to put this in MASHALL
                          Code:
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                              /// <summary>
                              /// Enter the description of your strategy here
                              /// </summary>
                              [Description("Enter the description of your strategy here")]
                              public class MASHALL : Strategy
                              {
                                  #region Variables
                                  // Wizard generated variables
                                  private int myInput0 = 1; // Default setting for MyInput0
                                  // User defined variables (add any user defined variables below)
                                  #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;
                          	    Add(A1());
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                          
                                   {
                                          EnterLong(DefaultQuantity, "");
                                    }
                                  }
                          I also tried [ ] instead of ()
                          Code:
                          CalculateOnBarClose = true;
                          	    Add(A1[]);
                          The error i get with Add(A1());[/CODE]
                          'NinjaTrader.Strategy.A1' is a 'type' but is used like a 'variable'
                          does not work.


                          The error I get with Add(A1[]);[/CODE]

                          Argument expected.
                          'NinjaTrader.Strategy.A1' is a 'type' but is used like a 'variable'
                          Statement expected.
                          Syntax error; value expected


                          How to i Fix this issue?????
                          Unfortunately, you seem to have overlooked where Joydeep told you: "You cannot use the Add in the OnBarUpdate event. Furthermore, you cannot add a strategy using the Add methods."

                          My posts in this thread have given you the skeleton of how to concatenate the code from multiple strategies. If you want the exact, specific code written for your precise setup, you may want to pay someone (not necessarily me) to write it for you.

                          Whoever you pay to code for you is likely to know what to do, but you can always refer them to this thread. All the information needed is in here.

                          Comment


                            #14
                            koganam thank you for the fast replay, but this should not be that hard to do, either there is something that I am missing or I am not given the correct information. Also, I tried it your way for some reason it doesn't work either can you look at the code and give me some advice. Thank you

                            Code:
                                /// <summary>
                                /// Enter the description of your strategy here
                                /// </summary>
                                [Description("Enter the description of your strategy here")]
                                public class MASHALL : Strategy
                                {
                                    #region Variables
                                    // Wizard generated variables
                                    private int myInput0 = 1; // Default setting for MyInput0
                            		private bool enterLongStrat1 = false;
                            		private bool enterLongStrat2= false;
                            	    // User defined variables (add any user defined variables below)
                                    #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;
                            	SetProfitTarget("", CalculationMode.Ticks, 4);
                            		}
                            
                                    /// <summary>
                                    /// Called on each bar update event (incoming tick)
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                            			
                                        // Strategy 1
                            		if (Bars.BarsSinceSession >=7)
                            				
                            	        if (Stochastics(7, 14, 3).D[0] >= 30)
                                        {
                                            enterLongStrat1 = true;
                            		enterLongStrat2 = false;
                            		DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 20 * TickSize, Color.Red);
                            				
                                        }
                            			
                            			//Strategy 2
                            			if (Bars.BarsSinceSession >=7)
                            				
                            			if ( Close[0] >= EMA(30)[0])
                                        {
                                            enterLongStrat2 = true;
                            		enterLongStrat1 = false;
                            	        DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 30 * TickSize, Color.Blue);
                            				
                                        }
                            			
                            			if (Bars.BarsSinceSession >=7)
                            			if(enterLongStrat2 == true && enterLongStrat1 == true)
                            			{    
                              				EnterLong(DefaultQuantity, "");
                            
                            			}
                                    }
                            
                                    #region Properties
                                    [Description("")]
                                    [GridCategory("Parameters")]
                                    public int MyInput0
                                    {
                                        get { return myInput0; }
                                        set { myInput0 = Math.Max(1, value); }
                                    }
                            	
                            		
                                    #endregion
                            Last edited by wallsteetking; 07-19-2013, 03:13 AM.

                            Comment


                              #15
                              Originally posted by wallsteetking View Post
                              koganam thank you for the fast replay, but this should not be that hard to do, either there is something that I am missing or I am not given the correct information. Also, I tried it your way for some reason it doesn't work either can you look at the code and give me some advice. Thank you

                              Code:
                                  /// <summary>
                                  /// Enter the description of your strategy here
                                  /// </summary>
                                  [Description("Enter the description of your strategy here")]
                                  public class MASHALL : Strategy
                                  {
                                      #region Variables
                                      // Wizard generated variables
                                      private int myInput0 = 1; // Default setting for MyInput0
                                      private bool enterLongStrat1 = false;
                                      private bool enterLongStrat2= false;
                                      // User defined variables (add any user defined variables below)
                                      #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;
                                  SetProfitTarget("", CalculationMode.Ticks, 4);
                                      }
                              
                                      /// <summary>
                                      /// Called on each bar update event (incoming tick)
                                      /// </summary>
                                      protected override void OnBarUpdate()
                                      {
                                          
                                          // Strategy 1
                                      if (Bars.BarsSinceSession >=7)
                                              
                                          if (Stochastics(7, 14, 3).D[0] >= 30)
                                          {
                                              enterLongStrat1 = true;
                               [B][COLOR=Blue] // [/COLOR][/B]      enterLongStrat2 = false;
                                      DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 20 * TickSize, Color.Red);
                                              
                                          }
                                          
                                          //Strategy 2
                                          if (Bars.BarsSinceSession >=7)
                                              
                                          if ( Close[0] >= EMA(30)[0])
                                          {
                                              enterLongStrat2 = true;
                              [B][COLOR=Blue] // [/COLOR][/B]        enterLongStrat1 = false; [COLOR=Blue]now, then [B]both[/B] conditions can [B]never[/B] be simultaneously true if you have this[/COLOR]
                                          DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 30 * TickSize, Color.Blue);
                                              
                                          }
                                          
                                          if (Bars.BarsSinceSession >=7)
                                          if(enterLongStrat2 == true && enterLongStrat1 == true)
                                          {    
                                                EnterLong(DefaultQuantity, "");
                              
                                          }
                                      }
                              
                                      #region Properties
                                      [Description("")]
                                      [GridCategory("Parameters")]
                                      public int MyInput0
                                      {
                                          get { return myInput0; }
                                          set { myInput0 = Math.Max(1, value); }
                                      }
                                  
                                      
                                      #endregion
                              If you turn off the bool for all other conditions when any one is true, then you will always have only one true bool. That is not quite what I suggested.

                              Corrections are in blue in your code.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Working...
                              X