Schaff_Trend_CycletesX

Download script
Schaff_Trend_CycletesX

This tool is designed to help traders identify and visualize cyclical trends in the financial markets by smoothing out market "noise" and highlighting significant momentum shifts. Instead of looking at raw price action, which can be volatile and confusing, this script processes price data into a readable percentage-based oscillator.

How the Logic Works

1. Trend Identification (The Foundation) The logic begins by comparing two different types of moving averages: a "Short-term" average and a "Long-term" average. By calculating the difference between these two, the script determines the current direction of the market's momentum. If the short-term average is significantly higher than the long-term average, the market is showing upward strength; if it is lower, the market is showing downward weakness.

2. Cyclical Normalization (The Oscillator) Rather than simply showing a raw number, the script looks at these differences over a specific "Cycle" period. It identifies the highest peak and the lowest valley within that cycle and translates the current momentum into a percentage between 0 and 100. This creates an oscillator that allows you to see where the market stands relative to its recent highs and lows.

3. Smoothing and Stability To prevent the indicator from jumping erratically with every minor price tick, the script applies a smoothing mathematical constant. This ensures that the resulting line movesFluidly, allowing traders to observe the "flow" of the trend rather than getting distracted by temporary spikes.

4. Visual Alerts and Signal Thresholds The script identifies two critical levels for the trader: 20 and 80. It is programmed to automatically place visual markers (vertical lines) on your chart when the indicator crosses these boundaries:

  • Green Vertical Lines: These appear when the smoothed trend line moves above the 20 level, potentially signaling a shift into stronger upward momentum.
  • Red Vertical Lines: These appear when the smoothed trend line moves above the 80 level, which can indicate that the trend is reaching an overextended state or a potential peak.

Summary for the Trader

In simple terms, this script takes complex price movements and simplifies them into a single flowing line. It tells you where the market is heading by looking at the gap between short-term and long-term trends, then highlights the most important "turning points" with color-coded lines so you can spot potential entries or exits more clearly.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Schaff_Trend_CycletesX
/*-----------------------------+
|			       |
| 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_STYLE, STYLE_SOLID);
            ObjectSet("vline1"+Time[shift], OBJPROP_COLOR, LimeGreen);
         }          
         if (MA[shift]>80 && MA[shift+1]<80)
      {            
            ObjectCreate("vline2"+Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            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