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.
//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"