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 AttiM, 02-14-2024, 05:20 PM
      10 responses
      179 views
      0 likes
      Last Post jeronymite  
      Started by ghoul, Today, 06:02 PM
      0 responses
      7 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by Barry Milan, Yesterday, 10:35 PM
      6 responses
      19 views
      0 likes
      Last Post Barry Milan  
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      13 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Working...
      X