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

AddDataSeries

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

    AddDataSeries

    Hi,

    When I add a data series is there a definitive way to know the associated BarsInProgress index? I understand all the admonitions against using any sort of variables (vs hard coded values), however because I add these data series in a dynamic way (which works just fine), I can't keep a simple count and add that to a dictionary. If I have to I can add a method to map this all out by iterating through the BarsArray at some point but I suspect I am missing something simple given AddDataSeries does not have a return value.

    This all is necessary because I am submitting orders from an external source using SubmitOrderUnmanaged which requires the index of the associated Bars object. I am also going with the assumption that when l add a data series its array index will not change which would in turn allow me to store the index of the added data series as each is added (i.e. BarsArray.Count -1).

    Thanks,
    Scott
    Last edited by ScottB; 07-07-2018, 02:23 PM.

    #2
    Hello ScottB,

    Thank you for your note.

    Would the following work?

    if(BarsInProgress==1)
    Print(Bars.Instrument.FullName.ToString());

    Whereas on a BIP update for BarsArray1, the instrument name will be printed out.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Alan,

      Thank you for getting back to me so quickly. The issue relates to going the other direction. I have a function SubmitOrder(MyOrder order) that makes a call to SubmitOrderUnmanaged(???, OrderAction.Buy...

      MyOrder has a symbol I can use to do a look up of some sort in my method SubmitOrder to get the proper selectedBarsInProgress. My hope is that there is a mapping somewhere of data series to BarsArray index so ES 09-18 would map to data series 0 (BarsInProgress = 0) once State == State.DataLoaded. This would allow me to do a mapping myself otherwise I have to do it as each new data series is added which given the multiple calls to OnStateChange() storing anything seems a bit sketchy.

      Comment


        #4
        Hello ScottB,

        How are you dynamically adding these data series?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Alan,

          First of all, I want to let you know I have sorted out my original issue, the clue being that the Positions array and the BarsArray have the same associated index.

          As to your question - I add the instruments in OnStateChange (State.Configure). I keep a dictionary that I clear each time I come through the Configure state; this keeps everything clean. I have an external data base where I map the CME symbols to the ones NinjaTrader uses (i.e. ES8U -> ES 09-18) and use a foreach loop to go through the dictionary (it is loaded in an external dll).

          AddDataSeries(kvp.Value.LocalSymbol, BarsPeriodType.Tick, 1);

          I know the index of the last entry into the BarsArry is always BarsArray.Length - 1 since it is just added and with each pass through OnStateChange() the BarsArray is reset so only the chart symbol is in the array. I use AddOrUpdate to avoid any key collisions (in case the order changes, I update the instruments' new position in the BarsArray.

          Once I get to State - State.Data loaded, I print the dictionary out to make sure everything is aligned and off I go. It works exactly as intended at this point.

          Comment


            #6
            Hello ScottB,

            Interesting, thank you for sharing.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Alan,

              You are quite welcome; if there are any technical details of interest please feel free to ask.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              40 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X