Charts... function to identify bar replay vs real time with live data

Are there AFL functions that can be used to indicate whether a bar replay is running vs the scenario where a chart is being updated with live real time data? I was using the GetPlaybackDateTime() function recently with bar replay and then realized it wouldn't work with a chart while gathering real time data. I should have realized that the 'playback' key word is part of the function name for a reason ha ha. I'm trying to get bar data , including timestamps, from bars during replays and also during the day with live data. I'd like to use the same AFL file for both scenarios and need a way to execute code specific to bar replays and code specific to charts in real time with live data. It appears that the 'Status' function can be used to determine whether a scan or an exploration is being done but I can't find a way to differentiate a chart replay vs a real time chart with live data.

@mcescher, I never used it but looking at the documentation of the function it will return 0 (zero) when Playback is not active.
In such a case, I will simply try to do as in the example provided in the documentation:

/// shared code / functions to be used in both cases

pt = GetPlaybackDateTime(); // new function to retrieve playback position date/time,
//returns zero if bar replay is NOT active
if( pt )
{
  Title = "Playback time: " + DateTimeToStr( pt );
  // add code to handle bar replay mode
}
else
{
  Title = "Bar Replay not active";
  // add code for the other situations
}
// any other shared code...
2 Likes

Hi Beppe...

You are correct that GetPlaybackDateTime() returns zero when playback is not active; however, I was using the return value of the GetPlaybackDateTime() function to control whether or not my log file would be opened for writing. I used this approach because when a chart is open and I also open 'Bar Replay' (just open it; not run it), records are written to the log file with an 'Invalid date' message because a valid date is not populated until Bar Replay is actively executing. I'm assuming that the AFL formula engine repeatedly evaluates the AFL code (once a second or so???) and then writes the "Invalid date" message to the open file even though the bar replay is not actively running. Thus I only opened the log file for writing when GetPlaybackDateTime() was returning a value that indicated valid dates were being generated.

I think I'll resolve this issue by using a Param Trigger to control opening/closing the log file. Then I'll be able to use the return value of the GetPlaybackDateTime() function to control program flow based on being in a bar replay mode or a real time data collection mode.

Thanks once again for your help Beppe.

Mike