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

Level 2 Book Example Syntax Question

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

    Level 2 Book Example Syntax Question

    This should be an easy one.... I am going through the Level 2 book example code, and I can reverse engineer it to a point. But what I need to be able to do is convert each row in the list into a column. So instead of having 1 column with 10 rows in this output, I could run several different filters on it and then 10 columns. Code example:

    Print("Ask Book " + GetCurrentAsk());
    for (int idx = 0; idx < askRows.Count; idx++)
    Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + "Prior Volume" + askRows[idx].PriorVolume +" Position=" + idx);

    So I suppose what I am looking for is a way to say when row is in position 0 or position 3 or position 6 then do..... And for each of these I will just take the output and make a new column. Is there any simple way to move through this list by filtering on row position?

    Thanks in advance!

    Ian

    #2
    Hello iantg,

    Thank you for the post.

    Regarding the position, if you have used the code from the sample we provide, the e.Position is used to insert items into the correct position of the lists. With that being inserted in that way, you should be able to just use index-based access if you wanted to know the 3rd position for example that would just be index 2 of the list.

    Can you confirm, are you asking how to use the askRows and then say I wan the position 0 or 3 data?

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse, Yes this is correct. And we are on the same page with the concept. I just need the syntax. I have tried a few things but haven't quite got it working. So what we have from the example code is this:

      Print("Ask Book " + GetCurrentAsk());
      for (int idx = 0; idx < askRows.Count; idx++)
      Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + "Prior Volume" + askRows[idx].PriorVolume +" Position=" + idx);

      And ultimately what I need is something like this:

      Header Columns:

      AskPrice1 AskVolume1 AskPrice2 AskVolume2 AskPrice3 AskVolume3, etc.

      Any syntax notes would save me some headache.

      I appreciate it.

      Ian

      Comment


        #4
        Hello iantg,

        If you are just trying to use the position, you could use a direct index instead of a loop is this what you are asking to do?

        Code:
        Print("Ask Price=" + askRows[0].Price + " Volume=" + askRows[0].Volume + "Prior Volume" + askRows[0].PriorVolume +" Position=" + 0);
        This would be the first row or index 0.


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

        Comment


          #5
          Thanks Jesse, I will take a stab at it with the approach you suggested and circle back if I hit any snags.
          Thanks!

          Ian

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,607 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          9 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          6 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          15 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X