Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Synchronize multiple bars on minute data

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

    Synchronize multiple bars on minute data

    Hi,

    My strategy runs on bid-ask data on minute bars. Every tick I calculate my signal based on bid-ask midprice.

    On the first bar of a minute, either the bid or ask will update first and I will get a midprice calculated on a current bar and a bar from last minute which is obviously very off from current market.

    I would like to run my strategy only when the last bar of that specific minute is updated. How can I do this?

    I have thought about counting the number of updates for a specific timestamp and only allowing to go further when that number equals the number of bars I have added, but can I have a guarantee that if I have subscribed to bid-ask, I will get OnBarUpdate fire for each bar at each minute?

    Also, to ensure realistic delays, if I submit my orders on the 'trades bar', can I submit the order at any time or should I wait for the 'trades bar' to have updated for that specific minute?

    #2
    Hello benoirat,

    Using a minute bar you would not be able to tell how many ticks will be inside each bar so you would not be able to tell which tick is the last one easily.

    With that said, you can check to see which is the FirstTickOfBar so that you can create your logic around this.

    Here is a link to our Help Guide that gives an example of this.


    As far as orders, you should be able to submit orders at anytime as long as your broker will accept them.

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks.

      I think I was not clear in my initial explanation. I simulate with minute bars with calculateonbarclose = false. My decisions depend on bid-ask midprice, which is the average of the bid close and ask close for minute x. I subscribe to bid and ask prices as 2 different bars. During the simulation, at minute x+1, the bid bar might update first, then my signal will be the average of bid[t+1] and ask[t], which I do not want. I want to wait for the ask to update so that my new midprice is the average of bid[t+1] and ask[t+1]. In that sense I want to know how to be sure that all the bars I have subscribed to are at t+1 and not t.

      Concerning the orders I was thinking of the backtesting. If I submit on the trade bar but the trade bar has not been updated yet will I be filled on the prices of one minute ago or will nt wait that the trade bar updates to the current minute before firing the fill algo?
      Last edited by benoirat; 06-30-2013, 10:35 PM.

      Comment


        #4
        Hello,

        You can use a BarsInProgress filter to only process certain logic when that particular bars object is updated.


        Code:
               /// </summary>
                protected override void Initialize()
                {
        			
        			//Add the Ask series => BarsInProgress 1
          			Add("$EURUSD", PeriodType.Minute, 1, MarketDataType.Ask);
        
        			//Add the Bid series => BarsInProgress 2
        			Add("$EURUSD", PeriodType.Minute, 1, MarketDataType.Bid);
                }
        
        		
                protected override void OnBarUpdate()
                {
        			
        			if(BarsInProgress == 1)
        			{
        				//do something when the ask updates, calculate your mid price, etc
        			}
        
        			if(BarsInProgress == 2)
        			{
        				//do something when the ask updates or do nothing
        			}
        		}
        There are some considerations you will have to account for when using these series

        Using Historical Bid/Ask Series




        Backtesting will always be CalculateOnBarClose = true, which means that it will wait until the bar updates to submit the order. However, it is possible to program your strategy to submit orders on a finer series such as a tick interval when backtesting:

        You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        651 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X