I have a simple strategy (written in C code) but I have been unable to find existing tS code that does the same thing. I also wasted many hours with chatGPT trying to get it converted properly (too many debugging errors in ToS and a comedy of errors in the chat transcripts). I would like to (learn how to ) create and backtest this strategy and I want to stay on ToS so I am looking for help to make this simple strategy work on ToS platform.
If the close in SPY is less than the close of 80 periods ago (stocks in downtrend), I am looking for a mean reversion trade.
I buy SPY when the 6-day EMA crosses below the 5-day SMA.
I sell SPY and buy TLT when the EMA crosses above the SMA.
If the close in SPY is higher than the close of 80 periods ago, I am looking for a mean reversion trade. The "fast" EMA will be somewhere near the current SPY price.
No sell signal can be generated until the "fast" EMA is below the 80-period price of SPY; that's when the trend is considered over, and the mean reversion trades begin.
I have a couple versions of chatGPT-produced code that will compile(?) but they would keep me perpetually in a trade, either SPY or TLT, never in a neutral state.
Is it okay to post the C code here to ask for help converting to thinkScript and making it backtest-ready?
If the close in SPY is less than the close of 80 periods ago (stocks in downtrend), I am looking for a mean reversion trade.
I buy SPY when the 6-day EMA crosses below the 5-day SMA.
I sell SPY and buy TLT when the EMA crosses above the SMA.
If the close in SPY is higher than the close of 80 periods ago, I am looking for a mean reversion trade. The "fast" EMA will be somewhere near the current SPY price.
No sell signal can be generated until the "fast" EMA is below the 80-period price of SPY; that's when the trend is considered over, and the mean reversion trades begin.
I have a couple versions of chatGPT-produced code that will compile(?) but they would keep me perpetually in a trade, either SPY or TLT, never in a neutral state.
Is it okay to post the C code here to ask for help converting to thinkScript and making it backtest-ready?