QQQ mean reversion coding question

Hey there. Looking to replicate a QQQ trading system from @QuantpT on Twitter. Basically the rules are…

Buy if QQQ

SMA(50) > SMA(125) &
ROC(5) < 0 for each of the last 5 days &
ROC(5) close < ROC(5) yesterday’s close

Sell if RSI(2) > 70

I’m getting a worse result than the author who runs the system on Amibroker and I wonder if my code is correct for summing the number of consecutive days with the ROC(5) < 0. His system may be selling the close with RSI(2) > 70 which I don’t think I can replicate here?

LoopSum(“ROC(5,0) < 0”, 5) = 5

Buy rules:
SMA(50) > SMA(125)
LoopMin(“ROC(5,Ctr)”,5) < 0
ROC(5) < ROC(5,1)

Sell rule:
RSI(2) > 70

Results are pretty nice overall - https://www.portfolio123.com/port_summary.jsp?portid=1664925 - but not in the last ten years.

It seems to me that;

LoopMin("ROC(5,Ctr)",5) < 0

should be



Yes, you’re right. Either that or LoopMax(“ROC(5,Ctr)”,5) < 0. Sorry about the error, and thanks for the catch!

Results with TLT when model is not in QQQ are good. Annualized return= 17% from 2000 to 2021. Max D/D= -23%

Ideal Number of Positions = 2
Reconstitution & Rebalancing Frequency = Daily
Position Weight Formula : 9.99ticker(“QQQ”)+0.01ticker(“TLT”)

ticker(“QQQ”) & SMA(50)>SMA(125) & LoopSum(“ROC(5,Ctr)<0”,5)=5 & ROC(5)<ROC(5,1) | ticker(“TLT”)

Sell: ticker(“QQQ”) & rsi(2) > 70

Thank you all for your help. My next question was going to be how to buy IEF when not in QQQ. Georg is in my head!

Shawn, you need to use the Position Weight Formula :
99.99ticker(“QQQ”) + 0.01ticker(“IEF”)

Ideal Number of Positions=2

IEF is never sold. So when model is not in QQQ it is in 100% IEF.

Roger that. TY. I only have the simulation level sub, so it won’t let me use position weighting, but I appreciate the result with TLT. My image was that the low exposure to equities would give a decent result if we allocate to treasuries when out of the market… I don’t suppose there is a way to run this without the simulation level subscription?

I’d like to run it with a basket of bonds when not in QQQ using trend following to pick duration.