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

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() -

    BertrandNinjaTrader Customer Service

    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 RDTrader16, Today, 10:19 PM
      0 responses
      5 views
      0 likes
      Last Post RDTrader16  
      Started by gemify, 03-08-2023, 08:02 AM
      9 responses
      148 views
      0 likes
      Last Post culpepper  
      Started by elirion, Today, 10:03 PM
      0 responses
      2 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by RaddiFX, Today, 09:55 PM
      0 responses
      9 views
      0 likes
      Last Post RaddiFX
      by RaddiFX
       
      Started by Trader146, 03-29-2024, 01:22 PM
      4 responses
      27 views
      0 likes
      Last Post Trader146  
      Working...
      X