NullReferenceException when Strategy is loaded after optimizing+saving
Author: electricessence
Creation Date: 7/13/2017 3:30 PM
profile picture

electricessence

#1
System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at WealthLab.StrategyManager.GetWealthScriptObject(Strategy s)
at WealthLabPro.ChartForm.set_Strategy(Strategy value)
at WealthLabPro.MainForm.OpenStrategyWindow(Strategy s, Boolean executeOnSelectedSymbol, Boolean useAdvancedSettings)
at WealthLabPro.HomeForm.a(Object A_0, EventArgs A_1)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

This occurs reliably, but I do not know when or what has caused the state.
I know that it will happen only after optimizing and then either setting/saving the parameters, or saving the strategy.

And seems to only happen on relaunch and not immediately after optimization.
Prevents me from using WealthLab at all.

Workaround: Delete created XML files under ...\AppData\Roaming\Fidelity Investments\WealthLabPro\1.0.0.0\Data\Strategies\...

This is frustrating because I have to manually edit my code to update the parameters knowing that saving them will cause an error. :(

Also, I really don't understand what effect 'setting' parameter values to specified symbol does because it is not obvious and looks like there's no change.
profile picture

Eugene

#2
1. Does this affect some particular strategy or all in principle (e.g. rule-based or canned "Moving average crossover")? If it's only your Strategy that is affected, then there might be something about its code that upsets WL:

An error occured when tried to use "Open Workspace"

I wouldn't be surprised to find out it's something specific to your Strategy code since you've been using Visual Studio for years.

2. And on a related note, could you dedicate a few minutes to try out a suggestion? We'd like to get Neuro-Lab up and running for you:

Neuro-Lab crashes immediately
profile picture

electricessence

#3
RE 1:
I can imagine this being true, but how am I supposed to fix if the stack doesn't actually pass through my code. :/
And, it only happens when loading the XML. :(
profile picture

electricessence

#4
I have a funny feeling (since this has happened across all the strategies I've been working on) that it's not my code but something with the the parameters or how the XML is loaded/saved. :(

Why would it be my code if it's simply happening when loading the params?

Here's how I create my params:
I do all the param creation in the constructor. Nothing special there.
Is that wrong?
profile picture

Eugene

#5
QUOTE:
I can imagine this being true, but how am I supposed to fix if the stack doesn't actually pass through my code. :/

Fortunately, you can make it pass through by creating a compiled Strategy library as shown below:

How can I debug my trading strategies in Wealth-Lab?
Strategies.ActiveTrader - open source example of a Strategy library

QUOTE:
I have a funny feeling (since this has happened across all the strategies I've been working on) that it's not my code but something with the the parameters or how the XML is loaded/saved. :(

Okay, but how do I reproduce it? Step by step from a blank strategy template (or "Moving average crossover") to getting the error message, please.
profile picture

electricessence

#6
I'll work on this and get back to you. For now try adding few parameters in the constructor. Run optimization. Adjust the defaults and save the strategy. Then restart wealthlab.
profile picture

Eugene

#7
QUOTE:
For now try adding few parameters in the constructor.

How exactly?
What parameters exactly?
QUOTE:
Run optimization.

What optimization? There are 5 methods total.
QUOTE:
Adjust the defaults

In the Optimization window or in code?


As these are everyday tasks please be specific.
profile picture

electricessence

#8
I updated to the new WealthLab. I know there's no note that would indicate that this fixed anything. But lemme try and see if the issue happens again. I've been avoiding 'setting defaults' or adjusting the parameters manually and saving so that might be negating the error.

The error happens on startup right when you try to open the strategy.
profile picture

Eugene

#9
Cannot reproduce.

Looking forward to seeing a detailed procedure with sample code and applicable settings.