- ago
I'm working on a rotation momentum strategy for SPDR Sector ETFs that needs a regime filter - only buy the if the SPY (Regime) is above the 50-day SMA.

I haven't found how to do that. I've looked at adding a Condition but I haven't found one that looks appropriate. Can anyone help?
0
363
4 Replies

Reply

Bookmark

Sort
- ago
#1
I don't know how to do this with Blocks, although I'm sure it can be easily done. But using C# code, this is how you can Buy a stock when SPY is above its 50-day SMA. You can also use a crossover trigger (instead of an inequality as shown). Study the IF statements below.

This strategy doesn't make any money because none of the Buy/Sell conditions in the IF statements are a function of what the stock itself is doing. You can add that.
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript3 {    public class MyStrategy : UserStrategyBase    {       BarHistory sp500;       IndicatorBase sma50;       public override void Initialize(BarHistory bars)       {          sp500 = GetHistory(bars, "SPY");          sma50 = SMA.Series(sp500.Close, 50);          PlotTimeSeriesCloud(sp500.Close, sma50, "SPY and its SMA50", "SPY", WLColor.Orange, WLColor.YellowGreen);       }       public override void Execute(BarHistory bars, int idx)       {          if (HasOpenPosition(bars, PositionType.Long))          {             //sell conditions below             if (sp500[idx] < sma50[idx])                PlaceTrade(bars, TransactionType.Sell, OrderType.Market,0.0, "<sma50 Sell");                }          else          {             //buy conditions below             if (sp500[idx] > sma50[idx])                PlaceTrade(bars, TransactionType.Buy, OrderType.Market,0.0, ">sma50 Buy");          }       }    } }
If you are new to WealthLab, I would start with one of the sample strategies that work, then play with it until you get what you want. But build from an existing strategy so you get going immediately.
0
- ago
#2
Thanks for the suggestion.

You guessed it .... I'm new to WealthLab. I'm familiar with ETFreplay but new to WealthLab. I'll start looking at the existing and sample strategies built into WealthLab and see if there is anything like what I want.
0
Cone8
 ( 12.18% )
- ago
#3
Here are the 2 ways to do it in Blocks. Just add your other conditions.



For a Rotation strategy, just put that in Additional conditions on the right side.



For more questions, try asking the WL AI Help Assistant - just hit F1.
0
- ago
#4
Cone, thanks for your answer. It helped a lot.

I also found an extensive instruction on how to do it in Lesson 5 starting @ minute 19:30 of the WealthLab University channel on YouTube. It also is a really good tutorial on Conditions and Qualifiers.
1

Reply

Bookmark

Sort