RecalcLastBarAfter messes up aiRealTimeCalc

Questions about MultiCharts and user contributed studies.
User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

RecalcLastBarAfter messes up aiRealTimeCalc

Postby JoshM » 22 Apr 2012

According the to wiki on GetAppInfo, the aiRealTimeCalc parameter:

returns a value of 1 if the calling application is performing calculation based on real-time data. Will return a value of 0 in all other cases.


While this is true, it isn't true if RecalcLastBarAfter is used.

For example, this code..

Code: Select all

if (LastBarOnChart_s = True) then begin

   Print(TimeNow, "SessionStart @ ", SessionStartTime(0, DayOfWeek(CurrentDate)),
      ", Last quote update: ", FormatTime("HH:mm:ss", ELTimeToDateTime_s(q_time_s)),
      ", aiRealTimeCalc: calculation based on ",
      IffString(GetAppInfo(aiRealTimeCalc) = 1, "real-time data", "historical data"));
end;

RecalcLastBarAfter(5);


..returns

Code: Select all

23-04_06:30:42  SessionStart @  800.00, Last quote update: 00:00:00, aiRealTimeCalc: calculation based on historical data
23-04_06:30:47  SessionStart @  800.00, Last quote update: 00:00:00, aiRealTimeCalc: calculation based on real-time data
23-04_06:30:52  SessionStart @  800.00, Last quote update: 00:00:00, aiRealTimeCalc: calculation based on real-time data
23-04_06:30:57  SessionStart @  800.00, Last quote update: 00:00:00, aiRealTimeCalc: calculation based on real-time data

(MC 7.4 build 4096)

Where the first calculation is based on historical data (correct), while the next calculations say there is "real-time data", an hour and a half prior to the exchange opening. Also, the quote field (q_time_s) returns a zero, clearly indicating there is no real-time data.

Either there's a bug in aiRealTimeCalc, which causes RecalcLastBarAfter calculation to be seen as 'performing calculations based on real-time data', or there is some confusion on what "real-time data" actually means.

    Regardless of what causes this behavior, can it be fixed/changed so that the aiRealTimeCalc parameter actually returns a 1 when there is "real" incoming real-time data?

Because the way it's working now, with RecalcLastBarAfter causing "real-time data" according to aiRealTimeCalc, the aiRealTimeCalc parameter is not useful since even if this reserved word says "real-time data", we still can't be sure there's actual real-time data coming in.
These users thanked the author JoshM for the post:
SUPER

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby SUPER » 23 Apr 2012

JoshM,

I ran you code on ticker symbol ES set at OpenOutCry Session and I got following results with MC 8.0 beta2, looks like expected behaviour.


Code: Select all

23-04_10:26:16  SessionStart @ 1430.00, Last quote update: 10:26:15, aiRealTimeCalc: calculation based on historical data
23-04_10:26:21  SessionStart @ 1430.00, Last quote update: 10:26:20, aiRealTimeCalc: calculation based on real-time data
23-04_10:26:26  SessionStart @ 1430.00, Last quote update: 10:26:26, aiRealTimeCalc: calculation based on real-time data
23-04_10:26:31  SessionStart @ 1430.00, Last quote update: 10:26:30, aiRealTimeCalc: calculation based on real-time data
23-04_10:26:36  SessionStart @ 1430.00, Last quote update: 10:26:35, aiRealTimeCalc: calculation based on real-time data
23-04_10:26:41  SessionStart @ 1430.00, Last quote update: 10:26:41, aiRealTimeCalc: calculation based on real-time data

These users thanked the author SUPER for the post:
JoshM

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby JoshM » 23 Apr 2012

SUPER wrote:I ran you code on ticker symbol ES set at OpenOutCry Session and I got following results with MC 8.0 beta2, looks like expected behaviour.

Thanks Super for checking this on your MC. :)

In your output, the aiRealTimeCalc also returns "real-time data" while the session hasn't started (so the calculations aren't performed on "real-time data" even tough aiRealTimeCalc say they do).

True MC Support, the quote field updates in Super's output, but RecalcLastBarAfter also causes aiRealTimeCalc to return "real-time data" when there are no quote fields updates (like the first post in this thread shows).

If it's expected behavior, this doesn't make aiRealTimeCalc very useful (and the documentation text wrong), since aiRealTimeCalc returns "real-time data" with a) RecalcLastBarAfter usage, b) Playback mode, and c) when the chart and indicators actually update with real-time data.

If this is "by design", I would suggest a GetAppInfo parameter like "aiRealRealTimeCalc", which returns a 1 when the calculations are performed on real "real-time data" (i.e. an actual updating chart), and a zero in all other cases.
These users thanked the author JoshM for the post:
SUPER

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby SUPER » 23 Apr 2012

JoshM wrote:If this is "by design", I would suggest a GetAppInfo parameter like "aiRealRealTimeCalc", which returns a 1 when the calculations are performed on real "real-time data" (i.e. an actual updating chart), and a zero in all other cases.



JoshM,

Totally support your view, hope MC implements this in thier next version.
These users thanked the author SUPER for the post:
JoshM

User avatar
Henry MultiСharts
Posts: 8520
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby Henry MultiСharts » 23 Apr 2012

That is expected behavior. GetAppInfo(aiRealTimeCalc) returns “1” if the tick has been received as real time feed. RecalcLastBarAfter recalculates the code after the specified interval, even if there is no new ticks, GetAppInfo(aiRealTimeCalc) will return “1” for the last received real time tick.
What I can recommend is to trace the bar Volume. If Volume changes then there is real time feed, if it does not change-there is no real time.
These users thanked the author Henry MultiСharts for the post:
JoshM

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby JoshM » 23 Apr 2012

[Removed since the aRealTimeCalc function, see below, seems to provide a reliable work-around for the problem.]
Last edited by JoshM on 23 Apr 2012, edited 1 time in total.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: RecalcLastBarAfter messes up aiRealTimeCalc

Postby JoshM » 23 Apr 2012

The function below, aRealTimeCalc, with Function Storage set to 'Simple' and Return Type to 'Numeric', gives a value of '1' only if the chart is updating with real-time data, and a zero in all other cases.

It uses the LastBarOnChart_s to only check this on the last bar of the chart, it uses GetAppInfo(aiRealTimeCalc) to filter out those conditions where there is no real-time data (such as when it's added to a chart and initialised). Then it uses the SessionStartTime and SessionEndTime (the sessions of the chart, not QuoteManager) to see whether or not the last Quote update falls in this range. I think this covers all possible conditions, but correct me if I'm wrong.

Code: Select all

{
   aRealTimeCalc
   -------------
   Function that provides a work-around for the GetAppInfo(aiRealTimeCalc) returning a 1, signalling
   real-time data, when used in conjunction with RecalcLastBarAfter(). This function returns a value
   of 1 when the chart's calculations are based on real-time data, and a zero (0) in all other cases.
}

Variables:
   sessionStart(SessionStartTime(0, DayOfWeek(CurrentDate)) * 100),
   sessionEnd(SessionEndTime(0, SessionCount(0) - 1) * 100);

if (LastBarOnChart_s = True) and (GetAppInfo(aiRealTimeCalc) = 1) and (q_time_s >= sessionStart) and (q_time_s <= sessionEnd) then
   aRealTimeCalc = 1
else
   aRealTimeCalc = 0;


It works correctly in my testing here, but please report any problems. :)
These users thanked the author JoshM for the post:
Henry MultiСharts


Return to “MultiCharts”