• 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

Get Dataseries Index in Initialize Routine

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

    Get Dataseries Index in Initialize Routine

    Hi

    Within Initialize() I add dataseries with add(). One special dataseries is my riskfree-data and I must know at which position in the dataseries arry it is saved.
    Example A:
    Instrument1: SP500
    Instrument2: RiskFreeData Series

    --> The riskfree data series is saved with index=1

    Example B:
    Instrument1: SP500
    Instrument2: WorldIndex
    Instrument3: RiskFreeData Series

    --> The riskfree data series is saved with index=2

    I want to save this during Initialize(), e.g.:
    RiskFreeIndex=

    however when I want to assign count to a variable, then I get the error that this is not accessible during.
    Is there a way to save it?

    #2
    Hello Beauregard,

    The series will be added in the order you have the syntax as you have demonstrated. If you know this will be index 1, the most simple way to use this in your logic is to use use the number 1 where you want to reference this series:

    Code:
    if(BarsInProgress == 1)
    If you want to be more descriptive in your variables you can make a constant int variable for this:

    Code:
    private int riskFreeSeries = 1;
    
    protected override void OnBarUpdate()
    {
        if(BarsInProgress == riskFreeSeries)

    I am curious why the index would change in your example, are you referring to when you make changes while developing the script and add a new series in an order that was not used previously?



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      hi Jesse

      thanks for the feedback. this does not solve my problem. Why? Because I pass in my strategy up to 4 instruments. The risk free instrument is added always, at the end. Therefore it is once number 1, and once 3 etc. And I cannot add it as first to be 0, because a lot of my existing code relies on the fact that the first added instrument is the main instrument

      Comment


        #4
        Hello Beauregard,

        Are you adding series in a dynamic way? Why would the position of the series change?

        If you are actively developing the script and the order changes, using a variable would work you just need to remember to change the value when you update your series. That is really up to you to remember to do if you are changing the series around as your logic would rely on the order you add them.

        If you are adding instruments dynamically I would have no suggestion for that use case. Dynamically adding series is not a supported way to add data in a script so you would need to come up with your own system there if that is the use case. You could check the instrument name you passed in or do other logic to try to determine what order your logic used, that would really depend on what you made.


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          hi Jesse

          yes, this is what I am doing instead, I have my own counter and save it finally in a variable. Just thought if there is a way by NT itself, it would be better
          thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pstrusi, Today, 09:06 AM
          0 responses
          4 views
          0 likes
          Last Post pstrusi
          by pstrusi
           
          Started by vpzdcv, Today, 02:31 AM
          0 responses
          9 views
          0 likes
          Last Post vpzdcv
          by vpzdcv
           
          Started by YevhenShynkarenko, Today, 01:22 AM
          1 response
          20 views
          0 likes
          Last Post YevhenShynkarenko  
          Started by ttodua, Today, 12:52 AM
          0 responses
          8 views
          0 likes
          Last Post ttodua
          by ttodua
           
          Started by ttodua, Today, 12:50 AM
          0 responses
          8 views
          0 likes
          Last Post ttodua
          by ttodua
           
          Working...
          X