Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate - Last - Volume - Historical

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

    OnBarUpdate - Last - Volume - Historical

    Hello,

    I'm modifying my own indicator, I need to use the last-tick price and last-tick volume in OnBarUpdate method.

    I already know that I can use the Close[0] for the last-tick price, however I don't know how to get the volume. I also don't know how to get those variables (price and volume) with historical data.

    I need to use price and volume for every incoming tick, therefore I'm using COBC = false

    Code:

    ... OnBarUpdate()
    {
    if (Historical)
    {
    myMethod( price?, volume?); //For every tick in the bar not only the last one
    }
    myMethod( Close[0], volume?);
    }

    I was using OnMarketData method in my indicator and it works well, but now I need the indicator working with historical data so I assume I should use OnBarUpdate.

    ... OnMarketData(MaketDataEventArgs e)
    {
    if(e.MarketDataType == MarketDataType.Last)
    {
    myLastVolume = e.Volume;
    myLastPrice = e.Price;
    }
    }

    Cheers,

    Ronald

    #2
    Ronald, thanks for the post - to simulate this for historical data you would need look into adding a 1 tick series in your indicator and then running the calculations with this series, here a tick bar would provide the price and volume you seek to work with. The timestamp resolution here would be down to a second offered - further enhancing this is on our feedback list in product management to consider for our next major platform update.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Thanks for your answer. Would you have some example of how to use tick series?. It would be very helpful.

      Once again thank you.

      Cheers,

      Ronald.

      Comment


        #4
        Here is an example for you to reference:

        http://www.ninjatrader.com/support/f...ead.php?t=6652
        MatthewNinjaTrader Product Management

        Comment


          #5
          Hi Matthew and Bertrand,

          Thank you guys, but unfortunately I haven't solved my issue with the information provided.

          Please let me explain in a different way:

          I'm using the e.Volume and e.Price data to calculate my indicator, that is working well. In real time I have price and volume for each last price.

          Code:

          ... OnMarketData(MaketDataEventArgs e)
          {
          if(e.MarketDataType == MarketDataType.Last)
          {
          myIndicatorLogic(e.Price, e.Volume) ;
          }
          }

          Now I need to calculate my indicator for historical data. Following your advice I tried to use:

          1. Add ("CL 02-13", PeriodType.Range, 4, MarketDataType.Last) - That provided me another bar however I don't know how to get price and volume of all the last-ticks for each historical bar.

          2.

          OnBarUpdate()
          {
          if(Historical)
          {
          myIndicatorLogic(Close[0], Volume???) - For every historial bar I get the price but I don't know how to get the volume, and I only have ONE price. Perhaps I should make a loop for historical bar???
          }

          }

          Thank you for your help.

          Ronald.

          Comment


            #6
            I found this:

            NinjaTrader_Bertrand
            NinjaTrader Customer Service
            Join Date: Sep 2008
            Location: Germany
            Posts: 21,363
            Thanks: 212
            Thanked 791 times in 777 posts

            xTrader1, thanks for the suggestion - those properties are unfortunately not available, you would need to custom code those calcs as you've outlined.

            CalculateOnBarClose is defaulted to 'true' for all historical OnBarUpdates(), as the intrabar formation is not known (only OHLCV).

            http://www.ninjatrader.com/support/f...historical+bar

            Is there any workaround?

            Cheers,

            Ronald.

            Comment


              #7
              Yes, that's still correct info - but you can't get lower than 1 tick - here the bar would only consist of this very tick, so you could use an added series of this granularity to attempt looking inside the bigger bars as you have access to all ticks happening inside those. The NinjaScript OnBarUpdate() call for this series then happens on every bar (same for historical and realtime data in this special case of a one tick series), so you have access to each price and it's volume (Volume[0]).
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Something like this:

                ...Initialize()
                {
                Add(Instrument.FullName, PreiodType.Tick, 1, MarketDataType.Last);
                CalculateOnBarClose = true;
                }

                And...

                ... OnBarUpdate()
                {

                If (BarsInProgress == 1)
                {
                MyMethod(Close[0], Volume[0]);
                }
                }

                Comment


                  #9
                  Originally posted by ronald.garcia View Post
                  Hi Matthew and Bertrand,

                  Thank you guys, but unfortunately I haven't solved my issue with the information provided.

                  Please let me explain in a different way:

                  I'm using the e.Volume and e.Price data to calculate my indicator, that is working well. In real time I have price and volume for each last price.

                  Code:

                  ... OnMarketData(MaketDataEventArgs e)
                  {
                  if(e.MarketDataType == MarketDataType.Last)
                  {
                  myIndicatorLogic(e.Price, e.Volume) ;
                  }
                  }

                  Now I need to calculate my indicator for historical data. Following your advice I tried to use:

                  1. Add ("CL 02-13", PeriodType.Range, 4, MarketDataType.Last) - That provided me another bar however I don't know how to get price and volume of all the last-ticks for each historical bar.

                  2.

                  OnBarUpdate()
                  {
                  if(Historical)
                  {
                  myIndicatorLogic(Close[0], Volume???) - For every historial bar I get the price but I don't know how to get the volume, and I only have ONE price. Perhaps I should make a loop for historical bar???
                  }

                  }

                  Thank you for your help.

                  Ronald.
                  He advised using a 1-tick second barSeries. What you have coded is a 4-Range series. A 1-tick series would be:

                  Code:
                  Add ("CL 02-13", PeriodType.Tick, 1, MarketDataType.Last);
                  The volume for the current bar on your secondary series is:

                  Code:
                  Volumes[1][0];

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Lloyd143, Today, 05:24 PM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by Hagar, Today, 04:38 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by [email protected], Today, 04:49 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post bpatel20@gmail.com  
                  Started by forrestang, Today, 02:05 PM
                  3 responses
                  24 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by harryodell55, Today, 01:30 PM
                  3 responses
                  29 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Working...
                  X