Buy and Sell if Price moves above or below 50/100 MA in Rules
Author: fid2020
Creation Date: 6/7/2020 10:50 PM
profile picture

fid2020

#1
Having trouble using rules for trading. Here's what I want to test.
Buy if MA moves above 50ma or 100ma
Sell if ma Moves below either 50ma or 100ma

Here's how I setup the rules.
Buy @ close
• Price crosses above 50ma
• Price crosses above 100ma
Sell @ close
• Price crosses below 50ma
• Or divider
• Price crosses below 100ma

I must have setup the rules wrong because it doesn't work. For example, I ran the strategy for 5 years on SPY. The following are dates that I think should have been buys and sells. But the trades doesn't find them.
3-11-16 Buy
5-18-16 Sell
7-1-16 Buy
9-12-16 Sell
2-11-19 Buy
5-31-19 Sell

Can anyone help me with my rules errors?
profile picture

Eugene

#2
Hi,

Your thinking is not correct here. The price did not cross both MAs neither on 3-11-16 nor or 5-06-16 and so on. It only crossed one MA e.g. the 100ma (while the 50ma stayed below) on 3-11-16, then the 50ma (vice versa) on 5-06-16 etc. Just take a careful look on the chart and give this a thought.

Crossing both MAs together by a price on the same bar can happen if these MAs are set tightly or if there's a wide range bar. It's sort of a rare event - take 06-24-16 for example when the price broke down through 50ma and closed below 100ma.

Apparently you might want to have the OR divider added to your Buy rule, too?

P.S. Since AtClose orders do not produce Alerts in a Wealth-Lab Strategy, I'd recommend their AtMarket equivalents here.
profile picture

fid2020

#3
This is all new to me since I only started using the program a week ago. Thanks for your quick response and I appreciate your suggestions.

My intent is not for buy signal to occur by crossing both MAs on the same bar. What I want is the buy signal to occur whenever both MAs are crossed, regardless of the lag time in the crossings. For example, 50ma could be crossed on say, 3-11 but the 100ma crosses on 4-3. I want the buy signal to occur on 4-3 since the price is now above both MAs. Can I do that with the rules?

Also, is the sell rule OK? I want to sell if price falls below either MA.

What happens when price falls below either MA and then reverses to go back above the same MA? Does that generate a buy signal?

Again, thanks for your help, Eugene.

Martin
profile picture

Eugene

#4
You're welcome Martin.

QUOTE:
My intent is not for buy signal to occur by crossing both MAs on the same bar. What I want is the buy signal to occur whenever both MAs are crossed, regardless of the lag time in the crossings. For example, 50ma could be crossed on say, 3-11 but the 100ma crosses on 4-3. I want the buy signal to occur on 4-3 since the price is now above both MAs. Can I do that with the rules?

Yes you can. All conditions imply that events take place on the current bar. The "fuzzy logic" rules which you want to implement can only be accomplished with the help of a special condition called Multi-Condition Group (nearby "OR Divider"). MC Group provides a way to combine conditions that aren't required to occur simultaneously but within some lookback period. Make sure to have read the WL User Guide on this subject for guidance (Strategy Window > Strategy Builder > MC, Multi-Condition Group).

QUOTE:
Also, is the sell rule OK? I want to sell if price falls below either MA.

Yes.
profile picture

fid2020

#5
Thanks again. You have given me a lot to think about and absorb.
profile picture

Eugene

#6
My pleasure.
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).