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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      244 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      157 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      165 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      250 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      201 views
      0 likes
      Last Post CarlTrading  
      Working...
      X