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

Last/First tick of volume bar changed in V7

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

    #16
    Originally posted by NinjaTrader_Josh View Post
    HNWTrader,

    This SecondTickProof is an invalid test. You cannot use FirstTickOfBar outside of the bars context of OnBarUpdate() as outlined here: http://www.ninjatrader.com/support/h...ttickofbar.htm
    Well then I guess I am paying the price for coming late to the NT7 party. I did not see any restriction on using FirstTickOfBar outside of OnBarUpdate in the NT6 Help Guide, so I am surprised to see it in NT7. It appears others who are a lot more experienced with this stuff than I am failed to convince NT that a valid first tick indicator in OnMarketData was needed, so I won't ask you to go down that road again.

    Thanks to RJay and eDanny for adding their contributions here. It gave me a better understanding of what is going on.

    Comment


      #17
      Possible solution- Is it reliable?

      Given that FirstTickOfBar cannot be used in OnMarketData, I looked for an alternative. I don't know if it is universally valid, but it seems to be a simple fix for my indicator, at least for the chart types and parameters I use. Since every tick triggers OnMarketData at some point, and NT has a Bars.TickCount (hoping of course that NT is updating Bars.TickCount before OnMarketData gets triggered; it appears to be working that way), I have replaced
      Code:
      if (FirstTickOfBar)
      with
      Code:
      if (Bars.TickCount == 1)
      I do nothing in OnBarUpdate. All my processing is done in OnMarketData. As before in my original indicator, I compare the volume of the tick corresponding to this condition being true to the bar volume (Volume[0], which also seems to be reliably updating prior to the OnMarketData trigger). When the tick volume is bigger than the bar volume, I know that the tick straddles the bar boundaries and I split the tick between the two bars.

      This may be an imperfect substitute for a true first tick of bar indicator (OR could this be it?) that will work in OnMarketData, but for the times of day and bar intervals that are of interest to me, it seems to be working well so far. Does anyone see a problem with this?
      Last edited by HNWtrader; 12-10-2010, 03:06 PM.

      Comment


        #18
        if(BarID != CurrentBar)

        {
        bidsumUp = 0;
        asksumUp = 0;
        totalaskvol = 0;
        totalbidvol = 0;

        BarID = CurrentBar;

        }
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #19
          Originally posted by rt6176 View Post
          if(BarID != CurrentBar)

          {
          bidsumUp = 0;
          asksumUp = 0;
          totalaskvol = 0;
          totalbidvol = 0;

          BarID = CurrentBar;

          }
          From the NT7 Guide, CurrentBar looks like it is connected to OnBarUpdate
          A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.
          I suspect it could have the same problem as FirstTickOfBar. I did not examine it per se, but I do know from my earlier observations that a bar does not even appear on my time based charts until the second tick (based on Time and Sales) of the bar is processed. So I don't see why there would be a difference between BarID and CurrentBar on the first tick of a bar if examined within OnMarketData where I need to do my processing. But there is a lot of this NT stuff that is still a mystery to me. I certainly don't know much about it.

          In some of the posts that you linked you talk about having to save the previous tick values to be processed later. I don't know if you still have to do that, but I don't think there is any need to do it with "if (Bars.TickCount == 1)" because it gets me directly to the first tick of the bar for processing, perhaps even before the bar appears on the chart. I have no idea what NT7 will do if there is a bar with only one tick, but I am never interested in such events.

          What I did was to change my test indicator to read Volume[0] in OnBarUpdate, and OnMarketdata. They are indeed not the same, with the reading from OnMarketData leading the reading from OnBarUpdate by 1 tick in NT7.

          I looked at this

          Code:
          protected override void OnBarUpdate()
          {
          	barVolumeBarOld = barVolumeBar;
          	barVolumeBar = (long) Volume[0];
          }
          
          protected override void OnMarketData(MarketDataEventArgs e)
          {
          	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 || ChartControl == null || askPrice == 0 
          			|| bidPrice == 0)
          		return;
          
          	barVolumeDataOld = barVolumeData;
          	barVolumeData = (long) Volume[0];
          	volume	= e.Volume;
          	price	= e.Price;
          	count += 1;
          	if (count < 3) Print ("("+Bars.Period+") " + price + "   " + volume + "   " + barVolumeBarOld
          		+ "   " + barVolumeBar + "   " + barVolumeDataOld + "   " + barVolumeData
          		+ "  count " + count + "  TickCount " + Bars.TickCount);
          
          	if(FirstTickOfBar)
          	{
          	count = 0;
          	Print ("");
          	Print ("("+Bars.Period+") " + price + "   " + volume + "   " + barVolumeBarOld
          		+ "   " + barVolumeBar + "   " + barVolumeDataOld + "   " + barVolumeData
          		+ "  count " + count + "  TickCount " + Bars.TickCount);
          	}
          }
          and later changed "FirstTickOfBar" to "Bars.TickCount == 1". Either way, you see that the volumes from the two methods are not the same. With "if (Bars.TickCount == 1)" you see that at count = 0 (when TickCount = 1), barVolumeData is less than barVolumeDataOld (and is equal to volume on time based charts and probably every other type besides volume) as you would expect if the new bar had opened. But barVolumeBar was still larger than barVolumeBarOld. When I changed the "if" in my original indicator, and moved a few lines from OnBarUpdate to OnMarketData it appeared to solve my problem. I have not yet made the change in my NT6.5 version, but I expect it will work there as well. As long as it keeps working for me, I will stick with it. If not, I will see if using CurrentBar will help me.

          Thanks again for your input.
          Last edited by HNWtrader; 12-11-2010, 10:19 AM.

          Comment


            #20
            HNWtrader,

            I will have Josh review this on Monday. Thank you for your patience.
            Ryan M.NinjaTrader Customer Service

            Comment


              #21
              HNWtrader,

              I do not foresee issues with your approach at this point in time except the missing Bars null reference check you should be using when utilizing Bars.TickCount.

              Please be sure to check if (Bars != null) before accessing Bars.TickCount outside of OnBarUpdate().
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              601 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              17 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Started by agclub, 04-21-2024, 08:57 PM
              3 responses
              17 views
              0 likes
              Last Post TradingLoss  
              Working...
              X