Synchronisation problem / Missing Barnumbers

Questions about MultiCharts and user contributed studies.
Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Synchronisation problem / Missing Barnumbers

Postby Fredi » 10 Jan 2014

With checking BARSTATUS I want to sync multi-data studies (same instrument).
Data1: 1 point DAX future
Data2: 16 point DAX future

The problem: I don´t get every Barnumber of Data2; that means, I can't trigger
reliably (buy/sell) my strategy with Data2.

Code: Select all

if (BarStatus(1) = 2) And (BarStatus(2) = 2) then
Print(FormatTime("HH:mm:ss", el_timetodatetime_s (time_s))
+ " BarN2=" + NumToStr(CurrentBar of Data2 + Maxbarsback of Data2,0)
+ " Barstatus2=" + NumToStr(BarStatus(2),0)
+ " Close1=" + NumToStr(close of data1,1) + " Close2=" + NumToStr(close of data2, 1));
Running in real-time it is producing this output (Barnumbers 400, 401, 406 are missing):

16:07:26 BarN2=398 Barstatus2=2 Close1=9458.5 Close2=9458.5
16:09:58 BarN2=399 Barstatus2=2 Close1=9465.0 Close2=9465.0
16:12:27 BarN2=402 Barstatus2=2 Close1=9460.5 Close2=9461.0
16:12:49 BarN2=403 Barstatus2=2 Close1=9456.5 Close2=9455.5
16:14:08 BarN2=404 Barstatus2=2 Close1=9462.0 Close2=9462.0
16:15:33 BarN2=405 Barstatus2=2 Close1=9460.5 Close2=9460.5
16:18:52 BarN2=407 Barstatus2=2 Close1=9472.5 Close2=9472.5


The anaylsis I made with
- "Realtime history matching" (RHM on/off) as well as with
- "IntrabarOrderGeneration" (false/true) and with intrabarpersist Vars, also

The result was every time the same. What do I wrong or is this known?

Regards,
Fredi

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 10 Jan 2014

Hello Fredi,

In order to make "if (BarStatus(1) = 2) And (BarStatus(2) = 2)" condition true you need to have the bars on both data series at the same time (with the same time stamp). If timestamps are different then the output of the data2 bar will be skipped, due to the fact that there is no bar with such timestamp on data1.
In order to avoid such situation you need to use time based resolutions on your chart.

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 10 Jan 2014

Ok. However - my strategy based on ticks (1 point and 16 points) so I can't switch to
a time based resolution.

And what I don't understand: why is the timestamp of Data2 not always automatically one
of the timestamps of Data1? Because both, Data1 and Data2, are basing on the same ticks /
timestamps in the data base of the QuoteManager (Data1 is a subset of Data2).

Is there any workaround for my problem?


Regards,
Fredi

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 12 Jan 2014

The problem is very much bigger than feared. With only Barstatus(2)=2 the missing barnumbers
are displayed. However it is impossible to get the OHLC values of the bars or to make any other
operations at this time, because the values aren't still valid after this time.

Code: Select all

vars: count(0);
if (BarStatus(2) = 2) then begin
Count = Count + 1;
Print(FormatTime("HH:mm:ss", el_timetodatetime_s (time_s))
+ " BarN2=" + NumToStr(CurrentBar of Data2 + Maxbarsback of Data2,0)
+ " Barstatus2=" + NumToStr(BarStatus(2),0) + " Count=" + NumToStr(Count,0)
+ " Close1=" + NumToStr(close of data1,1) + " Close2=" + NumToStr(close of data2, 1));
end;
And this is the output, now including the previously missing barnumbers (400, 401).

16:07:26 BarN2=398 Barstatus2=2 Count=218 Close1=9458.5 Close2=9458.5
16:09:58 BarN2=399 Barstatus2=2 Count=219 Close1=9465.0 Close2=9465.0
16:10:55 BarN2=400 Barstatus2=2 Count=220 Close1=9458.5 Close2=9458.0
16:12:10 BarN2=401 Barstatus2=2 Count=220 Close1=9455.0 Close2=9454.5
16:12:27 BarN2=402 Barstatus2=2 Count=220 Close1=9460.5 Close2=9461.0
16:12:49 BarN2=403 Barstatus2=2 Count=221 Close1=9456.5 Close2=9455.5


The problem will become already obviously with the variable Count: the results of the calculation
(Count increment by 1) were lost immediatly after Barstatus(2)=2 for the barnumbers 400, 401.
And the same happens with the OHLC values of Data2 at this time (not listed above): the values are
switching back to their previous values. Or with other words: In such a case all data (dataseries,
vars and operations during Barstatus(2)=2)) lose their values.

"Missing" barnumbers come up permanently during a simulation as well as in real-time.

Could please anybody confirm, explain and/or give a workaround for this event/behaviour?


Thank you in advance.
Fredi


PS: Possible, however to time-intensive: writing/reading the values in/from a file.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 13 Jan 2014

why is the timestamp of Data2 not always automatically one
of the timestamps of Data1?
Hello Fredi,

Point bars of different resolutions can have different timestamps due to the nature of the Point resolution.
To learn how the point bars are constructed in MultiCharts, please see this post and this document.

That is possible to modify your code to see when the bars of data1 and data2 do not have the same time stamp (BarStatus = -1):

Code: Select all

if (BarStatus(2) = 2) then
Print(FormatTime("HH:mm:ss", el_timetodatetime_s (time_s))
+ " BarN2=" + NumToStr(CurrentBar of Data2 + Maxbarsback of Data2,0)
+ " BS1=" + NumToStr(BarStatus(1),0)
+ " BS2=" + NumToStr(BarStatus(2),0)
+ " Close1=" + NumToStr(close of data1,1) + " Close2=" + NumToStr(close of data2, 1));
Image

In PowerLanguage regular variable's value is fixed on the main data series bar close.
If you want the variable value to be not reset - you need to use a Intrabarpersist variable.

Every "regular" variable will keep its value throughout the whole script calculation on all data series (if the value was assigned on the bar's close) until you assign a different value to it. 
Intrabarpersist never resets itself during the script calculation. 
 
The difference between regular variable and IntraBarPersist variable is that regular variable's value is fixed on bar close and IntraBarPersist variable's value is fixed even inside bar. 
 
For example: 
If you assign a value for regular variable inside bar (barstatus=1) - the variable value will not be kept on bar open/close (barstatus=0 and 2). 
If you do the same with intrabarpersist variable-the value will be kept on all barstatus values (0,1,2).
Attachments
example_1Point_16Point_Dax.PNG
(73.94 KiB) Downloaded 1304 times

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 20 Jan 2014

Thx Henry for this information.

An additional question comes up and I can't find any easy solution: same workspace as mentioned above with
Data1: 1 point DAX future
Data2: 16 point DAX future

Now I'm using, among other things, the indicator
RSID2 = RSI(Close of Data(2), 14) of Data(2);

In the Chart the "RSID2" is updated each tick. How I can update the RSID2 in the signal-script
in the same way (tick-by-tick update)?

Regards,
Fredi

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 27 Jan 2014

Hello Fredi,

As you already have function reference to data2 in your code it should already update based on data2:
RSID2 = RSI(Close of Data(2), 14) of Data(2);
Please also make sure the "update on every tick" is enabled in Format->Study->Format->Properties.

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 29 Jan 2014

I think, I didn't describe the problem correctly. The base data are still:
Data(1): 1 point DAX future (=Tick)
Data(2): 16 point DAX future

In a signal script - just like in the chart - I want to update RSI of Data(2) with the
actual Tick-Close. Or with other words: for RSI of Data(2) all Close of Data(2) should
be kept and RSI of Data(2) should be recalculated always with the actual Close (because
Data(1) is based on ticks the Close is a Tick-Close).

Code: Select all

{-- RSI for Data2 --}
RSID2 = RSI(Close of Data(2), 14) of Data(2);

{-- Copy / Reset: RSI2_Tick = RSI for Data2 --}
RSID2_Tick = RSI(Close of Data(2), 14) of Data(2);

{-- Update RSI2_Tick with the last (Tick-) Close --}
RSID2_Tick = RSI(Close, 14);
I tried a lot of approaches, like the above example. But nothing is working correctly.
How does MC calculating indicators of Data(2) based on ticks in the chart? How should
look like a solution in a signal script?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 30 Jan 2014

Fredi, please make sure the values of your variable RSID2 are fixed on data2.
The variable must be declared the following way

Code: Select all

Vars: RSID2(0, data2);

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 31 Jan 2014

The recommendation will not produce the desired result.

Independent from vars-Declaration [RSID2_Tick(0) or RSID2_Tick(0, Data2)]
I'm getting with this code ....

Code: Select all

once cleardebug;
vars: RSID2(0, data2), RSID2_Tick(0);

RSID2 = RSI(Close of Data2, 14) of Data2; // org. RSI for Data2 (reference)

RSID2_Tick = RSI(Close of Data2, 14) of Data2; // Reset: RSI2_Tick = RSI for Data2
RSID2_Tick = RSI(Close, 14) of Data2; // Update with Close (Example 1)

if (Date = 1140127) and (Time_s >= 202246) and (time_s < 202328) then begin

Print(FormatDate("dd.MM.yy", el_datetodatetime(Date)) + " " + FormatTime("HH:mm:ss", el_timetodatetime_s (time_s))
+ " BarN2=" + NumToStr(Symbol_CurrentBar of Data2,0) + " BarN1=" + NumToStr(Symbol_CurrentBar,0)
+ " C2=" + NumToStr(Close of Data2, 1) + " C1=" + NumToStr(C,1)
+" RSID2="+NumToStr(RSID2,2) + " RSID2_Tick="+NumToStr(RSID2_Tick,2)
+ " RSI1="+NumToStr(RSI(Close, 14),2));

end;
... the following results:

Test 1: RSID2_Tick = RSI(Close, 14) of Data2 (like in the code above)

27.01.14 20:22:46 BarN2=885 BarN1=45280 C2=9369.0 C1=9365.0 RSID2=69.88 RSID2_Tick=69.88 RSI1=48.49
27.01.14 20:22:46 BarN2=885 BarN1=45281 C2=9369.0 C1=9364.0 RSID2=69.88 RSID2_Tick=69.88 RSI1=42.89
27.01.14 20:23:04 BarN2=885 BarN1=45282 C2=9369.0 C1=9363.0 RSID2=69.88 RSID2_Tick=69.88 RSI1=38.15
27.01.14 20:23:10 BarN2=885 BarN1=45283 C2=9369.0 C1=9362.5 RSID2=69.88 RSID2_Tick=69.88 RSI1=36.00
27.01.14 20:23:14 BarN2=886 BarN1=45284 C2=9361.5 C1=9361.5 RSID2=62.64 RSID2_Tick=62.64 RSI1=32.11
27.01.14 20:23:21 BarN2=886 BarN1=45285 C2=9361.5 C1=9361.0 RSID2=62.64 RSID2_Tick=62.64 RSI1=30.35
27.01.14 20:23:25 BarN2=886 BarN1=45286 C2=9361.5 C1=9360.0 RSID2=62.64 RSID2_Tick=62.64 RSI1=27.14

Result: always RSID2_Tick = RSID2.
(Change of RSID2_Tick only with Bar2-change from 885 to 886)

Test 2: RSID2_Tick = RSI(Close, 14);

27.01.14 20:22:46 BarN2=885 BarN1=45280 C2=9369.0 C1=9365.0 RSID2=69.88 RSID2_Tick=48.49 RSI1=48.49
27.01.14 20:22:46 BarN2=885 BarN1=45281 C2=9369.0 C1=9364.0 RSID2=69.88 RSID2_Tick=42.89 RSI1=42.89
27.01.14 20:23:04 BarN2=885 BarN1=45282 C2=9369.0 C1=9363.0 RSID2=69.88 RSID2_Tick=38.15 RSI1=38.15
27.01.14 20:23:10 BarN2=885 BarN1=45283 C2=9369.0 C1=9362.5 RSID2=69.88 RSID2_Tick=36.00 RSI1=36.00
27.01.14 20:23:14 BarN2=886 BarN1=45284 C2=9361.5 C1=9361.5 RSID2=62.64 RSID2_Tick=32.11 RSI1=32.11
27.01.14 20:23:21 BarN2=886 BarN1=45285 C2=9361.5 C1=9361.0 RSID2=62.64 RSID2_Tick=30.35 RSI1=30.35
27.01.14 20:23:25 BarN2=886 BarN1=45286 C2=9361.5 C1=9360.0 RSID2=62.64 RSID2_Tick=27.14 RSI1=27.14

Result: always RSID2_Tick = RSI1 (= RSI(Close, 14)).
(Desired result must be, only at 20:23:14, with C2 = C1: RSID2_Tick = RSID2 )

Therefore the question is still: how I can update RSI of Data2 with Close of Data1 (between Bar2-changes)
like it happens in the chart?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 05 Feb 2014

Fredi, does this code produce the desired result?

Code: Select all

value1 = close;
RSID2_Tick = RSI(value1, 14) of Data2;
If no then please attach a screenshot of your chart and the log output so that we can see the desired result on the chart and the incorrect result in the code.

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 05 Feb 2014

Henry, unfortunately not. I tried it with the following code...

Code: Select all

once cleardebug;
vars: RSID2(0, data2), RSID2_Tick(0, data2), value1(0);

RSID2 = RSI(Close of Data2, 14) of Data2; // org. RSI for Data2 (reference)

RSID2_Tick = RSI(Close of data2, 14) of Data2; // Reset: RSI2_Tick = RSI for Data2
value1 = Close;
RSID2_Tick = RSI(value1, 14) of Data2; // Update with Close (Example 1)

if (Date = 1140127) and (Time_s >= 202246) and (time_s < 202328) then begin

Print(FormatDate("dd.MM.yy", el_datetodatetime(Date)) + " " + FormatTime("HH:mm:ss", el_timetodatetime_s (time_s))
+ " BarN2=" + NumToStr(Symbol_CurrentBar of Data2,0) + " BarN1=" + NumToStr(Symbol_CurrentBar,0)
+ " C2=" + NumToStr(Close of Data2, 1) + " C1=" + NumToStr(C,1)
+" RSID2="+NumToStr(RSID2,2) + " RSID2_Tick="+NumToStr(RSID2_Tick,2)
+ " RSI1="+NumToStr(RSI(Close, 14),2));

end;



Screenshot, including the output is attached (RSI_Data2.jpg).

At 20:23:09 (Data2 changed from Bar 2822 to 2823) the RSID2 switched from 69,88 to 62,64,
which is correct. However the RSID2_Tick is at this time with 51,72 far away from this
value (as well as the previous values).
Attachments
RSI_Data2.jpg
(106.64 KiB) Downloaded 1002 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 06 Feb 2014

Fredi, please attach the workspace you are using.

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 06 Feb 2014

Is attached.
Attachments
DD_2Tick.wsp
(49.59 KiB) Downloaded 406 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 07 Feb 2014

Fredi, sorry for this case taking so long. Our engineers have studied all possibilities.
Unfortunately that is not possible to update value of the variable calculated on data2 based on event of data 1.

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: Synchronisation problem / Missing Barnumbers

Postby Fredi » 07 Feb 2014

Thank you Henry. Do you see any sensefull ("with not too much effort") workaround
to realize such issue, like with an array etc.?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Synchronisation problem / Missing Barnumbers

Postby Henry MultiСharts » 10 Feb 2014

Hello Fredi,

We do not think any workaround is possible.


Return to “MultiCharts”