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

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
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        11 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        30 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X