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 issues

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

    Multi Instrument issues

    I am attempting to use the Add() feature to compare a custom indicator applied to two different instruments. I have followed the scripts provided for adding second instruments but my code sometimes works, sometimes does not, and I can't find a common denominator. If I add another timeframe (or Range size) and do not deviate from the master instrument input series, then the indicator works without any problems. But once I change instruments on the second series, the code becomes unstable. Below are the three attempts I've used to Add.
    Code:
    //  Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    //  Add(SecondInstrument, PeriodType.Range, Size, MarketDataType.Last);
    //  Add(PeriodType.Range,13);  //This seems to work consistently
    Any further examples of code using a second input series would be appreciated.

    #2
    Tdschulz,

    Please be sure that you are separating the OnBarUpdate() calls using BarsInProgress.

    BarsInProgress : http://www.ninjatrader.com/support/h...inprogress.htm

    Multi Instrument Strategies : http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      The structure of my code is below. Something with calling the second instrument is the issue because calling another size range chart of the same instrument is no problem. I only run into issues when trying to use the SecondInstrument method of Add(). I've tried a few variations of Adding the second instrument including hard coding into the code and still it sometimes works and other times doesn't. The stranger part is that sometimes I load the indicator, it does not come up with anything, I change the data series from "load days" to "load bars" and then it works. Sometimes it's the opposite though.
      I'm starting to feel crazy....

      Code:
      private double Indicator1()
      			{	
      				return ("this area is a combination of custom indicators all using BarArray[0]")
      			}	
      		
      		
      		private double	Indicator2()
      			{	
      				return ("Combination of custom indicators using BarArray[1]")
      			}
      				
      				
      		#endregion
      		
              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
      	   
                Add(SecondInstrument, PeriodType.Range, Size, MarketDataType.Last);
      		
      			CalculateOnBarClose	= false;
                  Overlay				= true;
      			PriceTypeSupported	= true;
      			DrawOnPricePanel    = true;
      			PaintPriceMarkers	= false;
      		
      		}
      		
      		/// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
      			
      		{	
      			
      			if (CurrentBarArray[0] > 0 && CurrentBarArray[1] > 0 )	
              {
      			if (BarsInProgress == 0) 
      			
      			{	
      				
      				
      				
      				if ((Indicator1 > X) && (Indicator2 > X))
      					
      				{
      					
      					BackColor = Color.MediumSeaGreen;
      					
      				}
      Last edited by Tdschulz; 01-09-2012, 09:36 AM.

      Comment


        #4
        Tdschulz,

        Are you passing the BarsArray[0] to the Indicator1 and Indicator2 methods?

        Also, I should have noticed before, this line : Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);

        You cannot access BarsPeriods in the initialize method.

        This : Add(SecondInstrument, PeriodType.Range, Size, MarketDataType.Last);

        Should work fine as long as SecondInstrument is defined.

        I look forward to helping you resolve your issue.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Adam. I found my mistake. I had forgotten "Value_" in front of Size.
          Code:
          public int Value_Size
                  {
                      get { return size; }
                      set { size = value; }
                  }
          Thanks for your help.

          Comment


            #6
            Tdschultz,

            I am happy you have resolved your issue.

            Please don't hesitate to contact us should you require additional assistance.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bmartz, Today, 09:30 AM
            2 responses
            11 views
            0 likes
            Last Post bltdavid  
            Started by f.saeidi, Today, 11:02 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by geotrades1, Today, 10:02 AM
            4 responses
            12 views
            0 likes
            Last Post geotrades1  
            Started by rajendrasubedi2023, Today, 09:50 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by lorem, Today, 09:18 AM
            2 responses
            11 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X