Buy specific ETFs

Hi

Would anyone be able to help with selecting a specific ETF to buy according to certain rules? e.g. lets say i would like to have the buy rules saying “if the SP500 is above its 200-day MA, then invest 50% in SPY and 50% in QQQ. Instead, if the SP500 is below its MA, then invest in TLT”

I have tried to select the appropriate buy rules but am struggling with the ETF selection

Many thanks
Matteo

One way is to set your benchmark to SP500, then use a buy rule something like:

eval(close(0,#Bench)>sma(200,0,#Bench ), Ticker(“SPY,QQQ”) , Ticker(“TLT”) )

and sell rules something like:

Ticker(“SPY,QQQ”) & close(0,#Bench)<sma(200,0,#Bench)
Ticker(“TLT”) & close(0,#Bench)>sma(200,0,#Bench)

Thanks for the suggestion!

If a function takes a series parameter then you can specify that series with GetSeries:

Eval(Close(0,GetSeries("SPY"))>SMA(200,0,GetSeries("SPY")),Ticker("SPY,QQQ"),Ticker("TLT"))

The main improvement here is that it won’t be tied to the benchmark. In fact this sort of thing will work in a stock strategy as well:

Eval(Close(0,GetSeries("SPY"))>SMA(200,0,GetSeries("SPY")),Ticker("IBM,MSFT"),Ticker("C"))

Thank you! I have tried to implement this but it seems like with the eval function the allocation to the security is c. 50% of the portfolio. How could this be changed to 100% i.e. I would like to have either 100% in SPY or 100% in TLT, depending on the SMA