When is a bar complete?


Dear All,

Below is a snippet from my log file which I don’t know how to interpret.
I am using the Analysis window executing Explore at 1 minute frequency using 5 minute bar data.
In the “Bar=[…/…/…/…/…]” part I am logging the timestamp of the bar together with the OHLC prices.
What I see from the log is that I get five different prices for the bar with timestamp 15:55:00 - the open price stays the same, but the HLC prices change.
This means that the first 4 bars that I see are partial bars and probably the last one is the complete bar.
Is there any way to know when a bar is complete?

9/27/2017 3:55:31 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[15:55:00/152.65/152.88/152.13/152.64] ...
9/27/2017 3:56:31 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[15:55:00/152.65/152.88/152.13/152.66] ...
9/27/2017 3:57:32 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[15:55:00/149.55/153.44/148.8/153.44] ...
9/27/2017 3:58:32 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[15:55:00/149.55/153.52/148.8/152.66] ...
9/27/2017 3:59:32 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[15:55:00/149.55/153.52/148.8/152.66] ...
9/27/2017 4:00:32 PM: INFO: AAPL-SMART-STK-USD: Executing expore: Bar=[16:00:00/153.59/153.59/151.63/152.69] ...

The timestamps and the OHLC prices where obtained using DateTimeFormat("%H:%M:%S", LastValue(DateTime())) , LastValue(Open) , LastValue(High), LastValue(Low), and LastValue(Close) respectively.

IQ Feed for real-time scan

The lastbar is incomplete by nature. It becomes complete once new bar arrives.
So bar is complete if it is NOT last.

Remove "Early Close" Bars at 13:00

In the IB controller’s help page there is an example for “Placing and transmitting Market Buy Order for 100 shares when MACD crosses above Signal line”:

Buy = Cross( MACD(), Signal() ); 

if( LastValue( Buy ) )
   ibc.PlaceOrder( Name(), "Buy", 100, "MKT", 0, 0, "Day", True ); 

If this code is invoked multiple times within a bar’s time frame, does this mean that the last value in the Buy array can toggle on/off as this last (and incomplete) bar is being built?
If yes, than I can have the scenario where in the middle of a 5 minute interval LastValue( Buy ) is 1 and an order is placed, then at the end of this bar the condition is not true. How can this be avoided to only place order when a complete bar is received?
With other tools I have used before my strategy code was notified with a bar when the bar was complete.


Just use not the last, but the one bar earlier. This one is complete.

LastValue( Ref( Buy, -1 ) );


Is this also true when the code runs outside regular trading hours? In that case there is no new/incomplete bar yet, isn’t it?


That is, I am not sure how to interpret the LastValue(Buy) call: Will this return an incomplete bar only during trading hours, and the last completed bar outside trading hours? Or even outside trading hours there will be an incomplete last bar?


Everything is already explained in my previous post. You can only be sure that the bar before the very last is complete. That is why Ref( Buy, -1 ) is used. The code I gave you returns the value of ONE BAR BEFORE the very last bar.