Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Instrument Orders not getting submitted

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

    Multiple Instrument Orders not getting submitted

    Hi all,
    Not sure what I am missing here. This strategy tries to submit a long order for one ETF on an SMA above crossover and a long order on another ETF on an SMA cross below. It also exits the other corresponding longs so you are only long one of the 2 funds at a given time.

    When backtesting from June 2011, if never enters the long position on the second fund (noted in code comment below). The Print("CrossBelow Detected") is printed in the output window and the ExitLong("Primary Fund") appears to work. There is not a singal order places for the secondary ETF. Why does the EnterLong not work on bar index 1 (secondary ETF)?


    Code:
    	public class ETFMACrossover : Strategy
    	{
    		#region Variables
    		private int		fast	= 3;
    		private int		slow	= 25;
    		#endregion
    
    		private DataSeries _ratioMA;
    		
    		/// <summary>
    		/// This method is used to configure the strategy and is called once before any strategy method is called.
    		/// </summary>
    		protected override void Initialize()
    		{		
    			//Primary instrument will be ETF: HYLD period = day
    			Add("SHY", PeriodType.Day, 1); //Secondary fund
    			
    			//This series will hold the ratio of close prices for the primary and secondary fund
    			//i.e. Close[Fund1]/Close[Fund2]
    			_ratioMA = new DataSeries(this, MaximumBarsLookBack.Infinite); 
    			
    			CalculateOnBarClose	= true;
    		}
    
    		/// <summary>
    		/// Called on each bar update event (incoming tick).
    		/// </summary>
     		protected override void OnBarUpdate()
    		{			
    			if (BarsInProgress != 0)	//process on primary bars only
    				return;
    
    			double ratio = Close[0] / Closes[1][0];  //Ratio of Primary Fund Close to secondary Fund Close
    			_ratioMA.Set(ratio); //populate new ratio MA Series
    
    			if (CrossAbove(SMA(_ratioMA, Fast), SMA(_ratioMA, Slow), 1)) 
    			{
    				Print("CrossAbove Detected");
    				ExitLong(1, 100, "Exit Secondary Fund", "Secondary Fund");			
    				EnterLong("Primary Fund");
    			}
    			else if (CrossBelow(SMA(_ratioMA, Fast), SMA(_ratioMA, Slow), 1))
    			{
    				Print("CrossBelow Detected");
    				ExitLong("Primary Fund");
    				EnterLong(1, 100, "Secondary Fund");	//*** THIS ORDER NEVER GETS SUBMITTED
    			}
    		}
    
    		#region Properties
    		/// <summary>
    		/// </summary>
    		[Description("Period for fast MA")]
    		[GridCategory("Parameters")]
    		public int Fast
    		{
    			get { return fast; }
    			set { fast = Math.Max(1, value); }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Description("Period for slow MA")]
    		[GridCategory("Parameters")]
    		public int Slow
    		{
    			get { return slow; }
    			set { slow = Math.Max(1, value); }
    		}	
    		
    		#endregion
    	}

    #2
    Hi fperugini,

    I have added your code to a strategy and I am currently testing this.

    So far I found that if I do not allow the primary instrument to trade by commenting out the order entries for this, the secondary instrument is trading (SHY).

    What is the Entries per direction set to in the strategy parameters?

    Its likely that the ExitLong does not change the position in time for the other order to be entered.

    If you change the Entries per direction to 2, does this resolve the issue?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      Entries per direction was set to 1. I set it to 2 and now it is working. Thank you.
      -Frank

      Comment


        #4
        Hello fperugini,

        An alternative fix would be to detect the trigger, exit the position with ExitLong, then in the OnExecution or OnPositionUpdate, detect that the exit order has filled before placing the order on the other instrument.

        This would ensure that the order places as the number of entries in that direction will be 0 once the position updates.

        Below is a link to the help guide on OnPositionUpdate().
        http://www.ninjatrader.com/support/h...tionupdate.htm
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X