SetContext vs GetExternalSymbol
Author: ss161
Creation Date: 11/30/2009 1:42 PM
profile picture

ss161

#1
I've read the two quick ref's repeatedly, but I'm having issues using both SetContext and GetExternalSeries and i don't understand when one should be used vs the other.

Here are some specific questions (whenever I use either of the above i have synch set to true):
1. if SetContext is called and the symbol is not in the current dataset but is in another dataset, I believe SetContext sets the Bars object to the data from the other dataset -- similar to GetExternalSeries being called without a dataset name specified. In one dataset, I have the symbol: AGII and for some reason, there is no data for it in the dataset (Yahoo provider, daily data). Separately, i have the same symbol in a Fidelity 5 minute dataset. It seems when i call SetContext( "AGII", true ). the bars object is set to the 5 minute object and then the system attempts to Synch it to my timeframe (which happens to be weekly). There seems to be a bug in this synchronization process as the data is not returned as weekly data.

2. Following in the above example where there is a symbol in a dataset with no data in it, I want Wealth-Lab to generate a runtime error (for which I am trapping in code), but Wealth-Lab doesn't seem to do that. Regardless of whether I specify the DataSetName or leave the DataSetName out, Wealth-Lab ignores the fact that the symbol is in my List but with no data and goes and tries to return the 5 minute bar data -- but with some synchronization error as above. How can I make Wealth-Lab generate the run-time error?

3. Can you provide guidance as to when GetExternalSeries should be used vs SetContext?

4. I think if GetExternalSeries is called with a specified DataSetName and the data can not be found, instead of Wealth-Lab going and search through other datasets for the symbol, it should Throw and error. If someone's gone through the effort to specify the dataset name and the symbol isn't there, the program probably shouldn't continue executing with other (possibly suspect data). (This last, not a question, but an opinion :) ).

Thanks for the help, as always!

Steve








here are the two quick ref entries:
CODE:
Please log in to see this code.

CODE:
Please log in to see this code.


profile picture

Cone

#2
1. SetContext finds the symbol in the current DataSet, but if not there it finds it in the first DataSet [from the same provider?] alphabetically. I'm not sure why there'd be a synch problem, so please create a ticket so we don't lose track of it.

2. Turn off Data On-demand?

3. In Version 5, SetContext is only needed if you need to create trades on a secondary symbol. GetExternalSeries provides the most flexibility if you just need to access secondary data to create indicators.

4. Seems like we've talked about this before, but the design is to try to find the data, and frankly it seems like it would take an act of God to change it now.
profile picture

ss161

#3
1. i'll create a support ticket
2. i never use data on demand
3. VERY HELPFUL EXPLANATION thanks. I'll only use SetContext if / when i want to trade the symbol.

By the way, I think I discovered an interesting undocumented feature or bug depending on how you look at it. If I SetContext( DataSetSymbols[i], true) to get a new context, and then SetContext to the next symbol in the list the next time through the loop without first restoring context, the Data from the new symbol comes in synchronized with the data from the last symbol, not the original "clickedsymbol". i think it's more of a bug than a feature because the data getting pulled in never extends back in time, only closer to the present.

4. we have talked about a related point before and the struggle is i've used the approach required by that discussion, but still have problems. i've attached some code below where i've wrapped the call to GetExternalSymbol in a Try / Catch statement and I'm specifying the current dataset name in the call. I would have thought this was as bullet proof as possible, but yet if there is an empty symbol int he curent dataset but the symbol exists somewhere else, it goes to the "somewhere else spot" to grab the data. this is the part that doesn't make sense. if you have any other coding suggestion, i'd appreciate it.

thanks.
CODE:
Please log in to see this code.

profile picture

Cone

#4
QUOTE:
By the way, I think I discovered an interesting undocumented feature...
Actually, it is intended to provide the most flexibility, and it's explained in the WealthScript Guide: DataSeries > Accessing Secondary Symbols > Secondary Series Synchronization > Note on Primary Bars.

Nonetheless, the QuickRef for SetContext doesn't cover that fine detail, so it probably should. The entry for GetExternalSymbol does cover it though: The synchronize method controls whether the returned Bars object will be automatically synchronized to the current Bars object.

Re: somewhere else spot
I understand what you're saying, but changing the baseline design requires an act of God (or a dozen customers calling in and complaining).
profile picture

tomphm

#5
Is it possible to specify dataset to use in SetContext()? Thanks.
profile picture

Eugene

#6
It's possible to specify the DataSet to use in GetExternalSymbol. Please refer to the QuickRef (F11).
profile picture

tomphm

#7
Thanks Eugene. Yes, I understand that GetExternalSymbol allows to specify DataSet but I am interested in using SetContext. This is to simulate trading on secondary symbols.
profile picture

Eugene

#8
I see. Sure you will find your question answered in the QuickRef for SetContext as well.

Hint:

1. Bars GetExternalSymbol(string dataSetName, string symbol, bool synchronize);
2. void SetContext(Bars bars);
profile picture

tomphm

#9
Thanks.
profile picture

Eugene

#10
You're welcome. Just to make it clear, the idea is to pass the Bars object created by GetExternalSymbol with the dataSetName overload, to SetContext.
profile picture

Eugene

#11
Discussion re: accessing intraday data from daily is moved to: Strategies based on multiple time frames?
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).