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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X