Schaff Trend Cycletest1

Download script
Schaff Trend Cycletest1

This tool is designed to help traders visualize market cycles and identify potential turning points by analyzing the relationship between short-term and long-term price trends. Instead of looking at raw price movements, it converts complex market data into a normalized cycle that oscillates within a specific range.

How the Logic Works

1. Trend Identification The script begins by calculating two different types of moving averages: a "Short" average (which reacts quickly to price changes) and a "Long" average (which follows the broader trend). By subtracting the long average from the short average, the tool determines the "distance" or momentum between current market speed and historical movement.

2. Cycle Normalization To make this data easier to read, the script groups these movements into specific time windows (cycles). It identifies the highest and lowest values reached during each cycle. It then calculates where the current price sits relative to those highs and lows, expressing the result as a percentage. This creates a wave-like movement that fluctuates between levels, similar to how a pendulum swings.

3. Smoothing the Data Because raw market cycles can be jagged and "noisy," the script applies a secondary smoothing process. It takes the cycle data and averages it out over time, resulting in a cleaner, more fluid line. This helps traders see the core direction of the market trend without being distracted by minor, insignificant price flickers.

4. Visual Signals The logic concludes by monitoring specific threshold levels (set at 20 and 80) to provide clear visual cues on the chart:

  • Overbought Conditions: When the smoothed cycle line rises above the upper threshold (80), the script places a Red vertical line, suggesting that the market may be stretched to the upside.
  • Oversold Conditions: When the smoothed cycle line falls below the lower threshold (20), the script places a Lime Green vertical line, suggesting that the market may be stretched to the downside.

Summary for the User

Essentially, this tool filters out the "noise" of the market to show you the underlying rhythm of price cycles. It tells you when the current move is becoming extreme compared to recent history, helping you identify potential areas where a trend might be losing steam or reaching an exhausted state.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Schaff Trend Cycletest1
/*-----------------------------+
|			       |
| 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(Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet(Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet(Time[shift], OBJPROP_COLOR, LimeGreen);
         }          
         if (MA[shift]>80 && MA[shift+1]<80)
      {            
            ObjectCreate(Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet(Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet(Time[shift], OBJPROP_COLOR, Red);
            
         }            
      Comment( MA[shift],MA[shift+1]);
      shift--;
      
     }

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

Comments