Custom Formula Ratio and SMA of Custom Ratio

I am fairly new to the platform and trying to mimic some ETF rotational idea I read about in order to get my hands dirty and am having trouble computing one main thing:

The strategy uses regime switching between "risk on" ETFs and "risk off" ETFs (like bond ETFs etc) by tracking the ratio between SPY and 3 low risk ETFs but let's just say IEF for now. Then It takes the 100 day moving average of that ratio. If the ratio is above it's own SMA, it's risk on and if it's below, risk off.

I realized you can't use standard functions like SMA on "$" custom formulas. I confirmed in Excel that I calculated the ratio correctly at least for the present day:

$ratio1: Close(0,GetSeries("SPY"))/Close(0,GetSeries("IEF"))
or??
$ratio2: Close(CTR,GetSeries("SPY"))/Close(CTR,GetSeries("IEF"))

But can't figure out in the documentation what this "CTR" thing means and whether I should be using "CTR" in place of "0".

My attempt at creating a 100 day moving average of this ratio is as follows which does not throw any error messages but sometimes throws NAs in the Screener output depending on which day of this month I select for the Screen:

ratioSMA1: LoopAvg("$ratio1",100)
or??
ratioSMA2: LoopAvg("$ratio2",100)

I'm sure I'm missing something here... Thanks!

Here's what I was trying to try out in P123. Again, not a huge deal. Was just using it to learn how to use P123.

https://seekingalpha.com/article/4288317-etf-rotation-strategy-to-outperform-market

ratioSMA2 is the right form. Under the Fundamental chart, this looked right;

LoopAvg(`Close(CTR,GetSeries("SPY"))/Close(CTR,GetSeries("IEF"))`,100)

CTR is described here;
https://www.portfolio123.com/doc/doc_detail.jsp?factor=LoopAvg

1 Like

I experimented with this some more and I thought your use of the GRAVE " ` " characters (secondary use of the tilda key). I thought you mistakenly used those but then your formula worked. Do you know when you use the grave character as opposed to " "? Is it when you have quotes inside of quotes?
Thanks!

Yes, it's when you have quotes inside of quotes.

1 Like