Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Multitimeframe Strategy

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

    Problem with Multitimeframe Strategy

    Hi, im coding a multitimeframe strategy where my primary Dataseries is in 2 minutes and i have a second dataserie in 5 minutes.
    I only calculate onbarclose but when i print time of my second Dataserie onBarUpdate with this filter

    if (BarsInProgress == 1){
    Print(Times[0][0].TimeOfDay);}

    it prints for example this minutes : 10:04 - 10:10 - 10:14 - 10:20

    Im missing something? the second dataserie must be multiple of the primary?
    how can i process info of 5 minutes dataseries onbarclose working on 2 minutes primary dataserie?

    Thanks for your help!​

    #2
    BarsArray[0] = primary
    BarsArray[1] = second

    if (BarsInProgress > 0) return;

    Print(Times[0][0].TimeOfDay);
    Print(Times[1][0].TimeOfDay);
    Last edited by MicroTrends; 06-08-2024, 07:23 AM.
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    Comment


      #3
      Also, every now and then, a 2min bar and a 5min bar will
      close at the exact same time -- guess which bar close your
      OnBarUpdate sees first?

      It's the primary bar series. So, when a secondary 5min bar
      closes with the same timestamp as a primary 2min bar, your
      OnBarUpdate for the 2min bar cannot see that.

      Required reading here.

      Additional reading here and here.


      Comment


        #4
        Thanks for the quick response! The reason I wanted to print time was because I am having a difference when executing the strategy historically and live. When printing time it returns a few milliseconds before the bar is closed
        09:14:59.9520000
        09:19:58.1880000
        09:24:59.8720000​
        but I think this can be the diference between historic and live or replay (because in historic the close already happend but in live not)
        Is this possible?
        If that is the problem, I was thinking of doing it with IsFirstTick and instead of using onbarclose, use oneachtick

        Comment


          #5
          Hello PabloTrader,

          Both bltdavid and MicroTrends have provided good info. To further help clarify exactly which Bars objects is currently updated in OnBarUpdate, it may be helpful to also print the BarsInProgress along with the time of the bar.

          Print("BarsInProgress: " + BarsInProgress + " " + Times[0][0].TimeOfDay);


          It would be expected that a strategy performs differently in live vs. historically. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics. Instead these are filled based on logical rules from processing historical data.
          • When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data.
            • This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known
            • Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
          Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series.

          In NinjaTrader 8, there have been two new enhancements so that programmers may not have to manually add this secondary series and code the script for high accuracy fills (Order Fill Resolution) or for intra-bar actions (TickReplay) depending on the needs of the script.
          Note: bar types that are IsRemoveLastBarSupported cannot be used with TickReplay and generally cause inaccurate results when backtesting in historical data.
          Note: High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

          Please see this support article for a detailed explanation:

          https://support.ninjatrader.com/s/ar...ar-granularity

          Comment


            #6
            Thank you very much for all the help. My problem was with Cumulative Delta that was not giving correct values in a a secondary serie but i find that i have to update first the indicator. I already fix it. Thanks!!!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            23 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            120 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            63 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            45 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X