Author: Leeroy
Creation Date: 3/12/2010 2:35 AM

#### Leeroy

#1
Eugene, good morning. Thanks again for your help with the ETF Primary/Inverse Rotation algorithm. I'm trying to develop another algorithm with yet another continuous loop process where a stock is sold using a Trailing Stop Loss % (% with an X value) and repurchased with a market order when the stock subsequently shows a trailing improvement of a % Y value....and this process would be continuous. Big picture a stock is doing well, but then the market goes down and the stock is sold using the trailing stop % (x value). Eventually the stock market & stock start to improve from the lows by a % Y of the stock and the stock is repurchased using a market order buy. Then the process would start all over again. Since this is a continuous loop, an initial concern is getting the algorithm started before the continuous loop starts, especially depending on the history data used. Clear as mud.

#### Eugene

#2
Hello Michael,

1. What exactly is the difference from this code?

Primary & Inverse ETF Rotation via Trailing Stop Loss (Dollars); Riding the Ups & Downs

2. Have you already tried coding/modifying it, i.e. what is the problem?

#### Leeroy

#3
1) There are several important differences. The ETF rotation switches back and forth continuously depending on the bear/bullness of the market. This new algorithm is only a single stock with a trailing stop loss (% x value) safety feature to exit the market when it goes down. Once the market and stock start to pick up again by a trailing % (% y value of stock), then the stock is repurchased with a market order. There are several differences: 1 stock instead of rotation back and forth between two ETFs, and the biggest difference, the monitoring of the stock for it to improve by Y % to trigger a market buy...Then continuous loop.

2) From the below code (first shot/ rough draft), problem (1) monitoring of the stock for it to improve by Y % to trigger a market buy & problem (2) maintaining a continuous loop.

#4
CODE:

#### Eugene

#5
Cam you rephrase the terms "improvement of a % Y value" or "pick up again by a trailing %"? What does it mean exactly? "Improve" relative to what - the last Position's exit price? some local low? etc.

#### Leeroy

#6
Let's say a stock that is worth a \$100 with a trailing stop loss%(x=3%) dips to \$97 and sells. The stock continues to descend to \$90 dollars but then improves by %1 (Y = 1%). 1% * \$90 = \$.9 Then the stock would be purchased with a market order buy at \$90 + \$.9 = \$90.9 Then the process would start all over again. Ideally the stock would continue to rise and then when it descended x=3%, the stock would be sold using the trailig stop loss%, and purchased again once the stock started to improve again by 1%....and be continuous.

#### Eugene

#7
Sounds very similar to what I was coding last month:

WSJ "Common Sense" Strategy

#### Leeroy

#8
Similar though there are differences. Instead of "BUY on 10% declines / SELL on 25% increases," the strategy I suggest sells with the trailing stop loss X% and buys whenever the stock shows an improvement of Y%, then starts the process all over again (continuous process).

Second shot/ rough draft:

CODE:

This code submitted before looking at the below code.

#### Eugene

#9
QUOTE:
Then the stock would be purchased with a market order buy at \$90 + \$.9 = \$90.9

This would be a stop order. Market order does not fit in here.
QUOTE:
the trailing stop loss X% and buys whenever the stock shows an improvement of Y%, then starts the process all over again (continuous process).

Here's something for you to start with. There may be omissions, so feel free to modify:
CODE:

#### Leeroy

#10
And that is how babies are made.

Thanks Eugene! I'm away from WealthPro, but I'll be able to try the code later on.

#### Leeroy

#11
Simulation runs well but running into similar problems as the ETF Rotation Strategy when running it in the minutes scale in the real time market using the Strategy Monitor/Orders. I'll try a greater scale than the minutes because it is probably having trouble with the amount of data. However at a greater time scale, the strategy won't be as effective if there are large market changes in the real time market, right? The Strategy Monitor says stock symbol is "updating" but never advances beyond that.
Range: Tried starting with a date in the past as well as using today's date
Scale: Minutes
Capital: 75% of paper account

The ETF Rotation Strategy requires an extensive amount of trades, which I thought was the problem. This strategy is not nearly as trade intensive so I was hoping I wouldn't have the same problems.

#### Eugene

#12
Please see Strategy Monitor > Employment Notes > Data Updates in the User Guide.

#### Leeroy

#13
Eugene, for the below mentioned reasons & setting, would you be willing to run this strategy at the 1 minute scale to see if you are able to get the strategy to start/work during the active market?

Per the employment notes, (1) I perform a static data update each day, (2) I set the Data Range to load only the data that I need, & (3) I limit the number of symbols (to 1 symbol). Even so, at the 1 minute and 5 minute scales, I get a continuous "Updating" the stock under the Action column in the Strategy Monitor, which never clears, updates, or starts the strategy. I had the same problem with the ETF Rotation strategy. Given the sensitive nature of this Trailing Stop Loss Strategy (and the ETF Rotation Strategy), 10 minute and greater scales render these strategies largely ineffectual.

Settings
Account: Paper Account
Data Range: Today's date or a day before
Position Size: 75% of equity
Scale: 1 minute or 5 minutes gives a continuous "Updating" the stock

#### Leeroy

#14
I tried running the program again today during the market real time with the 10 minute scale but nothing happened. Maybe it thought I already had a position since I used a data range that started yesterday(17 Mar)?

Settings
Account: Paper Account
Data Range: 17 Mar (yesterday) to today
Position Size: 75% of equity
Scale: 10 minute

#### Eugene

#15
With which parameters? By default, I left them at 25% and 10%.

#### Leeroy

#16
I ran them at 3.5% and 1%.

I've run the program during the market day using a data range of the current day, and the strategy didn't do anything.

Settings
Account: Paper Account
Data Range: current day
Position Size: 75% of equity
Scale: 10 minute

#### Eugene

#17
The Strategy only requires 2 bars of data to establish its first position, so it should have bought at bar 2. Strategy Monitor and paper trading aside, does it buy in Strategy Window? If not, is there a skipped trade (Trades tab > status bar)?

#### Leeroy

#18
It's strange. It works fine using the simulation/ Strategy Window...no skipped trades. But trying to run it in real time (Strategy Monitor/ paper trading), and nothing happens.

#### Leeroy

#19
Any thoughts/recommendations on how to proceed?

#### Cone

#20
Sorry I didn't see the previous post, but there's a known, but intermittent, bug in the Strategy Monitor that doesn't Stage/Place Alerts consistently. Could that be what you're experiencing?
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).