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

Accumulated Bid/Ask Volume on 1 minute bar

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

    Accumulated Bid/Ask Volume on 1 minute bar

    The code below shows the current bid/ask volume as the 1 minute bar updates, however every time the bar updates, the data in the sub-graph rolls over or refreshes. Is there a way to Add the accumulated ask and bid data respectively, as the 1 minute volume populates?

    Code:
    protected override void  OnBarUpdate()
            {    
                Ask.Set(GetCurrentAskVolume());
                Bid.Set(GetCurrentBidVolume());
            }
    Thanks,
    Alex

    #2
    Hello,

    Thank you for the question.

    If you wanted to Accumulate any sort of data and plot the Accumulation, you would need to store a variable outside of OnBarUpdate as that gets called over and over again.

    a simple example would be as follows:

    Code:
    long askVolume = 0;
    long bidVolume = 0;
    protected override void  OnBarUpdate()
    {    
         askVolume += GetCurrentAskVolume();
         bidVolume += GetCurrentBidVolume();
         Ask.Set(askVolume );
         Bid.Set(bidVolume );
    }
    Each time OnBarUpdate is called, the variables askVolume and bidVolume are incremented (the += sign) with the Current volume information.

    The variable is then used to Set the value of the plot.

    as an example, if 1 volume was received for each OnBarUpdate call, it would accumulate as 1, 2, 3,4 etc..

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

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the question.

      If you wanted to Accumulate any sort of data and plot the Accumulation, you would need to store a variable outside of OnBarUpdate as that gets called over and over again.

      a simple example would be as follows:

      Code:
      long askVolume = 0;
      long bidVolume = 0;
      protected override void  OnBarUpdate()
      {    
           askVolume += GetCurrentAskVolume();
           bidVolume += GetCurrentBidVolume();
           Ask.Set(askVolume );
           Bid.Set(bidVolume );
      }
      Each time OnBarUpdate is called, the variables askVolume and bidVolume are incremented (the += sign) with the Current volume information.

      The variable is then used to Set the value of the plot.

      as an example, if 1 volume was received for each OnBarUpdate call, it would accumulate as 1, 2, 3,4 etc..

      I look forward to being of further assistance .

      Thank you Jesse, that's exactly what I was looking for.

      Another question, maybe you can help. I'm creating this indicator as a sub-graph of time chart. The data series for this chart is based on "Last". Is there any way I can pull the data from the "Ask" or "Bid" on the same time scale and display it in the "Last" Data Series chart below? To populate the askVolume, bidVolume data in this case.

      I guess what I'm asking is, can I pull the volume data from the ASK data series and the volume data from the BID data series to populate askVolume and bidVolume?

      Thanks for the help.
      Alex
      Last edited by TzunTzai; 06-29-2015, 01:22 PM.

      Comment


        #4
        Hello,

        This would require adding additional series to the script.

        This would be an example using what you were already using and Adding the extra Ask and Bid series.

        protected override void Initialize()
        {
        Add(Instrument.FullName, PeriodType.Minute,1, MarketDataType.Ask);
        Add(Instrument.FullName, PeriodType.Minute,1, MarketDataType.Bid);
        //add your Add(new Plot items here as well.
        }

        double askVolume = 0;
        double bidVolume = 0;
        protected override void OnBarUpdate()
        {
        if(BarsInProgress == 0)
        {
        askVolume += GetCurrentAskVolume();
        bidVolume += GetCurrentBidVolume();
        Values[0].Set(askVolume );
        Values[1].Set(bidVolume );
        //charts Last series OBU
        }
        else if(BarsInProgress == 1)
        {
        askVolume += Volume[0];
        }
        else if(BarsInProgress == 2)
        {
        bidVolume += Volume[0];
        }
        }

        In the Initialize section, we add Ask and Bid series, then later in OnBarUpdate we determine which series is calling OnBarUpdate. For a single series this would get called every 1 minute, after adding two series OnBarUpdate will get called 3 times, once for each series at its own interval.

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

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello,
          protected override void Initialize()
          {
          Add(Instrument.FullName, PeriodType.Minute,1, MarketDataType.Ask);
          Add(Instrument.FullName, PeriodType.Minute,1, MarketDataType.Bid);
          //add your Add(new Plot items here as well.
          }

          So in the case of the E-MiniS&P it would be ...

          Code:
          Add("ES 09-15", PeriodType.Minute,1, MarketDataType.Ask);
          Add("ES 09-15", PeriodType.Minute,1, MarketDataType.Bid);
          I'm guessing that I'm going to have to change my code. Because if we're pulling actual volume from a specific data series, I wouldn't need to call the ask or bid data from the current data series... correct?


          Alex

          Comment


            #6
            Hello,

            If you are adding a specific instrument, what you had provided would be correct or:

            Add("ES 09-15", PeriodType.Minute,1, MarketDataType.Ask);
            Add("ES 09-15", PeriodType.Minute,1, MarketDataType.Bid);

            Otherwise if this will always be the charts instrument you could use Instrument.FullName.

            The example provided would be used the volume from the Secondary series or Ask and Bid series, that is the reason for the BarsInProgress check.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            943 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            9 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            5 views
            0 likes
            Last Post rocketman7  
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            28 views
            0 likes
            Last Post wzgy0920  
            Working...
            X