Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using OnMarketData with OnBarClose

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

    Using OnMarketData with OnBarClose

    Hi,

    will using OnMarketData with OnBarClose in my strategy work correctly, meaning that it will calculate correctly the marketdata, but only once at the end of the bar? It's hard to test so just checking here.

    Thank you!


    #2
    Hello, thanks for writing in. OnBarUpdate (with Calculate = OnBarClose) will update once at the close of every bar. OnMarketData will be called on every single change in price data, so its like running OnBarUpdate using Calculate = OnEachTick. I attached an example that is somewhat related, it builder minute bars from single tick data.
    Attached Files

    Comment


      #3
      Hi very late Chris,

      thank you very much for taking the time to answer my question with this .cs example. The fakeBars workaround is very interesting, however I must admit I don't understand everything in your code, I am and will still be for some time a python guy even though I feel rusty when I go back to python, because of NinjaTrader haha. I understand what you're doing though, I use a "fake" workaround like this too on my strategies by adding a secondary dataSerie for more granularity (like 1 second on a 5 mins strategy), so the strategy calculates every second to be ready to do action, even if the main idea is based around Calculate.OnBarClose of a slower time frame.

      I usually work with something like this:
      Code:
      else if (State == State.Configure)
                  {
      
                      if (secondsPeriod == true)
                      {
      
                          AddDataSeries(Data.BarsPeriodType.Second, barsPeriod01);  // BarsInProgress = 1, 300 sec
                          AddDataSeries(Data.BarsPeriodType.Second, barsPeriod02);  // BarsInProgress = 2, for orders
      
                      }
                      else
                      {
                          AddDataSeries(Data.BarsPeriodType.Minute, barsPeriod01);  // BarsInProgress = 1, strategy in minutes
                          AddDataSeries(Data.BarsPeriodType.Minute, barsPeriod02);  // BarsInProgress = 2, for orders
      
                      }
      
                  }​
      You get the idea, I think it conveys the same idea as your fakeBars, when you run the strategy on (BarsInProgress == 1) or (BarsInProgress == 2). Thanks for your time!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      51 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      129 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X