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

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:

        You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
        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).



            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 funk10101, Today, 09:43 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post funk10101  
                  Started by pkefal, 04-11-2024, 07:39 AM
                  11 responses
                  37 views
                  0 likes
                  Last Post jeronymite  
                  Started by bill2023, Yesterday, 08:51 AM
                  8 responses
                  44 views
                  0 likes
                  Last Post bill2023  
                  Started by yertle, Today, 08:38 AM
                  6 responses
                  26 views
                  0 likes
                  Last Post ryjoga
                  by ryjoga
                   
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  24 views
                  0 likes
                  Last Post algospoke  
                  Working...
                  X