Author: rij1127
Creation Date: 1/21/2014 2:56 PM

#### rij1127

#1
Hello. I've got 2 interesting trading strategies that I'd like to back test.
I'm not a programmer and the elements that I need are beyond the drop-down menu.

If you've got some time/interest, please let me know.

Thanks,
Rich

#### Eugene

#2
Hi Richard,

If you could post here the rules of your strategies, maybe we could help you out with the code?

#### rij1127

#3
Hi Eugene,

Thanks re: help. Here's the first strategy:
1. Create a basket of stocks/ETF's (i.e. 10 stocks)
2. Select an original investment \$\$ amount (i.e., \$100,000)
3. Equally allocate a \$ amount into each (i.e.., \$10,000)
4a.. Assign a trailing stop loss to each (i.e., 5% trailing stop loss).
5. When a stock stops, the cash proceeds are reinvested equally across ALL 10 stocks (including the one stopped out of).

4b. After running the first test, use a moving average condition rather than the trailing stop (i.e. 5-day MA crosses the 20-day MA)
4c. After running the first two, trying BOTH 4a. AND 4b. (i.e., trailing stop loss AND moving average cross

Variables to test:
- % stop loss (i.e., 2%, 5%, 8%)
- variable stop losses per security based on the underlying volatility of that security (i.e., tech has 8% stop vs consumer services 3% stop)
- cash holding period / when to reinvest (i.e., immediate, 1-day, 1-week, 2-weeks, 4-weeks)

Please let me know if you have any questions.

#### Eugene

#4
#5 In other words, you re-enter same stock and create 9 more positions - so the strategy is always invested (assuming holding period = immediate)?

#### rij1127

#5
Correct. So, if the 1 stock stopped out of yielded \$9000 of cash, then you would purchase \$900 of each of the original 10 stocks. If the leading stock at that point was worth \$14,000, it would grow to \$14,900; and the stock just stopped out of would have a value of \$900.

Assume \$8.00 trading costs in and out of each stock.

#### Eugene

#6
Here's my take at your constant readjustment. Wealth-Lab is Position-based, so you can't simply "adjust" the total position in a stock. If you would be creating 10 more positions, you'd end up with thousands 1-share sized positions very soon. One workaround used by the strategy is to exit all positions on a trailing exit event in a single stock, and re-enter them all at once:

CODE:

#### rij1127

#7
Thank you. The code is all Greek to me. With the workaround you suggested of a stop event selling ALL positions, does it purchase ALL 10 with the existing value before the stop + the (value of the stock that triggered the stop / n)?

How do I use the code to actually plug in stock symbols and run it using intraday data for 7 (or as many as available) years.

The first simple test I'd like to run has just two symbols: SPY and SH. These are the long and short symbols for the S&P index, using a 5% trailing stop loss. Here's a simple spreadsheet version if the market went straight up 20%: https://docs.google.com/spreadsheet/ccc?key=0Ahj6H_OJvcAsdDM3T3VmeDV6UzVpcjV0NnFOMTFvYWc&usp=sharing.

Rich

#### Eugene

#8
QUOTE:
With the workaround you suggested of a stop event selling ALL positions, does it purchase ALL 10 with the existing value before the stop + the (value of the stock that triggered the stop / n)?

If you choose Percent Equity = 10%, the equity will be reinvested at 10% equity per new position. I assume this is what you wanted.

With MS123 PosSizer Library, more flexibility is possible with the No Profit/Loss Sharing PosSizer that models maintaining a symbol's own allocation.

#### rij1127

#9
yes... Percent Equity = 10%
is it possible for you and me to speak on the phone?

#### Eugene

#10
QUOTE:
is it possible for you and me to speak on the phone?

No.

#### rij1127

#11
do you have enough info to run the test?

#### Eugene

#12
Richard,

Let's make it clear, since I even had to remove your pushy "bump up" post made just two hours after reply #9 - and now comes the phone and running some tests for you.

Although writing custom code is not part of the support deal, as a rule we try to help the user. However, please note that we technicians are used to support a lot of Wealth-Lab users seven days a week and to work on different projects. We can not dedicate time and resources to single-user solutions, let alone making phone calls and/or doing what in fact is user's job etc.

So, I'm sure that Wealth-Lab's versatility allows to run any tests on your own -- this is probably why you've chosen the platform, right? If you have questions re: learning the basics of Wealth-Lab, please feel free to ask us on the forums.

#### rij1127

#13
Is there a way to use the forum to HIRE someone to write the tests?

#14
The above code peeks into the future, since the trailing stop result is known at bar+1 (Tomorrow), but it is performing an ExitAtClose at bar (Today). Wish I could trade under those conditions!

CODE: