• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Questions about AddDataSeries() and Secondary PriceBars

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

  • Questions about AddDataSeries() and Secondary PriceBars

    Hello,

    It seems like the NT8 AddDataSeries() method and secondary pricebars handling is significantly better than it was in NT7. First off, thank you! Secondly, I have some questions about these things:

    Question #1: Is it true that in NT8, calling AddDataSeries() twice (in the appropriate OnStateChange() "else if (State == State.Configure)" branch) with the exact same values always adds 2 secondary pricebars to the strategy, instead of adding the secondary pricebars once?

    For instance, if I create a strategy with 2 input parameters of type "string" called "Symbol1" and "Symbol2", and the user decides that they want both symbols to be "SPY", will 2 secondary pricebars always be added?

    Code:
    AddDataSeries(Symbol1, Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);	
    AddDataSeries(Symbol2, Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    Is there any case where NT8 wouldn't add one secondary pricebars series for each call of "AddDataSeries()"?


    Question #2: I noticed that both input parameters and internal variables declared in the NT8 Strategy Builder get assigned a default value in OnStateChange() "if (State == State.SetDefaults)" branch. Is it safe to use any input param or internal variable as one of the parameters passed to AddDataSeries(), and it is a safe assumption that the default values assigned to the input param or internal variable will be the value that is used?


    Question #3: Why does the NT8 Strategy Builder "Add Additional Data" dialogbox disable the "Price based on (last, bid, ask)" combobox when "Use primary instrument" is checked? Does this mean that as a NinjaScript programmer, I shouldn't be calling "AddDataSeries()" using the primary instrument as the symbol but using Bid or Ask data instead of "Last" data?


    Thank you very much in advance,

    EquityTrader

  • EquityTrader
    replied
    Hi NinjaTrader_AlanP,

    Thank you for the explanation. You've answered all my questions for now, and I appreciate it.

    Best regards,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    Aside from direct mention that null can be used for isResetOnNewTradingDay and not for the other parameters, it’s reasonable to assume that isResetOnNewTradingDay is not dependent on run-time variables, given the user sets this when applying the strategy.

    Please let us know if you need further assistance.

    Leave a comment:


  • EquityTrader
    replied
    Hi NinjaTrader_AlanP,

    Thank you for your answer.

    For the sake of completeness, I do want to point out an exception to the quote you posted, which is literally on the same page ( https://ninjatrader.com/support/help...dataseries.htm ) as the quote you posted:

    In the grid titled "Parameters", the description for the "isResetOnNewTradingDay" parameter of the AddDataSeries() method includes the following statement:

    *Will accept true, false or null as the input. If null is used, the data series will use the settings of the primary data series.
    So on the same page that we are warned to not rely on such run-time variables as the value for "isResetOnNewTradingDay" of the primary data series, we are told that we are allowed pass "null" to "isResetOnNewTradingDay" to use the settings of the primary data series.

    It was this ability of "isResetOnNewTradingDay" to use the value from the primary data series at run-time that gave me hope that maybe some of the other parameters to "AddDataSeries()" could also break the rule stated in the quote you posted, but evidently, this very desirable flexibility of the "isResetOnNewTradingDay" parameter unfortunately is unique to it and it alone.

    I suggest that one of these two contradictory statements on this help page be modified so that they can both be true.

    Thank you,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    That would not be recommended.

    As stated in the helpguide,

    Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.
    https://ninjatrader.com/support/help...dataseries.htm

    Please let us know if you need further assistance.

    Leave a comment:


  • EquityTrader
    replied
    Hi NinjaTrader_AlanP,

    Thank you for your response. Too bad... I was really hoping I had found a safe and reliable workaround to this rather limiting aspect of the NT8 API's AddDataSeries() method.


    Moving on to another topic... I noticed that passing "null" for the "tradingHoursName" parameter ends up creating a secondary data series with a Trading Hours Template that is the default one for the secondary symbol. For instance, if the primary series is "SPY" and the secondary symbol is "AUDUSD", the Trading Hours Template for the secondary "AUDUSD" series is "Forex".

    Question #2: Is it safe to pass "null" for the "tradingHoursName" parameter, if the objective is to create a secondary data series that uses the default "Trading Hours Template" for the secondary data series, so long as all other parameters to AddDataSeries() are 100% hard-coded literal values, like "SPY"?

    Thank you in advance,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    No, "null" is not safe for the same reason using the code below is not suggested. While it may work, like the code below, its not suggested.

    Code:
    AddDataSeries(Instrument.FullName, new BarsPeriod() { MarketDataType = BarsPeriod.MarketDataType, BarsPeriodType = BarsPeriod.BarsPeriodType, Value = BarsPeriod.Value * 8}, Instrument.MasterInstrument.TradingHours.Name, null);
    Please let us know if you need further assistance.

    Leave a comment:


  • EquityTrader
    replied
    Passing "null" for instrumentName to AddDataSeries() == Primary instrumentName?

    Hello,

    In the previous posts in this thread, it has been agreed that the following line of code is not safe:

    Code:
    AddDataSeries(Instrument.FullName, new BarsPeriod() { MarketDataType = BarsPeriod.MarketDataType, BarsPeriodType = BarsPeriod.BarsPeriodType, Value = BarsPeriod.Value * 8}, Instrument.MasterInstrument.TradingHours.Name, null);
    For the following reason, copied from the NT8 user manual:

    Note: All additional data series must be added in State.Configure. Since objects such as Instrument, BarsPeriod, TradingHours, etc. are NOT guaranteed to be available until State.DataLoaded, you cannot reliably use the primary instrument properties as arguments in AddDataSeries(). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. In some cases, you may be able to use a BarsRequest() to obtain market data for other instruments and intervals.
    It was also determined that there is no possible way to pass the "Primary Data Series' Instrument Name" into any "AddDataSeries()" method overload that accepts "instrumentName" as a parameter.

    I believe that this conclusion might be incorrect. While it isn't safe to pass "Instrument.FullName" as the first parameter to this method, I've discovered that passing "null" (without the quotes) as the first parameter seems to reliably create the secondary data series with the instrumentName of the primary data series.

    Question: Is it true that passing "null" (without the quotes) as the first parameter to the AddDataSeries() method above safely and reliably sets the instrumentName to the Primary DataSeries' InstrumentName?


    Thank you in advance,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    Your suggestion is being tracked under feature request ID, SFT-2032.

    Please let us know if you need further assistance.
    Last edited by NinjaTrader_AlanP; 03-30-2017, 12:35 PM.

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    Thank you for your suggestion, I have included it with your feature request.

    Please let us know if you need further assistance.

    Leave a comment:


  • EquityTrader
    replied
    Hi NinjaTrader_AlanP,

    Thank you very much for your help on this, both for your answer and the feature request.

    I have a suggestion for a feature request regarding this issue that would solve many more problems for NinjaScript developers than only adding one more specific method overload like "AddDataSeries(BarsPeriodType periodType, int period, string tradingHoursName)", which is:

    Feature Request: It should be possible to create a Secondary Data Series with most of its properties exactly matching those of an arbitrary Primary Data Series (i.e. one whose instrumentName, bar period, and other properties are unknown at compile time so can't be hard-coded by the NinjaScript developer), while having some properties that differ from those of the Primary Data Series.

    Probably the simplest way of supporting this feature would be to allow NinjaScript programmers to call the most complete AddDataSeries() method overload with parameter values that refer to properties of the current Strategy, such as Instrument.FullName or BarsPeriod.MarketDataType, like the code below:

    AddDataSeries(Instrument.FullName, new BarsPeriod() { MarketDataType = BarsPeriod.MarketDataType, BarsPeriodType = BarsPeriod.BarsPeriodType, Value = BarsPeriod.Value * 8}, Instrument.MasterInstrument.TradingHours.Name, null);

    To solve the problem described above by adding more AddDataSeries() method overloads, of which there are already eight, is that you will need far more method overloads than the eight that exist already.

    For instance, I asked about solving the same problem for the "isResetOnNewTradingDay" parameter. You would actually need three more overloads just to support the three combinations of these two parameters ("isResetOnNewTradingDay" and "tradingHoursName"), and this would only solve the problem for keeping the instrumentName the same. I would also want to be able to keep the Bar Period Type and Value and the Market Data Type the same, which would cause the number of overloads needed to explode.

    Thank you very much for your help,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    Thank you for your patience.

    I misunderstood your question on 2B; the correct answer is that this is not suggested.

    There is no syntax which would allow you to not specify the instrument name and also include a trading sessions template. I will put a feature request for the syntax,
    AddDataSeries(BarsPeriodType periodType, int period, string tradingHoursName)

    You should hard code the instrument name using the following syntax for now,
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)

    Please let us know if you need further assistance.

    Leave a comment:


  • EquityTrader
    replied
    Hello,

    It's been almost a day and a half since I asked the two questions below.

    Can anyone from NinjaTrader give an official answer to the two questions I asked?

    Thank you very much,

    EquityTrader

    Leave a comment:


  • EquityTrader
    replied
    Hi NinjaTrader_AlanP,

    Thank you for your answers and for your patience.

    Your answer to Question 2B seems to contradict a quote from the NinjaTrader 8 documentation, so I still need your help in determining which is right and which is wrong, or if maybe both answers are right and I am not understanding something.

    In response to the following code...

    Code:
    AddDataSeries(Instrument.FullName, new BarsPeriod() { MarketDataType = BarsPeriod.MarketDataType, BarsPeriodType = BarsPeriod.BarsPeriodType, Value = BarsPeriod.Value * 8}, Instrument.MasterInstrument.TradingHours.Name, null);
    Which calls the following AddDataSeries overloaded method...

    Code:
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
    You wrote:

    2B: Yes, that looks fine.
    However, on the "NinjaScript Best Practices page", located at http://ninjatrader.com/support/helpG..._practices.htm , I found the following quote under its "State management practices" section:

    Note: All additional data series must be added in State.Configure. Since objects such as Instrument, BarsPeriod, TradingHours, etc. are NOT guaranteed to be available until State.DataLoaded, you cannot reliably use the primary instrument properties as arguments in AddDataSeries(). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. In some cases, you may be able to use a BarsRequest() to obtain market data for other instruments and intervals.
    Question 2B-I: Is the code I pasted above really OK to use as you suggested, or in light of the quote NT8 documentation is it actually unsafe to use?

    If the code above is not OK, then could you please answer the following question also:

    Question 2B-II:How can a NinjaScript programmer create a Strategy that can be used on any arbitrary stock in the S&P 500 that also has a secondary data series that differs from the Primary Data Series only in its "tradingHoursName" or "isResetOnNewTradingDay"?

    Note how in the question above, the AddDataSeries() method call can't have a hardcoded instrumentName, and unfortunately there appears to be no AddDataSeries() method overload that lets me set "tradingHoursName" or "isResetOnNewTradingDay" without also having to set the instrumentName. I hope this is not impossible to do.

    Thank you again for your help,

    EquityTrader

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello EquityTrader,

    2A: Yes, it should be a string and not a string variable.

    2B: Yes, that looks fine.

    2C: Every parameter should be hardcoded. From the helpguide “
    Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables..”

    http://ninjatrader.com/support/helpG...dataseries.htm

    Please let us know if you need further assistance.’

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by chartish, Today, 04:43 PM
0 responses
7 views
0 likes
Last Post chartish  
Started by Trader17, Today, 04:07 PM
0 responses
4 views
0 likes
Last Post Trader17  
Started by GussJ, Today, 01:30 PM
2 responses
18 views
0 likes
Last Post GussJ
by GussJ
 
Started by GARZONJ, Today, 12:25 PM
3 responses
17 views
0 likes
Last Post NinjaTrader_PaulH  
Started by RandanAL, Today, 11:53 AM
1 response
13 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X