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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X