Position Based Criteria Based on SMA
Author: MikeM_Houston
Creation Date: 5/16/2012 1:25 PM
profile picture

MikeM_Houston

#1
Have been using WLP now for several weeks and not having too many issues. Really powerful program and impressed with optimization tools. However, I am having difficulty with simple conditional problem and hoping I can use the strategy wizard or simple script to solve. Tried looking in Wiki and Forums but could not find. Here is my question.

Like to have position based exit strategy as follows:

1. If price > 5% SMA since entry sell when crosses below 200 day EMA
2. If price < 5% SMA since entry sell when 3% below 200 day EMA

Thanks in advance for your help - probably some simple thing I am missing so excuse my ignorance.
profile picture

Cone

#2
It's only simple when you know how to do it :) But as you'll see by my questions, the criteria aren't precisely clear...

1. What happens if price > 5% since entry, but price is already below 200 day EMA? You won't get a "cross below" signal because it is already there.

In both cases, does the "if price ..." condition need to be true at the same time as the second trigger condition? Or is the first condition a setup that needs only to be true once before acting on the trigger.
profile picture

MikeM_Houston

#3
Sorry for the confusion. I am trying to code a strategy published by Mike Sincere in Aug 17, 2009 issue of Fidelity Trading Strategies. It is method due to Tom Lydon using 200 day MA. (See description below for more detail). It is a decision tree problem. One monitors the price relative to the 200 day SMA since entering the trade. As long as price has been below the (SMA + 5% or 1.05*SMA) you use the the SMA - 3% or 0.97*SMA as the exit point. However if the price ever goes equal or above the (SMA + 5% or 1.05*SMA) you use the SMA as the exit point.

---------------------------------
ETF Trading: Tested Strategies
Ideas for how to make the most of your trades


By Mike Sincere
August 17, 2009

In today’s competitive trading environment, everyone is looking for a strategy that gives them a competitive advantage.  Lots of traders are using the variety and liquidity of exchange traded funds (ETFs) to execute their ideas. Here are some options that have shown strong results in backtesting. There’s no assurance the strategy will perform the same way in the future — conditions may change — but a successful history is may make these ideas worth your consideration.

Identify and follow ETF trends

According to Tom Lydon, author of The ETF Trend Following Playbook (FT Press, 2009), and president of Global Trends Investments, ETFs provide traders an opportunity to profit by identifying a specific trend.

“One of the simplest ways to identify trends is by using a simple moving average,” he suggests. “There are huge opportunities to take advantage of trends as they develop. The idea is to buy into the momentum as it goes above its trend line. Hopefully, it will be the beginning of a long-term trend.”

The rules for his ETF trend following strategy are straightforward and are based on the exponential moving average (EMA). The EMA calculates the average price of a stock over a given period with more weight placed on recent prices and the most weight given to the most recent price. Here are the trading rules:

1. Buy the ETF the following day after it crosses above its 200-day exponential moving average (EMA) at the market close.
2. If the ETF goes up 5% above the 200-day EMA, use the moving average as the sell point. Therefore, sell when it crosses below the 200-day EMA.
3. Finally, if the position goes below the 200-day EMA prior to it going 5% above the 200-day EMA, then sell the position when it goes 3% below its 200-day EMA.

For this strategy, Lydon only includes ETFs that have at least $50 million in assets. In addition, although he uses the 200-day EMA, a more active trader can use the 50-day or 100-day EMA.
“A 50-day EMA will identify a shorter-term trend,” he says, “with the idea that you buy above the average and sell below it.” He prefers the 200-day EMA because he’s looking for long-term trends.
The disadvantage of the shorter-term EMA is “you are going to have three to four times the amount of trading than the 200-day,” He says. During volatile times, however, Lydon admits that the 50-day works better than the 200-day.

profile picture

Cone

#4
In the code, I want to draw your attention to the " * 3" factor to start the trading loop. You can find a discussion of why this is done in the WealthScript Programming Guide > Indicators > Stability of Indicators

CODE:
Please log in to see this code.
I made the signals "AtMarket" which buys at the open of the next day (bar + 1). You can change the signals to AtClose to execute on "bar", but this type of trade is difficult to do in practice. For discussion, see WealthScript Programming Guide > Programming Trading Strategies > Alerts > How to: Alert for AtClose Signals
profile picture

Eugene

#5
QUOTE:
1. Buy the ETF the following day after it crosses above its 200-day exponential moving average (EMA) at the market close.

I read it as BuyAtClose(bar+1) at first too, but on second look the condition seems ambiguous. What it may really mean is simply "if crossover happened as of close this bar, buy the following day".
profile picture

Cone

#6
I went back and forth on it too, but I think the AtMarket order is the correct interpretation. Anyway, it's easy enough to change the signals to AtClose and retest to see if it makes any significant difference. WLP doesn't support AtClose trade automation and I don't even think Fidelity even supports a MOC order type, again making the mechanics of this trade very difficult.
profile picture

MikeM_Houston

#7
Hi Robert and Eugene,

Thanks for all your help. I found the article a little ambiguous too. I notice that the Lydon ETF site does not have the same rules, so I suspect the Fidelity article tuned the criteria a bit. When I checked with Tom Lydon of ETF Trends he said just use simple 200 day MA cross over plus an 8% stop loss.

Just what I needed in terms of your help. I can get going from here. I will compare the two methods to see what I like.

Mike
profile picture

MikeM_Houston

#8
Have been testing things with code and works just like I wanted it to. If you add code to public strategies might want to modify the EMA period CreateParameter to reflect a 200 day MA. Right now set for 100. One other question. What is reason for the statement at end of code RiskStopLevel = ema[bar] * riskFactor ? I commented this out and didn't seem to make any difference in results.
profile picture

Cone

#9
It makes no difference unless you want to apply the Max Percent Risk sizing method. Put the cursor on RiskStopLevel, strike F1 and look at the QuickRef (From the Editor, F1 brings up the User Guide too, which is annoying when you really just want the QuickRef.)
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).