Snapping Tortoise Rotation
Author: MikeyRules
Creation Date: 5/26/2009 10:12 AM
profile picture

MikeyRules

#1
Hello,

I took the Dogs of the Dow and the RSI symbol rotation scripts and altered them for my use. I seemed to have run into an exit issue that I am hoping someone could help with.

I look at a universe of stocks (e.g., Dow 30) and want to find the 5 stocks in the universe that are the farthest away from the 10 day Highest High. Once I have them, I want to buy them at the open (Market) the next day. I want to have two stops - the first is the low of the bar the day before the entry bar and the other is a profit stop that is a certain amount above the entry.

When I run this script on a single symbol in the Dow 30 data set I have created (e.g., AA), I get one result. When I run it on the next symbol (e.g., AXP), I get a different set of results. Based on my debugging, I believe I have narrowed it down to the initial exit that tries to use the Low of the bar before the entry. I am guessing that due to how WL processes this script I am getting a Low that changes based on which symbol I am selecting, but am not sure. Any insight here would be greatly appreciated.

If that is the case, I would like to try to figure out how I can use the low of the day before the entry bar as my initial stop. Thanks in advance!

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

Eugene

#2
Probably the problem here is because of trying to access a different symbol's Low:
CODE:
Please log in to see this code.

If you want to use the Bars object of a specific Position and not peek into the future, try this:
CODE:
Please log in to see this code.


A couple of notes:

1 - This will always return a fixed data series.
CODE:
Please log in to see this code.

Accordingly, private DataSeries PainCalc is affected.
Should be:
CODE:
Please log in to see this code.

2 - Your order of exits is not pessimistic enough, I'd suggest revisting the Programming Guide, Programming Trading Strategies > Peeking and using this sequence:
CODE:
Please log in to see this code.

3 - Keep statements like this outside of the loops: double iStop = 2.00;
profile picture

MikeyRules

#3
Thanks Eugene, I appreciate your help.

In your notes section, could you please explain further? I am not sure I understand. What I am trying to do is evaluate each symbol within the universe/data set, find its Highest High for the last ten days, then take the close of today, subtract the Highest High and then divide that sum by the Highest High. One I have that for each symbol in the data set, I want to find the 5 with the lowest value so I can then buy them. I am not clear on the GetExternalSymbol line as I thought we were evaluating each symbol within the data set.

Note 2 - thanks, will fix the order

Note 3 - that will be a variable based on the low of the position when the code is finalized so I think it needs to be in the loop. I made it a fixed amount for this testing.

profile picture

Eugene

#4
In private DataSeries HHten, you have a parameter string symbol which is simply not being used. I was just analyzing the syntax. From your explanation, it looks like that you don't need that input parameter.
profile picture

ss161

#5
i took a stab at getting your code to work as i've recently written a few symbol rotation scripts. i think what i did works, but i'd suggest assuming i made a mistake somewhere and checking it carefully. anyway, my own strategy in creating symbol rotation scripts is to create two lists (actually a list within a list). the higher order list is organized by date and contains the current date, bar, and then the list of data for that day. once all the data is added into the list, i sort by date, and then for each day, i sort by the buy / sell criteria for that day and then apply my trading logic for each day.

here is that style code applied to your script, again, i didn't test it too closely.
CODE:
Please log in to see this code.

profile picture

Eugene

#6
Hi Steve,

Nice design pattern. Re: this line --
CODE:
Please log in to see this code.

You can as well skip setting context to this symbol by commenting the line (and the RestoreContext line below) and instead let WL5 sort it all out:
CODE:
Please log in to see this code.

The outcome is going to be the same.
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).