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

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 samish18, Today, 10:13 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post samish18  
                  Started by kenz987, Yesterday, 10:20 AM
                  2 responses
                  13 views
                  0 likes
                  Last Post kenz987
                  by kenz987
                   
                  Started by nicthe, 08-23-2023, 07:53 AM
                  7 responses
                  196 views
                  0 likes
                  Last Post nicthe
                  by nicthe
                   
                  Started by nicthe, Today, 09:24 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post nicthe
                  by nicthe
                   
                  Started by stalt, 12-28-2015, 01:36 PM
                  6 responses
                  1,536 views
                  0 likes
                  Last Post giulyko00  
                  Working...
                  X