Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator using another instrument which is not loaded

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

    Indicator using another instrument which is not loaded

    Hi,

    I've made some scripts which compare two stocks in their prices and I'm finding that if the script is using a symbol for the secondary stock which has not been viewed in a NT chart (and thus had the data loaded), that the indicator does not work.

    Is there a way to force the data for the secondary stock symbol to load when the script initializes? If so, how would I do that?

    If there is no way, does that mean I have to open charts for each of the secondary symbols before my indicator would work?

    Thanks

    #2
    No, secondary symbols don't have to be loaded in a chart. But NT7 will only call OnBarUpdate after "BarsRequired" bars of data are available for all instruments. This can create some surprises - if a secondary symbol doesn't have data in history, and you don't have "get data from server (if available)" checked, then the data is not available, OnBarUpdate will not be called, and your indicator will not plot.

    If that doesn't explain your problem, if you want to see some code samples for how I've done it, I have some multi-instrument indicators in the Indicators area - some are 2-instrument (Correlation, Spread, Beta) and one is for an unlimited number of instruments (Index).

    Comment


      #3
      Right, well I'm talking about it not plotting at all, not just for some bars, I hope you didn't misunterstand me there. I have "get data from server" checked.

      Ok so OnBarUpdate gets called for each instrument, and I'm guessing this is when NT7 tries to get the data if it's not there. However, I have this as the first line of OnBarUpdate:

      Code:
      if (BarsInProgress == 1)//dont update on secondary bars
                  return;
      Does this prevent the OnBarUpdate from downloading data in some way?

      Also, are you saying that if BarsRequired amount of data is not available the instrument will not plot at all or only for some bars?

      Thanks

      Comment


        #4
        braincell, the BarsRequired does have to be satisfied for all symbols used in the script other the indicator would not plot, as no OnBarUpdate() is called. The BIP check you have is just for the calculations, the data is being added before that once the script's Initialize() is called. What time frame are you using in your scripts?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I am using 1 minute charts only for these.

          When I load the chart template, it loads the indicator with the default value as the string for the name of the secondary stock, and it loads just fine. This loads just fine. However, I then change the stock name in the parameters (type string) and the indicator fails to load if the symbol wasn't previously viewed in a separate chart.

          Is there some property I need to set so that it loads the data for the new symbol when the parameter (string) is changed within the Indicators > Parameters menu?

          Comment


            #6
            There would be no property you would need to set, the Initialize() would be called again and changes should be applied, would you mind attaching the your script for a test or send it to support at ninjatrader dot com to my Attn?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              OK I am attaching the file.

              Here is more debugging information:

              -When I closed NT and re-opened it with the same workspace, the chart loaded the secondary symbol even though it was not default (ie it was the last one saved with workspace which would not load before). It also appeared in the eSignal data manager symbols list.

              -I then tried loading another secondary symbol "KEY" via input in the Parameters section and it would not load. It did not appear in the data manager list either. "SINA" didn't work either. I tried it thinking it might have something to do with 1-minute bars not getting filled, but SINA is high volume and it should have them all.

              -I tried loading "OXY" and it loaded just fine, and appeared in the data manager also. Same with GS, V, YHOO, BIDU. None of these were loaded since starting up NT.

              -I viewed SINA in a chart, then typed it into the Properties field, Apply, and the indicator worked this time like expected (mentioned earlier).

              -I tried CSE and it wouldn't load. I requested the symbol vai eSignal data manager, and it appeared in it's list. I refreshed the indicator and it still wouldn't show. I switched to GOOG (works) and back to CSE, still nothing. Then after loading the CSE chart, and refreshing the indicator, it worked.

              Please let me know if you find anything wrong with what I'm doing, I'm still very new to NinjaScript even though I have 5+ years of full time coding experience.
              Attached Files

              Comment


                #8
                Please try the version attached here, it would contain the needed check for enough bars on both series before proceeding with any calcs. Would you still be able to reproduce your issue then?

                Thanks,
                Attached Files
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hey there. I tried that already in the meantime, and I tried the code you sent, the issue is still there, I checked thoroughly and nothing has changed.

                  Can you reproduce my issues? You may have to change stock symbols several times.

                  Comment


                    #10
                    I could not reproduce your issue here with my changes in, what data provider are you using?

                    If this still happens for you even after the update and recompilation of the code - are there any errors in the log tab?

                    Thanks,
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Yes, that's interesting. I tried a few symbols and they loaded OK but then I tried "TSM" and I got this message in the log:

                      The indicator 'Test2' has called the Add() method with an invalid instrument. Either 'TSM' does not exist in the Instrument Manager or the specified exchange has not been configured.
                      I open a chart for TSM and no message in the log, chart loaded ok. I then re-fresh the indicator and it works.

                      What could it be?

                      PS
                      As you know, I can always get the indicator to work provided I load a chart of the symbol first, this is what we're trying to solve ultimately (so they load without me opening a chart).

                      Comment


                        #12
                        braincell, all instruments you wish to load need to be configured and setup in the Instrument Manager. So the first time you load it on a chart, it's added as 'on the fly' instrument to the database - then the next time the indicator calls it it's available. This does not happen if the Indicator calls an instrument that was never called / loaded before. So best would be first setting up all the instruments you need.

                        http://www.ninjatrader.com/support/h...e_database.htm

                        http://www.ninjatrader.com/support/h...stock_symb.htm
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Oh. I see... Well, that's new! I just got used to the way eSignal works so I thought all were automatically added.

                          Thanks!

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            Please try the version attached here, it would contain the needed check for enough bars on both series before proceeding with any calcs. Would you still be able to reproduce your issue then?

                            Thanks,
                            Could you (or someone else) help me with a code snip to see the high, low, or close of that external symbol? From that code example you shared (thanks!) I see where the symbol is "Added", but I don't see how to access that symbol's current (or past) OHLC in order to perform some logic on it.

                            Thanks!
                            Daniel

                            Comment


                              #15
                              Daniel, you would access the added symbols data via Closes, Lows, Highs or Opens - which are arrays that would let you access any bars object at any bars back index -

                              http://www.ninjatrader.com/support/h...nt7/closes.htm
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Frank1000, Today, 03:05 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Frank1000  
                              Started by ntdev, Today, 01:14 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NT-Roland  
                              Started by ct, Today, 02:22 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ct
                              by ct
                               
                              Started by yodaler, Yesterday, 06:12 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post yodaler
                              by yodaler
                               
                              Started by sinpeople, 05-07-2021, 04:38 AM
                              2 responses
                              21 views
                              0 likes
                              Last Post hedgeplay  
                              Working...
                              X