Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

is there any way to record volumes (ask size and bid size)

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

    is there any way to record volumes (ask size and bid size)

    Hi guys,

    I'm making myself a tick collector to read market data and save it in a file. I can't find in MarketDataEventArgs something to give an AskSize or BidSize. Is it really missing? Also a field with the time of the quote in server time?

    #2
    fxeconomist, you can get all of these bits of info from the OnMarketData() method - http://www.ninjatrader.com/support/h...aeventargs.htm.
    Code:
    if (e.MarketDataType == MarketDataType.Ask)
       int askVolume = e.Volume;
    // same for bid
    
    // time field. this can be timestamped by either your pc or the server, depending on the provider
    DateTime updateTime = e.Time;
    AustinNinjaTrader Customer Service

    Comment


      #3
      In the previous post, I linked to the MarketDataEventArgs, which shows everything available. Please also take a look at the actual reference page for OnMarketData() - there is an example for how to grab both price and volume from the feed.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Austin View Post
        fxeconomist, you can get all of these bits of info from the OnMarketData() method - http://www.ninjatrader.com/support/h...aeventargs.htm.
        Code:
        if (e.MarketDataType == MarketDataType.Ask)
           int askVolume = e.Volume;
        // same for bid
        
        // time field. this can be timestamped by either your pc or the server, depending on the provider
        DateTime updateTime = e.Time;
        A bit of a silly question, it doesn't seem to recognize the DateTime type! Should it be in a special using directive? I downloaded the [URL="http://www.ninjatrader.com/support/forum/showthread.php?t=19292"SampleDateTimeFunctions.zip[/URL] but it doesn't seem to have an extra using directive. What should I do?

        Comment


          #5
          Hi again, what is the exact syntax you're using here? I just created a simple sample to test this out and everything is working as expected.
          Attached Files
          AustinNinjaTrader Customer Service

          Comment


            #6
            struct QuoteStruct {
            public int BarIndex;
            public long BidSize, AskSize, LastSize;// fields
            public double Bid, Ask, Last;
            public DateTime Timestamp;
            public void Quote() { this.BidSize=0;this.AskSize=0;this.Bid=0.0;this.As k=0.0; }
            }

            It doesn't recognize the DateTime type. Also, another issue. I have the symbols that I want to add, symbol1, symbol2, symbol3... as strings, which I am loading in the Initialize in string Symbols[]. At the end of the end of the Initialize(), I have:

            for (int i=0;i<SymbolCount;i++)
            {
            Add(Symbols[i],PeriodType.Tick,1);
            Quotes[i].BarIndex=i;
            }

            On the Add line, I have "cannot convert from 'string' to NinjaTrader.Data.PeriodType) ! The compiler strongly believes that the Add uses prototype 3 of 4 , meaningly StrategyBase.Add(PeriodType periodType, int period). It doesn't want to understand that I want to use prototype 2 of 4, StrategyBase.Add(string InstrumentName, PeriodType periodType, int period). It forces to typecast the string in a PeriodType, and , of course, crashes.

            Comment


              #7
              I just copied + pasted your quote struct code into the sample I sent you and everything compiled fine. How are you trying to use the struct? This is unfortunately beyond the level of support we can provide.

              As for the symbol addition, NinjaTrader currently doesn't support adding instruments programmatically.
              AustinNinjaTrader Customer Service

              Comment


                #8
                Hmm, now it accepts that. It has issues with switch (e.MarketDataType). Says that "control cannot fall through one case label ('case 0') to another" and so on, for each branch. Guess this can be solved using if instead of switch.

                Now, if it doesn't support adding symbols programatically, then how should I add the symbols? Is it a way, in the wizard?

                P.S. I don't have Visual C# installed. I edit and compile using the built-in editor and compiler from NinjaTrader. Should I install Visual C# instead?

                Comment


                  #9
                  To add symbols, you can do it with NinjaScript, but not with a loop or anything like that:
                  Code:
                  Add("ES 09-11", PeriodType.Minute, 1);
                  Add("YM 09-11", PeriodType.Minute, 1);
                  Add("SPY", PeriodType.Minute, 1);
                  /// etc
                  You can certainly use Visual C# if you want, however, we don't support Visual C#. The regular NinjaScript editor should be fine for 99.5% of our users.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Do you mean that the instrument symbol must be hardcoded inside the Add call? like Add("ES 09-11",PeriodType.Tick), which works, while string instr="ES 09-11";Add(instr,PeriodType.Tick) will fall?

                    Comment


                      #11
                      Originally posted by fxeconomist View Post
                      struct QuoteStruct {
                      public int BarIndex;
                      public long BidSize, AskSize, LastSize;// fields
                      public double Bid, Ask, Last;
                      public DateTime Timestamp;
                      public void Quote() { this.BidSize=0;this.AskSize=0;this.Bid=0.0;this.As k=0.0; }
                      }

                      It doesn't recognize the DateTime type. Also, another issue. I have the symbols that I want to add, symbol1, symbol2, symbol3... as strings, which I am loading in the Initialize in string Symbols[]. At the end of the end of the Initialize(), I have:

                      for (int i=0;i<SymbolCount;i++)
                      {
                      Add(Symbols[i],PeriodType.Tick,1);
                      Quotes[i].BarIndex=i;
                      }

                      On the Add line, I have "cannot convert from 'string' to NinjaTrader.Data.PeriodType) ! The compiler strongly believes that the Add uses prototype 3 of 4 , meaningly StrategyBase.Add(PeriodType periodType, int period). It doesn't want to understand that I want to use prototype 2 of 4, StrategyBase.Add(string InstrumentName, PeriodType periodType, int period). It forces to typecast the string in a PeriodType, and , of course, crashes.
                      You may want to declare your struct in the more traditional style, where it assigns values within its structure, and uses an internal declaration to return the struct.

                      ref: http://msdn.microsoft.com/en-us/library/0taef578.aspx

                      Your struct is not declared wrongly. It is just much easier to work with and debug, when one uses the style referenced. At least for me. YMMV.

                      Comment


                        #12
                        I think the editor is buggy. I removed the switch() structure and replaced with if . Still, i was having the same errors after saving, at compile. Then I got pissed off , closed, reopened file and recompiled. No errors.

                        Comment


                          #13
                          No, it doesn't have to be hardcoded, but it doesn't work with loops. This, for example, works fine:
                          Code:
                          private string inst = @"ES 09-11";
                          
                          Initialize()
                          {
                             Add(inst, PeriodType.Minute, 1);
                          }

                          What errors were you having that were resolved with the restart?
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by koganam View Post
                            You may want to declare your struct in the more traditional style, where it assigns values within its structure, and uses an internal declaration to return the struct.

                            ref: http://msdn.microsoft.com/en-us/library/0taef578.aspx

                            Your struct is not declared wrongly. It is just much easier to work with and debug, when one uses the style referenced. At least for me. YMMV.
                            Man, I never programmed in C# before (think I played with it once 5 years ago). This is quite my first time. I don't understand which would be the "traditional style", but indeed on the MSDN page it says that using the constructor without parameters should be an error.

                            Comment


                              #15
                              Originally posted by NinjaTrader_Austin View Post
                              No, it doesn't have to be hardcoded, but it doesn't work with loops. This, for example, works fine:
                              Code:
                              private string inst = @"ES 09-11";
                              
                              Initialize()
                              {
                                 Add(inst, PeriodType.Minute, 1);
                              }

                              What errors were you having that were resolved with the restart?
                              Man, this is nice. It doesn't work in loops, but it still works programatically.

                              About the errors, I had errors because i was using a switch e.MarketDataType : "control cannot fall through one case label ('case 0') to another" also for case 1 and case 2. Even after I removed, saved, compile was saying the same thing. Sure the editor is glitchy. Perhaps that's why it said in the begining that it doesn't recognize DateTime type. But I don't think this is too serious bug. I can live with it.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              590 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              342 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              555 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X