Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with 2 instruments in indicator

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

    Need help with 2 instruments in indicator

    Hi,

    I want to plot the percentual difference between two instruments. I was going to use ROC indicator as a "template".

    My pseudo code something like this

    Value[0] = (EURUSD[0] - inputPeriod) / inputPeriod) * 100;
    Value[1] = ((EURCAD[1] - inputPeriod) / inputPeriod) * 100;
    Diff[0] = Value[0] - Value[1]

    Plot = Diff[0]

    My first question is; how and where do I declare the instruments? Is there an indicator already that could accomplish above (I'm obviously not good at coding indicators)?

    Many thanks in advance!

    br,
    Chris

    #2
    Hello suroot,

    Thanks for your post.

    To add instruments to your code you would use AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

    As you would be creating a multi-series indicator, you would need to review the contents of: https://ninjatrader.com/support/help...nstruments.htm

    You may want to review the NT8 indicator SpreadOscillator as it sounds similar to what you want to do and/or may provide a starting means for your indicator: https://ninjatrader.com/support/foru...hp?&linkid=687

    Comment


      #3
      Thanks Paul!

      Do you manage to spot my error in the below code/logic?

      Code:
      			else if (State == State.Configure)
      			{
      					AddDataSeries(FirstInstrument, Data.BarsPeriodType.Minute, BarsPeriod.Value, Data.MarketDataType.Last);
      					AddDataSeries(SecondInstrument, Data.BarsPeriodType.Minute, BarsPeriod.Value, Data.MarketDataType.Last);
      			}
      		}
      
      		protected override void OnBarUpdate()
      		{
      			if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot || CurrentBars[2] < BarsRequiredToPlot) 
      				return;
      				double inputPeriod	= Input[Math.Min(CurrentBar, Period)];
      			
      				double FirstValue = ((Closes[1][0] - inputPeriod) / inputPeriod) * 100;
      				double SecondValue = ((Closes[2][0] - inputPeriod) / inputPeriod) * 100;
      				Spread[0] = FirstValue - SecondValue;
                      }
      Thanks!

      br,
      Chris

      Comment


        #4
        Hello suroot,

        Thanks for your reply.

        If you are not getting the expected values or are experiencing errors, I recommend you use print statements in your code to resolve what data is being used or how far the code gets before an error occurs. This type debugging will help you to isolate to the line(s) causing whatever issues there are and then isolate further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        598 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X