Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator based on 2 instruments

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

    indicator based on 2 instruments

    Hello,
    I want to draw an indicator which applies on a chart with 2 instruments and which uses both instruments prices. In the OnBarUpdate() method, Close(0) refers to the main instrument. What is the object path to acess the 2nd instrument's equivalent " Close(0)" from that method?
    thank you

    #2
    Hello fredp,

    The secondary series close price can be accessed with Closes[1][0]

    Documentation for multiple series scripts is available here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your quick answer but I've got a problem. Maybe because i's not multitime frame instruments, but 2 stocks in the same timeframe.
      I made 3 little tests on a chart with 2 stocks in the same panel and same timeframe, "line on close".
      1st test:
      Plot0.Set(Closes[0][0]);
      =>it's OK (1st stock duplicated )
      2nd test:
      Plot0.Set(Closes[0][0]-Closes[0][0]);
      =>it's OK (dummy indicator flat to 0)
      3rd test:
      Plot0.Set(Closes[0][0]-Closes[1][0]);
      =>(after recompile and reload script) Nothing at all, indicator's line disapears

      just as if Closes[1] was not initialized with the array of the 2nd stock prices.
      did I miss something ?

      Comment


        #4
        Please check log tab of control center for any error messages. Let us know what you find out.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Error Message (translated from french as I am on a french computer)/
          "Error on calling "OnBarUpdate" method for indicator 'diff' on bar 0 : index is out of the limits of the array"
          It seems that the second column of the matrix Closes is not automatically initialized with the 2nd instrument of the context. I thought it was.
          I have read the example of overriding "initialize" but it is to create another time frame with the same instrument or a 2nd "hard-coded" instrument. My aim is to take into account dynamically the second instrument of the chart. Is it possible ?

          Comment


            #6
            That message comes up when attempting to access bar objects that don't exist. Help for this issue is available here:


            All series must be hard coded in. Unfortunately there's no way to read it from other series that are applied to the chart.

            If you're still having trouble getting the indicator to plot:
            Please share the complete script, making sure to include the Initialize method. You can copy-paste into this thread or share the .cs file from:
            My Documents\NinjaTrader\bin\custom\indicator

            Let us know your data provider, the instrument and interval you have it applied to and we can give it a run here.
            Last edited by NinjaTrader_RyanM1; 02-02-2011, 03:47 PM.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              "all series must be hard coded"
              OK
              Last edited by fredp; 02-02-2011, 04:03 PM.

              Comment


                #8
                Yes, you're on the right track. You have no series added to the Initialize method and Ninja won't automatically add this. I would take a look at the sample multiInstrument strategy for an example implementation. Click Tools > Edit NinjaScript > Strategy > SampleMultiInstrument
                Documentation for this is here:
                Last edited by NinjaTrader_RyanM1; 02-02-2011, 04:02 PM.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  "all series must be hard coded"
                  OK, so I cannot really do what I want
                  thank you

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  602 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  347 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
                  559 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  558 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X