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

Set secondary instrument from user input

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

    Set secondary instrument from user input

    I refer to the documentation about AddDataSeries() quoted here:

    "This method should ONLY be called from the OnStateChange() method during State.Configure
    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)."

    So, while I can read and understand what has been said there, I am still looking for a way to enable the user of my indicator to specify the instrument symbol and the time frame, like "MSFT", Minute and 10.

    I created three properties, SecondaryInstrument, SecondaryPeriodType, and SecondaryPeriod so my user can set the values. I then put this line of code in State.Configure of the OnStateChange() method:

    Code:
    AddDataSeries(SecondaryInstrument, SecondaryPeriodType, SecondaryPeriod, Data.MarketDataType.Last);
    It worked, which didn't surprise me, but the documentation is saying that it is unsupported, if I am reading it correctly.

    So I have two questions:

    1) Is this approach really inappropriate; will it cause problems?

    2) If this approach is not supported, how can I enable my indicator user to specify the instrument and time frame for my indicator?

    Thanks!
    sh_daggett
    NinjaTrader Ecosystem Vendor - NinjaLaunchpad

    #2
    Hello sh_daggett,

    Thank you for your post.

    You have performed this correctly. The documentation is referring to setting the AddDataSeries() based on the primary series values. For example, the following would be incorrect:
    Code:
    AddDataSeries(Secondaryinstrument, Bars.BarsPeriod.BarsPeriodType, Bars.BarsPeriod.Value);
    The above would be incorrect as the data has not loaded (State.DataLoaded) for the primary series yet.

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      Thanks for your speedy reply. You folks are awesome!

      I think I understand your reply. Here's how I understand it: The code sample you provided won't work because it is referring to the primary series from within State.Configure, which it can't do because that series has not loaded yet. However, I can legally use user inputs (obtained from the Indicators Properties panel) in the AddDataSeries method from within State.Configure without concern.

      Let me know if I get it wrong, and thanks again for your quick reply!
      sh_daggett
      NinjaTrader Ecosystem Vendor - NinjaLaunchpad

      Comment


        #4
        That is correct!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DayTradingDEMON, Today, 09:28 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by George21, Today, 10:07 AM
        0 responses
        8 views
        0 likes
        Last Post George21  
        Started by navyguy06, Today, 09:28 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        8 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X