Tradable Trend Lines
Author: traderray
Creation Date: 5/22/2012 8:05 PM
profile picture

traderray

#1
I have set up several tradable trendlines for stocks in a single watchlist. When I try to run a backtest on the symbols in my watchlist, I do not get any alerts. When I go thru the stocks one by one, several of the stocks have an alert.

Is this a bug or am I doing something wrong?
profile picture

Eugene

#2
See if the passage about SetContext in the Remarks section for TrendlineValue in the QuickRef applies to your case.

If it's not the case, then this might be a bug or you're doing something wrong. But if you show us an example of what the backtest is doing and it performs not as expected, we might be able to tell more precisely. ;)
profile picture

traderray

#3
Eugene,

Here is how I am trying to use tradeable trendlines.
1. I scan my charts and draw tradeable trendlines at prices where I want to review the chart again.
2. I start a new script using "New Strategy From Code".
3. When I click on a symbol using this new script, I get an alert if my tradeable trendline is crossed. This alerts me to review the chart.
4. When I highlight the dataset name and run backtest of all symbols in the dataset, I do not get any of the alerts I get when I look at the charts one at a time.
profile picture

Eugene

#4
Between #2 and #3, anything can happen. It's your code, and we have no idea what you're doing there. ;)
profile picture

traderray

#5
The script is the default script you get when you get "New Strategy from Code". There is no logic in the script. WLP is kicking the alert out on its own when you run the default script on a single symbol.
profile picture

Eugene

#6
Thanks for the clarification.

Same QuickRef remark fully applies here. It's not possible to access a Trendline value because in a multi-symbol backtest, there is no Chart for the TrendLine to exist.

profile picture

traderray

#7
So the ONLY way to use trendlines is when you access a single chart.
profile picture

Cone

#8
Right, in a single chart.

Let's clarify something though. First you said "Tradable Trendlines". A TT is a specific drawing tool. TTs "inherit" from Trendlines (they have all the same properties of a Trendline), but you don't have to access a TT name in your code to get alerts. Even so, they only work in a chart window.

Finally, it's not necessary to have a chart if your code actually "draws" the TT. I say "draw" because it doesn't really have to DrawLine(), it needs only to "know" where the line is, i.e., calculate it.
profile picture

traderray

#9
Cone and Eugene,

Thanks for the education. I now understand the difficulty.

I love the concept of being able to draw tradable trendlines and then being able to scan for them each day. When one of the trendlines is broken, I know I want to review that chart. The concept works great on a single chart. Now my problem is the lack of scanning. I could view each chart seperately but that is a pain.

Now let's talk about a workaround. One concept is to have a script that I use when I draw the tradeable trendline determine and save two points on each line. The only trendline data that I am aware of that you can access is the trendline value at a particular bar so that is what I have to work with.

My second script, a scan script, would then retrieve the two points per tradable trendline for any chart that has tradable trendlines, and calculate the trendline. I could then determine if the trendline is broken on the day of interest and give an alert.

This is a long way around but I believe it should work. Do you see any problems with what I have described? Do you have any suggests to improve it or suggestions for a better workaround?
profile picture

Cone

#10
Until someone comes up with a better plan, it sounds like it will work. If you create a class to store and retrieve the line(s) for given symbol, the solution oculd work practically seamlessly, and you don't even have to be confined to a single time frame as manually-drawn TLs require.
profile picture

Cone

#11
For closure on this thread, here's the solution (in post #16):
http://www.wealth-lab.com/Forum/Posts/Why-TrendlineValue-returns-0-34016/Page/1#179534
profile picture

Eugene

#12
This link has already been on our Wiki FAQ ;)

TrendlineValue can't be accessed.
profile picture

Cone

#13
I know, that's where I got it! ;)