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

Historical Bid/Ask Volume Splitter

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

    Historical Bid/Ask Volume Splitter

    Hi there -

    Before NT7 & Zen-Fire's Historical Bid/Ask Tick Data feature, I was using the OnMarketData method like so:

    Code:
     
    if (e.MarketDataType == MarketDataType.Ask)
    {
    askPrice = e.Price;
    return;
    }
    else if (e.MarketDataType == MarketDataType.Bid)
    {
    bidPrice = e.Price;
    return;
    }
    else if (e.MarketDataType != MarketDataType.Last || askPrice == 0 || bidPrice == 0)
    return;
     
    if (e.Price >= askPrice)
    askVolume += e.Volume;
    else if (e.Price <= bidPrice)
    bidVolume += e.Volume;
    Now that I have access to Historical Bid/Ask data, I'm trying to build a similar indicator using the OnBarUpdate method only. On a 500 Tick chart for example, I would need to add these data series?
    Code:
     
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
    I'm stuck on how to split the volume in the OnBarUpdate method...Could one of you coders lend a hand?

    See attached file for a first attempt.
    Attached Files
    Last edited by un$ane; 09-15-2010, 07:24 AM.

    #2
    Correct un$ane, in NT7 you can add those Bid / Ask / Last series to a MultiSeries indicator and then know for example if the OnBarUpdate() is called for the BIP1 you got an update of the bid series. You could then cumulate it's volume in a dataseries synched to the BIP0, your 500 tick chart.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand - Any chance you could provide a code snippet, or make some modifications to my file? I feel I'm close, but need that extra push. There's a free weekend with my girlfriend in it for ya :O

      Also, I'm looking at the Historical Data Manager, and I see 3 data tables each for Tick: 'Ask', 'Bid', and 'Last'.

      The 'Last' table contains a Date, Time, Price, and Volume traded for each tick, correct? The 'Ask' and 'Bid' tables also have these data columns, but is the Volume column traded volume or resting orders?

      Thanks for the help.

      Comment


        #4
        Unfortunately I wouldn't have a snippet handy here un$ane, however you can access the Volume array of all series with Volumes[BIP][Index] - the volume is traded volume for the last and resting for bid / ask.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok...Thank you.

          Comment


            #6
            In the initialize section

            Code:
            Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);		
            Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
            In OnBarUpdate()

            Code:
            if(BarsInProgress == 0) //Main Chart interval
            {
            }
            else if(BarsInProgress == 1) //Bid Tick Chart interval
            {
            }
            else if(BarsInProgress == 2) //Ask Tick Chart interval
            {
            }
            else
            {
            // Just a place holder.  This should never be reached.
            }
            Hope this helps
            mrlogik
            NinjaTrader Ecosystem Vendor - Purelogik Trading

            Comment


              #7
              Is this close?

              The historical values are close to the real-time values...Is that as good as it gets?

              Code:
              public class BidAskVolumeSplit : Indicator
                  {
                      private double askPrice, bidPrice;
                      private double askVolume, bidVolume, totalVolume;
              
                      protected override void Initialize()
                      {
                          Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
                          Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
                          Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
              
                          ClearOutputWindow();
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if (BarsInProgress == 0)
                          {
                              Print(
                                  String.Format(
                                  "Time[0]: {0}\taskVolume: {1}\tbidVolume: {2}\ttotalVolume: {3}\r\n", 
                                  Time[0], askVolume, bidVolume, totalVolume)
                                  );
              
                              askVolume = bidVolume = totalVolume = 0;
                          }
                          else if (BarsInProgress == 1)
                          {
                              askPrice = Close[0];
                          }
                          else if (BarsInProgress == 2)
                          {
                              bidPrice = Close[0];
                          }
                          else if (BarsInProgress == 3)
                          {
                              if (Close[0] >= askPrice)
                              {
                                  askVolume += Volume[0];
                              }
                              else if (Close[0] <= bidPrice)
                              {
                                  bidVolume += Volume[0];
                              }
              
                              totalVolume += Volume[0];
                          }
                      }
                  }
              }

              Comment


                #8
                Hello,

                Looks good! Nice work.

                Comment


                  #9
                  Looks good on the surface but cannot work

                  Because multiple bid, ask, and last events can occur during a single second, while the minimum timestamp resolution is one second, this cannot work. Gomi realized that a long time ago. That's why the GomRecorder exists.

                  Remember that the bid, ask and last data are in SEPARATE files. Within each file, they are in the correct sequence. But the order in which records in the three separate files were recorded relative to each other is NOT preserved anywhere in the file structure. When NT reads the three files on the fly to construct a chart, the only thing it has to go by is the one second timestamps.

                  To characterize each historical trade as a buy or a sell, you need to compare the last price to the current bid and ask. If, for each last price, there are a bunch of different bid and ask prices that have the same time stamp, how can NT know which ones to compare the last price to?


                  IF the bid, ask, and last prices were recorded in sequence in a SINGLE FILE, this would work. But they're not. For that reason, the bid and ask data is of no practical use and those files are a pure waste of I/O and memory..

                  Over the summer I wrote a Cumulative Delta indicator using this approach. It seemed to work, plotting what looked like plausible results. Until I compared them to GomCD and saw that the results from my new indicator were totally way off useless and not consistent with price action like GomCD or what you get live with OnMarketData.

                  Finer timestamp resolution is not the optimal solution. That would be for the historical data for each trade to include not only the last price, but the current bid and ask at that instant, in the same record of the file.

                  Sorry.
                  Last edited by Ricam; 04-16-2011, 09:36 AM.

                  Comment


                    #10
                    Yeah...Figured as much after comparing with the real-time results. Any idea if someone provides historical GomRecorder files for download? And thanks for the elegant explanation

                    Comment


                      #11
                      un$ane,

                      Many, many NinjaTrader users have been waiting for years to get this functionality.

                      This assertion is fairly easy to validate ...
                      • Go to Search Forums (click here)
                      • Enter the word "NinjaTrader" as the keyword in box that says"Search by Keyword",
                      • Under "Sort Results by", select either
                        • "Number of Views", or
                        • "Number of Replies"
                      • Then click on "Search Now"

                      With either search, within the top 3-postings, you will find 2 threads that address this topic (going back to 2007 and wth over 150,000 total viewings and over 1000 total replies).

                      I think this shows that this is the one area that NinjaTrader users have the most agreement about.

                      Gomi's indicator package is well-coded (in a programming style well above that of these forums) and works very well, but unfortunately is high-maintenance, since his recorder's data files are not auto-magically maintained for for us behind the scenes, available for instant downloading from a server that runs all the time like is available with NinjaTrader's historical data servers and replay data severs.

                      Thus outages where NinjaTrader does not run on our system for even short periods of time cause the data to not be recorded and it's real nuisance to fill in the blanks.

                      Good luck.

                      P.S. I now see that you sent me some PMs about this topic.

                      I don't read the forums as often and as regularly as I used to and generally I don't reply to PMs on popular topics like this as I tend to get the same questions over and over again, and often the question...
                      • will get faster attention in the support forums
                      • will have an answer that will benefit the whole community
                      • or (as in this case) the question has already been answered in the support forums

                      Once again, good luck.
                      Last edited by KBJ; 04-23-2011, 12:02 PM.

                      Comment


                        #12
                        As I'm very ignorant of the inner workings of tick data and bid ask data i can only ask very simple questions.

                        I use Gomi indicator for volume delta information and have resorted to downloading replay files of the instruments i'm interested in and running them through market replay very quickly to generate the gomi history files. i usually do this during the weekend for filling in the previous weeks gaps or in the 5-6 pm hour when the instruments i trade are basically dead.

                        so if the historical data is available via replay, why is it not available via normal history files.

                        again, see the first sentence. but seems like it shouldn't be an unsolvable problem.

                        Comment


                          #13
                          rsmtrade, can you please clarify? You can download bid and ask data from most providers, as well as the replay data.
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            i'll try... i'm wondering why indicators like buy/sell volume have to be only real time? why do we have use Gomirecorder to get delta volume etc.? why can't ninjatrader have this data available for use by volume indicators such as buy/sell volume, cumulative delta etc.

                            seems like there are other platforms that do i.e investor r/t

                            Comment


                              #15
                              rsmtrade, the implementation is slightly different than the Gomi one, and not all providers support the data.
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              59 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X