Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Multiple Instruments?

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

    Custom Multiple Instruments?

    Maybe I'm missing something, I'm a n00b to stocks and NT, but an experienced programmer..

    Basic example:
    I have a strategy that:
    - takes any 2 stocks, A and B.
    - at 9 AM, longs A buying 10 shares, goes long on B buying 20 shares
    - at 4 PM, exits both positions.

    Can you point me in the right direction in terms of specifying 2 instruments? I see EnterLong() but I don't see a way to specify an instrument for the EnterLong function:


    How can I specify multiple instruments for a strategy and then refer to them for entry and exit?

    Here is some pseudocode. (Untested, just to demonstrate what I want to do.)
    Code:
    		protected override void OnBarUpdate()
    		{
    			
    				if ((ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 100000)) {
    					if (!this.hasEnteredA) {
    						EnterLong("SPECIFY SECURITY A at 10 shares?");
    						this.hasEnteredA = true;
    					}
    					if (!this.hasEnteredB) {
    						EnterLong("SPECIFY SECURITY B at 20 shares?");
    						this.hasEnteredB = true;
    					}
    				} else if (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) < 143000))
    				{
    					if (this.hasEnteredA) {
    						ExitLong("SPECIFY A?");
    						this.hasEnteredA = false;
    					}
    					if (this.hasEnteredB) {
    						ExitLong("SPECIFY B?");
    						this.hasEnteredB = false;				
    					}
    				}
    
    		}
    Last edited by cyman; 06-04-2015, 08:56 AM.

    #2
    Hello,

    Each of the order entry methods, such as EnterLong(), include a constructor overload that will allow you to specify a Bars in Progress index to which to submit the order. In order to accomplish the setup you are looking for, you can first add a secondary data series to the script (Stock B, for example), then refer to that specific data series as the Bars in Progress index when calling your entry or exit methods.

    The overload I'm referring to is EnterLong(int barsInProgressIndex, int quantity, string signalName)

    Below is quick sample of how this can work:

    Code:
     protected override void Initialize()
            {
                CalculateOnBarClose = true;
    			Add("AAPL",PeriodType.Minute,5,MarketDataType.Last);
            }
    
            protected override void OnBarUpdate()
            {
    			if(ToTime(Time[0]) == 90000)
    			{
    				EnterLong(0,1,"entryStockA");
    				EnterLong(1,1,"entryStockB");
    			}
    			
    			if(ToTime(Time[0]) == 140000)
    			{
    				ExitLong(0,1,"exitStockA","entryStockA");
    				ExitLong(1,1,"existStockB","entryStockB");
    			}
            }
    The key is the first value in the constructors of EnterLong() and ExitLong(). "0" refers to the primary data series to which the strategy is applied, and "1" refers to the one we added in Initialize().
    Dave I.NinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

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