Trying to oursource the code for "Interacting with Equity" to my DLL
Author: MDA
Creation Date: 12/9/2019 11:21 AM
profile picture

MDA

#1
Hello,

I'm trying to outsource the code for creating equity.

Within the "normal" code it works. When I outsource the code the code is compiled error free. But during execution I get a general error message.

This is the code:

CODE:
Please log in to see this code.


Can anyone help?

Kind regards
Matthias
profile picture

Eugene

#2
Help doing what exactly? Sorry, having trouble with my extrasensory ability. ;)
profile picture

MDA

#3
I call the method in the "normal" script:

CODE:
Please log in to see this code.



and get a general error message. The code works directly in the trading script. If I "outsource" it it doesn't work anymore.
profile picture

MDA

#4
the code abort occurs in line
CODE:
Please log in to see this code.


profile picture

Eugene

#5
What does it mean that you "outsource" the code, precisely? Please clarify where exactly MD_Tools1 resides in?

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

MDA

#6
the code should be in a separate .dll
profile picture

Eugene

#7
That's correct. Thanks for making it clear. What "general error message" do you get? Please expand the exception details and strike Ctrl-C to copy the underlying error message and Ctrl-V to paste it when replying (a standard Windows shortcut). Also, taking a screenshot of the error dialog may be helpful.
profile picture

MDA

#8
The error message is not very concrete and unfortunately in German.

Runtime error: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei WealthLab.Strategies.MyStrategy.Execute()
bei MD_Tools1.Tools.equitySchreiben(String inHandelsstrategiename)



Since the code "doesn't swap" works, I don't know where to look for the error.
profile picture

Eugene

#9
1. Firstly, just to make sure we're not going in the wrong direction. What's wrong with Community Components? Why can't you just add a reference to its DLL file and simply reuse the "Interacting with Equity" solution? Just trying to understand why you're "outsourcing" it to another DLL with so much trouble.




2. It's clear intuitively that you're getting an "Object reference not set to an instance of an object". It's not specific so it doesn't give much clue, you're right. At the moment I'm very busy to do the troubleshooting of your code library but you can (and are expected to) do it if you follow this simple step by step procedure:

Programming | How can I debug my trading strategies in Wealth-Lab?

When you hook up your MD_Tools1 library and do everything right, Visual Studio should highlight the problematic code line where you can inspect the state of any variables and objects.

There are numerous forum topics to help out on your way but feel free to ask questions.

P.S. Should you get another error message in German or any other language, simply go to this site and paste the error to get its translation to English:

http://finderr.net/search?q=Der%20Objektverweis%20wurde%20nicht%20auf%20eine%20Objektinstanz%20festgelegt

This is a translator for .NET error messages into English.
profile picture

MDA

#10
Oh dear, I don't understand the first remark very well. I don't know exactly what you mean. Which dll should be referenced?

Again to the background. If I open a trading system in Wealth Lab, then the equity should be spent for this trading system. If I implement the corresponding code directly into the trading system code, then it works perfectly.

Since this equtity code unnecessarily increases the trading system code, I wanted to outsource this equtity code.

Only this equity code alone does not do much, because no special settings are taken into account by the trading system, such as special "position options". Since each trading system has different settings, it is better to execute the equity code from the trading system code. Because when the trading system is loaded (with workspace) then all settings are correct. With the outsource I just wanted to save a few lines per trading system code.

Sorry for my bad English.

Translated with www.DeepL.com/Translator (free version)
profile picture

Eugene

#11
What you're saying makes sense. To fix the issue, replace these lines (obsolete)...

CODE:
Please log in to see this code.


...with these:
CODE:
Please log in to see this code.


Of course this all implies that the strategy named "Beispiel" actually exists.

QUOTE:
Which dll should be referenced?

WealthLab.Components.Community.dll. Don't worry, it's already referenced in your project or it won't compile.
profile picture

MDA

#12
Thank you so much. The code now works without error message. Unfortunately the correct equity is not output. A value appears that I can't assign anywhere.
profile picture

Eugene

#13
Not sure what "can't assign anywhere" may mean. Your code assumes that 1) the strategy "Beispiel" exists and 2) it's run in Single-Symbol Backtest mode.
profile picture

MDA

#14
Ahhh. Now I see it. It the the equity only from the first symbol in the list.

Is there a change possibility for Portfolio Backtest? As I said, the same equity code within the trading strategy code works fine. Also with Portfolio Backtest.
profile picture

Eugene

#15
QUOTE:
Is there a change possibility for Portfolio Backtest?

Sure there is!

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

MDA

#16
hmm, doesn't work, I'm afraid. Now I don't get an error message in the small window below the code. Now I get an error message in the external debug log window:

"Error processing symbol IWM The object reference was not set to an object instance".

This error is displayed for every single symbol.
profile picture

Eugene

#17
At the risk of repeating, the strategy named "Beispiel" must exist. Change that to "Moving Average Crossover" to make sure that everything works.
profile picture

MDA

#18
the "Beispiel" code exists. With
CODE:
Please log in to see this code.
it basically worked. I test again with simpler strategies.
profile picture

Eugene

#19
Sounds reasonable.
profile picture

MDA

#20
Problem found. I have restricted the trade in the "Beispiel" code to certain symbols with a csv list.

Without this restriction, i.e. without such a line

QUOTE:
foreach (var lineL in File.ReadLines(ETFListLong))


in the trade code, it works.

Strange. With the other two variants
(i) Equity code in trading code
(ii) Equity code outsourced, but limited to single symbol
that line didn't cause any problems.

But I can deal with that. Most trading systems have no symbol restrictions.

Thank you very much for your great help.
profile picture

Eugene

#21
Glad I could be of assistance!
profile picture

MDA

#22
I'm afraid I'll have to call you again. The above solutions only work with simple codes. My more complex codes are not loaded or produce errors. Otherwise the more complex codes run error-free in Wealth Lab.

Unfortunately I can't get any further. Is there another possibility to get the Euqity values? It would be very annoying and time-consuming if I had to program something extra to create an equity. Especially since the required values are available.
profile picture

Eugene

#23
You can copy the Equity values to clipboard: right click on the Equity Curve tab and choose "Copy equity curve data to clipboard".

On troubleshooting your complex code please refer to my post #9 above. If you wish to solve problems that will arise with any complex solutions, debugging in a tool like Visual Studio is the best skill to learn.
profile picture

MDA

#24
Copying to the clipboard is too time-consuming if you need the equity values regularly. Unfortunately, that doesn't help me either.

There doesn't seem to be any other solution. Let's see how I solve the problem. I've never done WL Code Debugging in Visual Studio before.
profile picture

Eugene

#25
Then it's a good chance to start! :)

Just follow the step-by-step tutorial and search the forum for typical questions answered in the topics having "visual studio" in their title.

By the way, what errors are thrown for your "more complex" code?
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).