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

bid and ask volume

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

    bid and ask volume

    Hello. New to coding so I'm experimenting: I want to subtract the bid volume from the ask volume and have the answer print when the bar closes. It appears I'm not getting the correct answers. Here's the code--please tell me where I've gone wrong:

    protected override void OnBarUpdate()
    {
    //Print("Bid Volume: " + GetCurrentBidVolume() + " | Ask Volume: " + GetCurrentAskVolume() );
    Print(ask - bid);
    ask = 0;
    bid = 0;
    //x += 1;

    Thank you.

    #2
    Originally posted by imalil View Post
    Hello. New to coding so I'm experimenting: I want to subtract the bid volume from the ask volume and have the answer print when the bar closes. It appears I'm not getting the correct answers. Here's the code--please tell me where I've gone wrong:

    protected override void OnBarUpdate()
    {
    //Print("Bid Volume: " + GetCurrentBidVolume() + " | Ask Volume: " + GetCurrentAskVolume() );
    Print(ask - bid);
    ask = 0;
    bid = 0;
    //x += 1;

    Thank you.
    #region variables

    private int bid;
    private int ask;

    #endregion

    protected override void OnBarUpdate()
    {
    bid = GetCurrentBidVolume() ;
    ask = GetCurrentAskVolume() );
    Print(ask - bid);
    }

    Comment


      #3
      Thanks for the information. Another question: if I add all the bids on a price bar to the asks on the same price bar, would this constitute the total order flow for that particular price bar? If not, what command will give me the total order flow for a price bar? Is it this:

      bid = GetCurrentBidVolume() ;
      ask = GetCurrentAskVolume() )

      Because I am not getting the answers I'm expecting.

      Thank you for your input.

      Comment


        #4
        Better question: if, during a price bar, I want to split up the ask and bid order flow into price incremental buckets so I can run my algorithm--I want my calculations to run at various price levels--what is the Ninjascript command that can help with this task?

        Thank you very much.

        Comment


          #5
          Hello imali,

          Thank you for your post.

          You may wish to run the logic in OnMarketData() rather than OnBarUpdate() as the OnMarketData() method will be called when market data updates rather than on the bar update: http://www.ninjatrader.com/support/h...marketdata.htm

          Please let me know if you have any questions.

          Comment


            #6
            Thanks for that, Patrick, but I knew that. Let me go back to my previous question and see if that'll help me:

            If I add all the bids on a price bar to the asks on the same price bar, would this constitute the total order flow for that particular price bar? If not, what command will give me the total order flow for a price bar? Is it this:

            bid = GetCurrentBidVolume() ;
            ask = GetCurrentAskVolume() )

            Because I am not getting the answers I'm expecting.

            Thank you for your input.

            Comment


              #7
              Hello Imalil,

              What values do you expect? And would Volume[0] not provide this with CalculatOnBarClose = False?

              Comment


                #8
                Thanks Patrick. The problem is on my end; I need to formulate a better question. I'll get back to you.

                Comment


                  #9
                  Is there a simple command to signal the beginning of a new price bar in a time frame? As of right now I'm using tickcount == 1, but sometimes the new bar starts at tick 3 or 4 which destroys my results. What's the method for signaling the beginning of a bar?

                  Thank you very much.

                  Comment


                    #10
                    Hello imalil,

                    Thank you for your post.

                    You can use FirstTickOfBar: http://www.ninjatrader.com/support/h...ttickofbar.htm

                    Comment


                      #11
                      Thanks. Would firsttickofbar work in something like this or should I use something else:

                      protected override void OnMarketData(MarketDataEventArgs e){
                      if (e.MarketDataType != MarketDataType.Last){
                      if (Bars.TickCount == 1 && e.MarketDataType == MarketDataType.Ask){
                      Print("Bar " + CurrentBar + ": " + ChrisFunc(askHash, bidHash, aseed, bseed));
                      Print("Us: " + (ask - bid));
                      askHash.Clear();
                      bidHash.Clear();

                      Comment


                        #12
                        The programmer I'm working with wants to know the following: on the OnMarketData() function, what is the difference between incoming market data and a tick?

                        Thanks.

                        Comment


                          #13
                          Originally posted by imalil View Post
                          The programmer I'm working with wants to know the following: on the OnMarketData() function, what is the difference between incoming market data and a tick?

                          Thanks.
                          Why doesn't he contact NT directly for the issue lol?
                          ninZa
                          NinjaTrader Ecosystem Vendor - ninZa.co

                          Comment


                            #14
                            Originally posted by imalil View Post
                            The programmer I'm working with wants to know the following: on the OnMarketData() function, what is the difference between incoming market data and a tick?

                            Thanks.
                            No difference with Tick, but OnMarketData contains more information/changes that really aren't necessary for processing.. the NT SuperDom is OnMarketData, the Level2 thingy is OnMarketData (or some other proprietary NT stuff)..




                            Definition
                            The OnMarketData() method is called and guaranteed to be in the correct sequence for every change in level one market data for the underlying instrument. This can include but is not limited to the bid, ask, last price and volume.




                            Definition
                            The OnBarUpdate() method is called whenever a bar is updated. If the "CalculateOnBarClose" property is set to true, it is only called on the close of each bar, otherwise it is called on each incoming tick. This is the method where all of your strategy or indicator core calculation logic should be contained.

                            Comment


                              #15
                              Thank you very much for the information. I'm just going to tell you what we're attempting since we're floundering a bit.

                              From the first tick of a new bar, we want to add all the ask volume together at each price level for the entire bar, and add all the bid volume together at each price level for the entire bar. In other words, all asks at price 2000 will be added together over the bar, 2000.25 will be added together, etc. The same for the bids. So every price level will have a grand total of bid and ask volume. We then want to apply our formula comparing the asks at a certain price to the bids at a certain price, at all price levels on the bar so we can get the value we're after. When a new bar starts, the counting resets and starts over again.

                              We are having problems 1) resetting at the new bar and 2) working with marketdatatype vs. onbarupdate. We've read all the definitions and are still not 100% sure which to focus on. I do not care if our calculation takes place during the bar or after it closes. I just want to do what's most efficient. If it takes two indicators to make this work--one during the bar totalling all the bids/asks, and one after the bar closes to do the math--I can live with it. We just want to know what to focus our attention on so we don't waste our time trying this and that.

                              If anyone can give us feedback on this I'd greatly appreciate it. Thank you again.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X