- ago
Thank you very much, Glitch. Your solutions works perfectly to mimic my V6 code. Since I spent quite a bit of time unsuccessfully trying to figure this out, I have a few questions I would appreciate you answering if you can.

1. I never came across "SymbolData" before, which appears to be a type of V6 "DataSeries" replacement. I couldn't find any documentation on this (not sure how to classify it) except it is defined as "public list SymbolData: A list of BarHistory instances..." So it is a class that contains a method to create a symbol history price / time series? I can't find the hierarchy this class belongs to; it is not listed as Class in the QuickRef. How should I have tripped across this? This is what comes up in V6 QR for DataSeries Object:

TimeSeries, IndicatorBase
Wealth-Lab 7: TimeSeries, IndicatorBase

2. I didn't realize that the values in my series were considered "indicator" data types, and that I had to use PlotIndicator as a V6 PlotSeries replacement to get the result I wanted. Again, not sure how I could have / should have figured this out from available documentation.

I want to be as efficient as possible in trying to resolve these issues on my own, assuming documentation or examples are available. Again, I appreciate any suggestions you have for me.

0
636
Solved
10 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.89% )
- ago
#1
I think the best bet is to liberally ask here on the forum, we respond within the hour typically. You can't get much better in terms of "expert answers" :)

SymbolData is an Indicator, you'll find it in the Indicators list. Like any complex software, there will be a discovery period and you'll likely find many more useful nuggets in your explorations, but be sure to ask here on the forum whenever the need arises.
0
- ago
#2
Thank you, Glitch. I'm good with your answer.

Are SymbolData instances only for use in PlotIndicator? Or is there a way to access members of this set, e.g.:

CODE:
double value vixExtract = vix[idx]

if run in the Execute section?

Or do I need to create a new vix series to operate on vix values?
0
Glitch8
 ( 10.89% )
- ago
#3
All indicators are instances of the IndicatorBase class, which descends from the TimeSeries class. So yes, you can access the data using the square bracket notation, just like with a plain vanilla TimeSeries.
0
- ago
#4
The above code construct had a typo. But this one:
CODE:
double vixExtract = vix[idx];

throws a RT error "Object reference not set to an instance of an object."

QUOTE:
Execute Exception (^NDX,274) Line 88 - Object reference not set to an instance of an object.
Execute Exception (^GSPC,274) Line 88 - Object reference not set to an instance of an object.
at WealthScript5.CTSVarLev.Execute(BarHistory bars, Int32 idx) in :line 88
at WealthLab.Backtest.UserStrategyExecutor.CountMapper(List`1 lst, DateTime dt)

0
- ago
#5
QUOTE:
SymbolData is an Indicator, you'll find it in the Indicators list.

But there's more. SymbolData is designed to fetch an external symbol that's not already part of the BarHistory passed in by Initialize(). Notice that it's taking a string for the symbol in question. If you just wanted to plot the BarHistory bars.Close TimeSeries passed in by Initialize()--which would be faster--then you could simply use PlotTimeSeries instead. Use SymbolData just for fetching external symbol data, which must be synchronized to the current symbol being analyzed.

QUOTE:
2. I didn't realize that the values in my series were considered "indicator" data types, and that I had to use PlotIndicator as a V6 PlotSeries replacement to get the result I wanted.

Ahhhh. You need to understand OOP (object-oriented programming) design to make an informed choice here. But the short answer is that IndicatorBase is inherited from TimeSeriesBase, so technically you can use either PlotIndicator or PlotTimeSeries to plot an indicator. But generally speaking, I would use the highest-level ("smartest") call whenever possible. In this case, that would be PlotIndicator. The highest-level call can take advantage of internal state variables (which are part of the indicator object, but not part of the TimeSeries object) for creating a smarter plot.

I don't think WL6 required as much an understanding of OOPs design as WL7. But it's this OOPs architecture that makes WL7 more powerful for those familiar with it.
0
- ago
#6
Thanks for that, @superticker. It is an external symbol. Here's the code that fetched the bar history:

CODE:
//get VIX SymbolData vix = SymbolData.Series(bars, "$VIX", PriceComponents.Close); PlotIndicator(vix, Color.Navy, PlotStyles.Line, false, "VIX");


It works fine with PlotIndicator, but doesn't seem to be accessible by index, as Glitch stated, for me. Am I missing a step, like Synchonize?
0
- ago
#7
QUOTE:
[vix] doesn't seem to be accessible by index,... Am I missing a step, like Synchonize?

SymbolData already synchronizes your external symbol (vix in this case) with the current symbol BarHistory Initialize() passed in. (Check the SymbolData docs for Indicators.) That's why you're using SymbolData in the first place.

And vix is like any other IndicatorBase type. It will take an [indexer] as shown below.
CODE:
double vixCloseAtBar = vix[bar];

QUOTE:
throws a RT error "Object reference not set to an instance of an object."
There's nothing wrong with the above code. Perhaps the indexer isn't set right. Try vix[4] and see if that works. Or perhaps that error message applies to the line above it.
0
Glitch8
 ( 10.89% )
- ago
#8
Here's a complete, minimal, example using an indexer to access the data from an IndicatorBase (TimeSeries) variable.

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) {          vix = SymbolData.Series(bars, "$VIX", PriceComponents.Close);          PlotIndicator(vix);          int idx = bars.Count - 1;          double value = vix[idx];          DrawHeaderText("Last value of VIX is " + value.ToString("N2"), Color.Black, 14); } //Execute public override void Execute(BarHistory bars, int idx) { }       //private members       private IndicatorBase vix; } }
0
Best Answer
- ago
#9
The external symbol discussion that didn't relate to SymbolData now has a new home at:
https://www.wealth-lab.com/Discussion/Detect-an-open-position-in-an-external-symbol-7118
1
- ago
#10
@Glitch @superticker thanks for your help with this. The problem was my setup in C#. The problem was with which section in the code the vix variable was declared that was the cause of the RT error. Working now. Thanks again.
1

Reply

Bookmark

Sort