Schaff_Trend_Cycletes1

Download script
Schaff_Trend_Cycletes1

This technical tool is designed to identify and visualize market cycles by analyzing the relationship between two different moving averages. Instead of looking at raw price action directly, it focuses on the "momentum" or the gap between short-term and long-term trends to help traders see where the market might be reaching an extreme point or beginning a new trend.

How the Logic Works

The script operates through a multi-step calculation process to smooth out market noise and highlight clear cycles:

1. Measuring the Momentum Gap The tool begins by calculating two distinct moving averages: one that reacts quickly to recent price changes (Short) and one that tracks the broader trend (Long). By subtracting the Long average from the Short average, the script determines the current "momentum." This tells us whether the price is pulling away from its baseline or returning toward it.

2. Identifying Local Highs and Lows To make this data useful, the tool looks at these momentum gaps over a specific set of bars (the Cycle). It identifies the highest point (peak) and the lowest point (trough) reached within that specific timeframe. This allows the tool to determine the relative position of the current price movement compared to the recent past.

3. Normalizing the Data into a Percentage The script converts the raw momentum gap into a percentage scale. By comparing the current gap to the range between the local high and low, it produces a value that helps visualize how "stretched" the market is. This prevents the data from jumping around wildly and keeps it within a readable boundary.

4. Smoothing the Trend Cycle Once the percentage is calculated, the script applies an additional layer of smoothing. It uses a mathematical constant to blend the current value with previous data points. This creates a fluid, wavy line (the Trend Cycle) that makes it much easier for a human observer to see the rhythm of the market without being distracted by minor price fluctuations.

Visual Signals and Alerts

The tool provides automatic visual cues on your chart based on specific intensity thresholds:

  • Overbought Signals: When the smoothed trend cycle drops below the 20 level (indicating a potential transition or low momentum), the script automatically places a Lime Green vertical line on the chart.
  • Oversold Signals: When the smoothed trend cycle rises above the 80 level (indicating high momentum or potential exhaustion), the script places a Red vertical line on the chart.

In summary, this tool acts as a "rhythm detector" for the market. It filters out the noise of daily price movements to show you the underlying waves of the market trend, highlighting specific moments where the trend may be reaching its limit.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
Schaff_Trend_Cycletes1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                          Schaff Trend Cycle.mq4  |
//|                                       Ramdass - Conversion only  |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, FostarFX."
#property  link      "mail: fostar_fx@yahoo.com"

#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 110
#property indicator_buffers 1
#property indicator_color1 DarkOrchid

#property indicator_level2 20
#property indicator_level3 80

//---- input parameters
extern int MAShort=12;
extern int MALong=50;
extern double Cycle=10;
extern int CountBars=300;
//---- buffers
double MA[];
double ST[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexBuffer(0, MA);
   SetIndexBuffer(1, ST);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,DarkOrchid);

//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Schaff Trend Cycle                                               |
//+------------------------------------------------------------------+
int start()
  {
   SetIndexDrawBegin(0,Bars-CountBars+MALong+MAShort+1);
   int shift,u,counted_bars=IndicatorCounted();
   double MCD, LLV, HHV, MA_Short, MA_Long, sum ,prev, smconst;
   int n, i, s;
   bool check_begin=false, check_begin_MA=false;
   double MCD_Arr[100];

   if(Bars<=MALong) return(0);
 if (CountBars==0) CountBars=Bars;
//---- initial zero
   if(counted_bars<MALong+MAShort)
   {
      for(i=1;i<=MALong;i++) MA[Bars-i]=0.0;
      for(i=1;i<=MALong;i++) ST[Bars-i]=0.0;
   }
//----
   shift=CountBars-MALong-1;
//   if(counted_bars>=MALong) shift=Bars-counted_bars-1;
   
   check_begin = false;
   check_begin_MA = false;
   n = 1;
   s = 1;
   smconst = 2 / (1 + Cycle/2);

   while(shift>=0)
     {
   MA_Short = iMA(NULL,0,MAShort,0, MODE_EMA, PRICE_TYPICAL, shift);
	MA_Long = iMA(NULL,0,MALong,0, MODE_EMA, PRICE_TYPICAL, shift);
	MCD_Arr[n] = MA_Short - MA_Long;
	MCD = MA_Short - MA_Long;

	if (n >= Cycle)  
	{	
		n = 1; check_begin = true;	} else {n = n + 1;}
	
	if (check_begin)  
	{
		for (i = 1; i<=Cycle; i++)
		{	
			if (i == 1) {LLV = MCD_Arr[i];}
			else {
				if (LLV > MCD_Arr[i]) LLV = MCD_Arr[i];
			}
			
			if (i == 1) {HHV = MCD_Arr[i];}
			else {
				if (HHV < MCD_Arr[i]) HHV = MCD_Arr[i];
			}					
		}
		ST[shift] = ((MCD - LLV)/(HHV - LLV))*100 + 0.01;
		s = s + 1;
		if (s >= (Cycle)/2)
		{ 
			s = 1;
			check_begin_MA = true;
		}
	}	else {ST[shift] = 0;}
	if (check_begin_MA) {	
		prev = MA[shift + 1];
		MA[shift] = smconst * (ST[shift] - prev) + prev;	}
      if (MA[shift]>20 && MA[shift+1]<20)
      {            
            ObjectCreate("vline1"+Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet("vline1"+Time[shift], OBJPROP_WIDTH,3);
            ObjectSet("vline1"+Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet("vline1"+Time[shift], OBJPROP_COLOR, LimeGreen);
         }          
         if (MA[shift+1]>80 && MA[shift]<80)
      {            
            ObjectCreate("vline2"+Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet("vline2"+Time[shift], OBJPROP_WIDTH,3);
            ObjectSet("vline2"+Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet("vline2"+Time[shift], OBJPROP_COLOR, Red);
            
         }            
      Comment( MA[shift],MA[shift+1]);
      shift--;
      
     }

   return(0);
  }
//+------------------------------------------------------------------+

Comments