Translating dynamic watchlist script
Author: dansmo
Creation Date: 2/26/2010 2:42 AM
profile picture

dansmo

#1
Hello,

I am using a script from cone that gives back a boolean if a symbol is on a speciified list that is stored in txt files.
Can someone translate it to v5 code?

CODE:
Please log in to see this code.


Maybe this is something for community.components?
profile picture

Eugene

#2
Here are a few pointers from Wiki on An equivalent WealthScript function can't be found.

* For file operations, see StreamReader, StreamWriter etc.
* Replace TLists with List<> or other collections such as ArrayList, SortedList, Hashtable etc
* For string operations in C#, look at the String class methods

But honestly, it would be optimal to rewrite such kind of script from scratch in C# rather than trying to translate it.

1) How does the data file look like?
2) How were you using it?
profile picture

dansmo

#3
QUOTE:

But honestly, it would be optimal to rewrite such kind of script from scratch in C# rather than trying to translate it.


Thats exactly why I did not want to use the Translator tool. I thought this would result in a total mess ;-).

The way I was using it was for survivorship bias. The funcion returns true if a symbol was in the list on a given bar.
The structure of the files is following:

One file is a library of all the available files that contain the symbols that are active from this file to the next file. The individual files have the naming convention xxxx_yyyymmdd.txt.
Lets assume you have these files:
DAX_20010702.txt
DAX_20010910.txt
DAX_20020923.txt
Each of those files holds a list of symbols that were in the index at this date. The list is one smybol at each line. The assumption is, that each symbol in the list is active or onWatch (how it is named in the v3 code) until the next file. If it still appears it was still in the index, if not it was dropped.

Additionally there is one file I named "Bestandsliste.txt", which is a library of all single files. So in this example "Bestandsliste.txt" holds in every line the names of the files
DAX_20010702.txt
DAX_20010910.txt
DAX_20020923.txt.


One can use this function for index components or any othere operation where one creates a watchlist that is replaced from time to time.
profile picture

Eugene

#4
I don't find this design particularly appealing, i.e. having multiple files per index. In my opinion, having a file containing only the changes for a WatchList would be more optimal and would lead to a simpler design. For example:

1. FAQ 5: How can I perform a $imulation on an evolving WatchList of Index constituents?
2. Gbeltrame's TDynamicWatchList study, usage example #3.

If I was to include a class in Community.Components, I'd code it up to "FAQ 5..." and stick with it. Nonetheless, here's a quick example of reading a folder containing multiple files. You need to specify a folder, an index name, and pass the current Bars object.

Hint: please try picking a meaningful title to your forum thread... Stuff like "Translating this script", "Help me" etc. absolutely won't help other people interested in the same idea to join the discussion, suggest their ideas etc. "Evolving watchlist", "Dynamic watchlist in V5" - that's an example of a good title that attracts attention of other persons interested in overcoming survivorship bias.

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

dansmo

#5
QUOTE:
1. FAQ 5: How can I perform a $imulation on an evolving WatchList of Index constituents?


Tis page says:
QUOTE:

Note that the solution above does not account for symbols that exit and reenter the WatchList. Another more complete, but more complex solution was posted by kgo in this thread (click).


And that is exactly why I the concept is designed as it is presented in posting #1- btw. If you read kgo´s thread you will see that I contributed there and acutally am using hsi method in WL4 ;-).
QUOTE:

Nonetheless, here's a quick example of reading a folder containing multiple files. You need to specify a folder, an index name, and pass the current Bars object.


Thank you. Will try it.

QUOTE:
Hint: please try picking a meaningful title to your forum thread... Stuff like "Translating this script", "Help me" etc. absolutely won't help other people interested in the same idea to join the discussion, suggest their ideas etc. "Evolving watchlist", "Dynamic watchlist in V5" - that's an example of a good title that attracts attention of other persons interested in overcoming survivorship bias.


You are absolutely right. I will change this in the future.
profile picture

dansmo

#6
Hi Eugene,

I tried to get it run for every bar, but somehow this does not work.
I modified the Execute() part of the script:
CODE:
Please log in to see this code.


Why do I get "Object reference not set to an instance of an object" Error?
profile picture

Eugene

#7
Our Wiki could give a hint on Object reference not set to an instance of an object, but I think it's because my code doesn't yet have a check for the existence of a symbol list on a date before the first date. It's a Sunday prototype, not a fully tested solution.
profile picture

dansmo

#8
Would it be possible for you to implement it?
profile picture

Eugene

#9
Sure, when time permits.
profile picture

Eugene

#10
I have added the FirstIndexDate property to the class; it holds the date of the first symbol list file found. See revised code above.
profile picture

dansmo

#11
Thank you Eugene. Frist tests show that its running as expected.
profile picture

Eugene

#12
I think of adding basic support for "evolving watchlists" based on this code to Community.Components.
profile picture

dansmo

#13
Great news!
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).