This Schaff Trend Cycle code is an attempt to recode the same indicator as the one in the platform to be user with simplified creation to build automatic trading strategy through ProOrder or stock screener with ProScreener. Enjoy. Idea and final code come from this discussion: https://www.prorealcode.com/topic/why-cant-use-or-call-some-indicator/
How to use it:
The Schaff Trend Cycle (STC) indicator, invented by Dough Schaff, measures the overbought and oversold market conditions. This is an improved version of the traditional MACD indicator widely used by traders.
The STC works by detecting trends, uses exponential moving averages (EMAs), but includes a cycle to include trends in currency sequences.
The STC indicator combines the MACD with a slow stochastic indicator and provides an early signal to recognize trends.
The STC indicator oscillates between 0 and 100.
Less than 20 readings are considered oversold. Over 80 readings are considered overbought.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//input parameters TCLen = 10 MA1 = 23 MA2 = 50 Once Factor = 0.5 if barindex>MA2 then //{Calculate a MACD Line} XMAC = ExponentialAverage[MA1](Close) - ExponentialAverage[MA2](Close) //{1st Stochastic: Calculate Stochastic of a MACD} Value1 = Lowest[TCLen](XMAC) Value2 = Highest[TCLen](XMAC) - Value1 //{%Fast K of MACD} if Value2 > 0 then Frac1 = ((XMAC - Value1)/Value2) * 100 else Frac1 = Frac1[1] endif //{Smoothed Calculation for % Fast D of MACD} PF = PF[1] + (Factor * (Frac1 - PF[1])) //{2nd Stochastic: DCalculate Stochastic of smoothed Percent Fast D, 'PF', above} Value3 = Lowest[TCLen](PF) Value4 = Highest[TCLen](PF) - Value3 //{% of Fast K of PF} if Value4 > 0 then Frac2 = ((PF - Value3)/Value4) * 100 else Frac2 = Frac2[1] endif //{Smoothed Calculation for %Fast D of PF} PFF = PFF[1] + (Factor * (Frac2 - PFF[1])) endif RETURN PFF, 75 coloured(0,0,255) as "level 75", 25 coloured(0,0,255) as "level 25" |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Merci il lui ressemble bcp
Think this is something we can experiment with in the ‘universal’ strategy along with the Bollinger and RSI2.
https://www.prorealcode.com/prorealtime-trading-strategies/universal-strategy/
Hello Francesco,
thanks for the code. Now I can do backtests on this indicator. I’m testing a weekly strategy and noticed that the parameters which fit most stock indexes do not work with volatile stock markets or commodities. Does every market have a different “cycle”, so you need to fit the indicator to every market (risking overfitting)?
For weekly chart I use:
TCLen = 25
MA1 = 30
MA2 = 60.