eKam has pointed out that the LastBarOnChart function does not work correctly on type 0 (tick) bars.

The problem is that the time function called by LastBarOnChart does not resolve time finer than 1-minute increments. Therefore, this function may become true up to 1 minute before the last bar prints on a tick chart since several tick bars may print with the same minute time stamp. The same problem occurs for multiple volume bars which may print with the same minute time stamp.

However, there is also a problem using LastBarOnChart with real-time data for all bar types > 0.

When the last bar on the chart has printed, LastBarOnChart does not become true until the next tick of data is received. The same can be said for function GetAppInfo(aiRealTimeCalc). Therefore GetAppInfo(aiRealTimeCalc) cannot be used to trigger LastBarOnChart immediately when the last bar has printed on a real-time chart. Both LastBarOnChart and GetAppInfo(aiRealTimeCalc) must wait for the next tick of data to arrive before they are triggered.

If you are using LastBarOnChart to trigger the plotting of an indicator or performing a calculation, this action will be delayed until the next tick of data arrives. In some cases, this delay will be objectionably long if the symbol is trading infrequently.

The following code can be used to force an immediate trigger of the LastBarOnChart condition when the last bar has printed on a real-time data chart of BarType > 0:

Function LastBarOnChartImproved Code