Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to reset blockcount each bar

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

    How to reset blockcount each bar

    I have some code that draws a histogram using time and sales data volume. The idea is to plot the quantity of block trades for each bar. I have the code counting but the blockcount variable is cumulating each bar.

    How do I reset the blockcount variable to zero at the start of a new bar?

    Here is the code:

    /// //initialize the blockcount variable

    int blockcount = 0;


    protected override void OnMarketData(MarketDataEventArgs e)
    {


    //Increment blockcount each time a trade of 1000 shares or greater comes in

    if (e.MarketDataType == MarketDataType.Last && e.Volume >=5)
    {
    blockcount++ ;
    }

    }
    protected override void OnBarUpdate()
    {

    Blocks.Set(blockcount);
    }

    #2
    gdavis74, you could reset your custom tracking variable in FirstTickOfBar in the OnBarUpdate() -

    Comment


      #3
      Bertrand, thanks for the quick response. That worked perfectly, I was able to monitor blocktrades today!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X