My SetScale code has Synchronization issue
Author: kazuna
Creation Date: 1/23/2013 4:07 PM
profile picture

kazuna

#1
Here is a code example I tested on WLP 6.4.
CODE:
Please log in to see this code.

profile picture

kazuna

#2
Run this strategy code in streaming window under 1-minute scale symbols below and observe the last five logs in the debug log.
Make sure you have both 1-minute and daily scale .VIX datasets before running the strategy.

[.VIX / 1-minute scale] (looks good)

VIX_1 / VIX_SMA = 13.7 / 17.4589000000001
VIX_1 / VIX_SMA = 13.45 / 17.4485500000001
VIX_1 / VIX_SMA = 13.52 / 17.4392000000001
VIX_1 / VIX_SMA = 13.28 / 17.4229000000001
VIX_1 / VIX_SMA = 12.67 / 17.4067000000001

[SPY / 1-minute scale] (looks wrong!!!)

VIX_1 / VIX_SMA = 13.41 / 13.5633
VIX_1 / VIX_SMA = 13.37 / 13.2969499999999
VIX_1 / VIX_SMA = 13.61 / 13.3884
VIX_1 / VIX_SMA = 12.33 / 12.53595
VIX_1 / VIX_SMA = 12.55 / 12.6255
profile picture

kazuna

#3
Notice that VIX_SMA is not based on daily scale data if it is run under symbols other than .VIX.

1) Is this a known issue being fixed in 6.5 or later?
2) Is there a workaround for this issue so that I can access both 1-minute and daily external symbols?
profile picture

Cone

#4
SetScaleDaily works on the Context Bars, not just any series that you reference. So, if you access another series unsynchronized (as you did here), you are working with data from the base timeframe.

To fix it, you can get VIX_D by passing true. Or, if you really want to create the moving average of the unsynchronized .VIX daily series first...

CODE:
Please log in to see this code.

profile picture

kazuna

#5
That "SetContext" fixed the problem. Thank you.

However, I found another issue.

[.VIX / 1-minute scale] VIX_1 looks good.

VIX_1 / VIX_SMA = 13.7 / 17.4589000000001
VIX_1 / VIX_SMA = 13.45 / 17.4485500000001
VIX_1 / VIX_SMA = 13.52 / 17.4392000000001
VIX_1 / VIX_SMA = 13.28 / 17.4229000000001
VIX_1 / VIX_SMA = 12.67 / 17.4067000000001

[SPY / 1-minute scale] VIX_1 looks wrong and it is one bar behind than the primary symbol.

VIX_1 / VIX_SMA = 13.41 / 17.4589
VIX_1 / VIX_SMA = 13.37 / 17.44855
VIX_1 / VIX_SMA = 13.61 / 17.4392
VIX_1 / VIX_SMA = 12.33 / 17.4229
VIX_1 / VIX_SMA = 12.55 / 17.4067

If i replace VIX_1.Open[bar].ToString() with VIX_1.Open[bar+1].ToString(), I get correct open value.
Any idea?
profile picture

kazuna

#6
I updated the code slightly to print the date/time of the bar.
CODE:
Please log in to see this code.

The result is interesting.

[.VIX / 1-minute scale]
2013/01/22 09:32:00 / 2013/01/22 09:32:00 : VIX_1 / VIX_SMA = 13.28 / 17.4229000000001
2013/01/23 09:32:00 / 2013/01/23 09:32:00 : VIX_1 / VIX_SMA = 12.67 / 17.4067000000001
2013/01/24 09:32:00 / 2013/01/24 09:32:00 : VIX_1 / VIX_SMA = 12.73 / 17.3871000000001

[SPY / 1-minute scale]
2013/01/22 09:31:00 / 2013/01/18 16:00:00 : VIX_1 / VIX_SMA = 12.33 / 17.4229
2013/01/23 09:31:00 / 2013/01/22 16:00:00 : VIX_1 / VIX_SMA = 12.55 / 17.4067
2013/01/24 09:31:00 / 2013/01/23 16:00:00 : VIX_1 / VIX_SMA = 12.49 / 17.3871

So it looks like .VIX is special and it does not have a bar at 09:31 probably because it is calculated based on the data at 09:31.
Because GetExternalSymbol(true) filling the bar with the previous available bar data, it is filling the bar with the data at 16:00?
profile picture

Cone

#7
That is correct and precisely how secondary symbol synchronization is supposed to work.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).