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 algospoke, Today, 06:40 PM
      0 responses
      10 views
      0 likes
      Last Post algospoke  
      Started by maybeimnotrader, Today, 05:46 PM
      0 responses
      8 views
      0 likes
      Last Post maybeimnotrader  
      Started by quantismo, Today, 05:13 PM
      0 responses
      7 views
      0 likes
      Last Post quantismo  
      Started by AttiM, 02-14-2024, 05:20 PM
      8 responses
      169 views
      0 likes
      Last Post jeronymite  
      Started by cre8able, Today, 04:22 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X