Hello,
I just fine-tuned a strategy and the strategy can properly run basing on the existing symbol. But when I click other symbols for test, it can't work with the error remarks as below:
QUOTE:
Runtime error: Object reference not set to an instance of an object
At WealthLab.Strategies.BollingerBuyer.Execute()
What could be the problem?
Thanks
Size:
Color:
Much too hard to guess without see the code.
Size:
Color:
So I need to put the strategy code here or just apply for a support ticket to send the code to you?
Thanks
Size:
Color:
BollingerBuyer, a pre-built strategy that came with WL, doesn't seem to be super secret code. It's best to start from
Errors | Strategy > "Object reference not set to an instance of an object". Most likely cause is described in paragraph #2:
QUOTE:
If "Benchmark Buy & Hold" symbol is defined and enabled in the Wealth-Lab's Preferences dialog, Backtest Settings, you need to make sure that the symbol name is valid and could be found in your DataSets. Entering a symbol that does not exist is a popular reason for getting this error message in backtests.
Size:
Color:
It's not the cause of 2nd paragragh.
The draft code is as below. Would appreciate if you can help to address the problem.
Thanks
CODE:
Please log in to see this code.
Size:
Color:
Easy one:
CODE:
Please log in to see this code.
That happens when
if (!IsLastPositionActive) i.e. you have no open positions, so you're checking the entry price for a Position that does not exist yet.
Size:
Color:
Thanks.
Yes, it's the cause.
So,is it possible to conduct the comparison for:
the "close(bar)" and the "entry price"(or the close price of the BAR at which last position buy/short) for the last postion which was sold/covered already?
Size:
Color:
Yes, by including an extra check for Positions.Count > 0 and at the same time making sure that the Position's Active property returns false (e.g. if(!LastPosition.Active) ).
Size:
Color:
It works now.Thanks a lot.
Size:
Color:
Hello,
I got the following error message when running the code below. The compilation is okay. My understanding is that the error is due to using the 'buy/sell' statements within a function beside that of 'Execute ()' function. Please let me know what can be done to resolve this. Thanks for any help.
CODE:
Please log in to see this code.
Size:
Color:
Strategies aren't meant to be self-referenced or become recursive. If you have a good reason for doing what you're trying to do, feel free to ask in a new thread - because being the most unusual cause of typical, FAQ-like "Object reference not set to an instance of an object" error I've ever seen, it doesn't really belong here. Otherwise the solution is to not break what's working.
Size:
Color:
Thanks Eugene, I am not sure what you mean by 'self-reference' or 'recursive' in this case. The reason I use this approach is to make the program more modular and its flow more easier to understand. The function that open & close positions is part of a larger program and will be call many times depends on a number of conditions. Having it resides on a function beside the Main or Execute () seems to be cleaner and makes more sense. Thanks.
Size:
Color:
Thanks for the clarification Tom. In fact, your program is trying to be exactly what you're not sure about -- i.e. be recursive or reference itself. The concept of recursion is outside C# 101 but still you might want to google it. You're invited to discuss the modular approach to building WealthScript programs in a new (or more appropriate) forum thread. This is a topic of its own.
Size:
Color:
i have the following code and it compiles but i get runtime error: object reference not set to an instance of an object, please help
CODE:
Please log in to see this code.
Size:
Color:
The DataSet parameter of GetExternalSymbol is context sensitive:
CODE:
Please log in to see this code.
Or simply don't use it (just like you do for "Bars b1"):
CODE:
Please log in to see this code.
Size:
Color:
i have been using this code with no issue and suddenly i have runtime error using symbol ^GSPC with yahoo provider, please help
CODE:
Please log in to see this code.
the run time error is index is out of range must be non negative and less than size of collection,
also daily, weekly, quaterly and yearly chart work but monthly chart gives an error
Size:
Color:
For possible reasons see
Errors >
Index was out of range. Most likely you have a broken chart drawing object on Monthly ^GSPC as the code runs for me just fine.
Size:
Color:
yes i was playing with the chart drawing objects, how do i fix it
Size:
Color:
i fixed it, i erased the objects and now it works thanks
Size:
Color: