Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multi instrument Strategy - same conditions

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

    Multi instrument Strategy - same conditions

    Hi all, I have a strategy that I want to run in multiple instruments. As you can imagine can´t get it to work. So far, I have done this:

    Add data series for second instrument:

    Code:
    Add("M6J", PeriodType.Day, 1);

    I want to enter and close a trade everytime this happens in each instrument. I´ve tried this way:

    Code:
    if (BarsInProgress == 0)
    		{	
    		
    	// Condition set 1
               if (ATR(12)[0] > ATR(48)[0])
                    
                {
                    EnterLong(DefaultQuantity, "");
                }
    			
                // Condition set 2
                if (ATR(12)[0] < ATR(48)[0])
                {
                    ExitLong("", "");
                }
    		}
    		
    
    	if (BarsInProgress == 1)
    		{	
    		
    	   // Condition set 1
               if (ATR(BarsArray[1],12)[0] > ATR(BarsArray[1],48)[0])
                    
                {
                    EnterLong(DefaultQuantity, "");
                }
    			
                // Condition set 2
                if (ATR(BarsArray[1],12)[0] < ATR(BarsArray[1],48)[0])
                {
                    ExitLong("", "");
                }
    		}


    But after backtesting in srategy analizer, only trades the primary intrument. There´s no trades for second, third, etc... instruments.

    How do you tell NT to trade the second instrument (or the third, fourth, etc... any other)? I mean, EnterLong("TRADE M6J""")

    Did I do something wrong? I guess I did.

    Thank you!!

    #2
    Hello tomaslolo,

    Thanks for your post.

    When your code isn't executing as expected you can use Print statements to verify that the code block is being reached. For example:

    if (ATR(BarsArray[1],12)[0] > ATR(BarsArray[1],48)[0])

    {
    Print ("Condition set 1 of BarsInprogress 1 true at: "+ Times[1][0]); //debug print
    EnterLong(DefaultQuantity, "");
    }

    Other debugging tips can be found here: https://ninjatrader.com/support/foru...ead.php?t=3418

    We recommend that you use the Entry order method overload that includes the BarsInProgress index: EnterLong(int barsInProgressIndex, int quantity, string signalName), as identified here: https://ninjatrader.com/support/help...?enterlong.htm

    In addition, please review the section, " Entering, Exiting and Retrieving Position Information" here: https://ninjatrader.com/support/help...nstruments.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Ninja_Trader_Paul, I had to delete these lines in order to let run the script

      Code:
      if (BarsInProgress == 0)
      Code:
      if (BarsInProgress == 1)
      I suppose BarsinProgrees can be used for different TimeFrame series.

      Thank you very much,

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Radano, 06-10-2021, 01:40 AM
      20 responses
      616 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by Mizzouman1, Today, 07:35 AM
      0 responses
      4 views
      0 likes
      Last Post Mizzouman1  
      Started by i019945nj, 12-14-2023, 06:41 AM
      6 responses
      66 views
      0 likes
      Last Post i019945nj  
      Started by aa731, Today, 02:54 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by BarzTrading, Today, 07:25 AM
      0 responses
      3 views
      0 likes
      Last Post BarzTrading  
      Working...
      X