Unable to cast object of type 'WealthLab.DataSeries' to type 'WealthLab.Indicators.RSI'
Author: kelvinyip
Creation Date: 3/5/2016 7:10 AM
profile picture

kelvinyip

#1
I think I am not doing anything special but I got this exception. Did I forget to upgrade some .netframework or something like that ?

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'WealthLab.DataSeries' to type 'WealthLab.Indicators.RSI'.
at WealthLab.Indicators.RSI.Series(DataSeries ds, Int32 period)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at WealthLab.ChartControl.IndicatorDragDropManager.d(IndicatorDescriptor A_0)
at WealthLab.ChartControl.IndicatorDragDropManager.CreateDragDropIndicators()
at WealthLab.ChartControl.Chart.set_Bars(Bars value)
at WealthLabPro.ChartForm.set_Bars(Bars value)
at WealthLabPro.ChartForm.SymbolSelected(DataSource ds, String symbol)
at WealthLabPro.MainForm.a(Object A_0, DataSourceSymbolEventArgs A_1)
at WealthLab.DataSourceTreeView.OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
at WealthLab.DataSourceTreeView.OnAfterSelect(TreeViewEventArgs e)
at System.Windows.Forms.TreeView.TvnSelected(NMTREEVIEW* nmtv)
at System.Windows.Forms.TreeView.WmNotify(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
profile picture

Eugene

#2
What exactly were you doing to get this exception? Please give us the details, the more the better. Is this a chart window or strategy window; which indicators does it have; symbol(s) and time frame etc. To understand and fix we need to be able to reproduce.
profile picture

Eugene

#3
P.S. One more thing. Please run this code and tell me the framework version:

CODE:
Please log in to see this code.
profile picture

kelvinyip

#4
I ran the code you gave and it says I am on 4.5 or later .net. I got these 2 files on the console saying that it might be useful. They are attached.
I have pure strategy code and then I tried to insert indicator using the wealthlab GUI drag and drop. I wonder if that's what causing the crash. I vaguely remember that I can either use code or the GUI but not both. If so, how do I remove the indicator ? wealthlab will crash if I try to run the code again. There must be some file that remembers the indicator assignment ?
profile picture

kelvinyip

#5
Yeah, I clear all indicators and it works again. I think code and GUI don't match. In 6.4, I think it was ok. weird
profile picture

Eugene

#6
Glad that you've sorted it out on your own. The Strategy's XML file remembers the indicator assignment. Something has gone wrong and clearing drag & drop indicators has fixed it. Your workaround has been added to the Wiki, but it's also known that this error can happen if you run some code in a non-native time scale:

Unable to cast object of type 'WealthLab.DataSeries' to type 'WealthLab.Indicators.MACD'.

1. Did your strategy code have RSI?
2. What are the steps to make this happen: strategy code, drag n' drop RSI's settings, data loading settings, symbol etc?
profile picture

robinkno

#7
I got this error: "Error processing symbol ZTS Unable to cast object of type 'WealthLab.DataSeries' to type 'WealthLab.Indicators.StochK'." when running a backtest on a portfolio with ZTS as the last symbol. When run on any individual symbol no errors.

Using Daily data with daily and weekly time frames. Daily only works but introducing weekly caused the error.

The backtest appears to work OK and the error appears as soon as I try to look at a chart of a trade within the result. No matter which trade or symbol I try to chart ZTS always comes up as the error. ZTS on it's own works OK.

Tried clearing drag and drop and also tried using coded indicators rather than drag and drop.

Is this a bug or have I overlooked something else?
profile picture

Eugene

#8
Robin,

1. Have you updated Community.Indicators and TASCIndicators to their latest versions released recently? This is a must to fix most of those errors.
2. If yes, let's investigate further. What are the data provider, bar scale, DataSet, and of course, the strategy code?
profile picture

robinkno

#9
Eugene,

1. The Community and Tasc were both up to date.

2. I tried datasets from Fidelity data and TC2000 data in .txt files. Tested on DJ30 and SP500. Daily data.

To make sure my code was not the issue I tested the sample code from the stochK indicator page and added the 4 lines for weekly stochK. They are all that is necessary to create the error. Run the code on the dataset, all seems well. Now click on a trade and the error appears and the indicator disappears from the chart.

CODE:
Please log in to see this code.
profile picture

Eugene

#10
QUOTE:
Using Daily data with daily and weekly time frames. Daily only works but introducing weekly caused the error.

Thanks for the details. I can reproduce the error message in Weekly scale. Explanation already exists in the Wiki and you know it:

Solution 1:
This error can happen when a Strategy is being executed in non-native time scale. (...)


Having said that, I don't know why you're trying to run this code in Weekly scale. Since the code does a SetScaleWeekly, you would want to run it on Daily and below - not on Weekly.
profile picture

robinkno

#11
I am running it in Daily Scale, not weekly, that is why SetScaleWeekly is there.

From the explanation Solution 1:
"This obviously applies to "lower" time scales because Wealth-Lab would easily upscale from Daily to Weekly, for instance."

So I thought this should work with daily data, daily scale and upscale to weekly should work.

Should I now assume that the upscale is also a known bug?

attached is a print screen of WL screen showing code and settings.

When you run the code go to the trades tab and select a trade. The error will appear and the indicator will have disappeared from the chart.

The error only occurs when you run on DataSet. Each individual symbol works without error.
profile picture

Eugene

#12
Thanks Robin, I can duplicate it now. Congratulations on having discovered what seems like a new bug.

The problem here is that many indicators can not "live" together despite being set in different bar scales. These are StochK, StochD, ADX, ADXR... to name a few. Other indicators I tried like RSI and ROC do not seem to suffer from this issue. What makes the first group different is the use of Bars as a parameter whereas the second group uses DataSeries and doesn't accept Bars.

So I gather that those that accept a Bars parameter are susceptible whereas the others are not. I'm going to add a note to the Wiki's Open Issues page and file a bug report to the development team.
profile picture

robinkno

#13
Ok Eugene, that's not the prize I hoped to win!
profile picture

Eugene

#14
P.S. The Wiki note has been added.
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).