Francesco

Schaff Trend Cycle

Category: Indicators By: Francesco Created: August 3, 2017, 8:30 AM
August 3, 2017, 8:30 AM
Indicators
3 Comments
Schaff Trend Cycle

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"

 

Download
Filename: Schaff-trend-cycle-open-source.itf
Downloads: 570
Download
Filename: schaff-trend-cycle-prorealtime-code.png
Downloads: 121
Francesco
Francesco Average
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
Author’s Profile

Comments

ggolfet
9 years ago
#

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.

juanj
9 years ago
#

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/

oraclus
9 years ago
#

Merci il lui ressemble bcp

ProRealCode ProRealCode
Loading...