Schaff_Trend_Cycle2Test

Download script
Schaff_Trend_Cycle2Test

This script is designed to provide traders with a visual representation of market momentum and trend cycles. Rather than showing the raw price of an asset, it focuses on calculating the underlying "rhythm" of the market to help identify potential turning points and overextended conditions.

Core Logic Overview

The tool operates by analyzing the relationship between two different types of moving averages: a fast-moving average (which reacts quickly to price changes) and a slow-moving average (which tracks the broader trend). By calculating the difference between these two, the script identifies the "momentum" of the market.

How the Data is Processed

To turn this raw momentum data into a usable visual signal, the script performs several layers of calculation:

  • Cycle Analysis: The logic groups the price movement into specific cycles. Within each cycle, it identifies the highest and lowest points of the momentum.
  • Percentage Scaling: It then measures where the current momentum sits relative to those highs and lows. This converts volatile price movements into a standardized percentage scale (typically ranging between -10 and 110).
  • Smoothing: To prevent the visual output from being too erratic or "noisy," the script applies a smoothing constant. This ensures that the resulting line flows smoothly across the chart, making it easier for a human observer to follow the trend without being distracted by minor price fluctuations.

Visual Signals and Alerts

The primary purpose of this indicator is to provide clear, actionable visual cues on the trading platform:

  • The Trend Line: A smooth, colored line appears in a separate window below the main chart. This allows you to see the "heartbeat" of the market momentum independently of price action.
  • Dynamic Vertical Markers: The script automatically monitors the trend line for specific breakthroughs:
    • Bullish Signals: When the trend line crosses above a lower threshold (Level 20), it places an Aqua-colored vertical line on the chart, highlighting a potential upward shift in momentum.
    • Bearish Signals: When the trend line drops below an upper threshold (Level 80), it places a Yellow vertical line on the chart, signaling a potential downward turn or exhaustion in the current move.

Summary for the Trader

In essence, this script filters out the "noise" of constant price ticks to reveal the larger cyclical movements of the market. It automates the difficult task of spotting when a trend is becoming overextended or when it is beginning to pivot, marking these key moments with distinct vertical lines for quick identification.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Schaff_Trend_Cycle2Test
//+------------------------------------------------------------------+
//|                                          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;
extern double sm = 2;

//---- buffers
double MA[];

string ObjectID = "stc2vline";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//   string short_name;
//---- indicator line
   SetIndexBuffer(0, MA);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,DarkOrchid);

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

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here   
int    obj_total=ObjectsTotal(OBJ_VLINE);
  string name;
  for(int i=obj_total-1;i>=0;i--)
    {
     name=ObjectName(i);
     if (StringFind(name,ObjectID, 0) >= 0) ObjectDelete(name);
     
    }
//----
   return(0);
}
  
  
//+------------------------------------------------------------------+
//| Schaff Trend Cycle                                               |
//+------------------------------------------------------------------+
int start()
  {
   SetIndexDrawBegin(0,Bars-CountBars+MALong+MAShort+1);
   int shift,u,counted_bars=IndicatorCounted();
   double ST, 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;
   }
//----
   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 = sm / (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 = ((MCD - LLV)/(HHV - LLV))*100 + 0.01;
		s = s + 1;
		if (s >= (Cycle)/2)
		{ 
			s = 1;
			check_begin_MA = true;
		}
	}	else {ST = 0;}
	if (check_begin_MA) {	
		prev = MA[shift + 1];
		MA[shift] = smconst * (ST - prev) + prev;	}
      if (MA[shift]>20 && MA[shift+1]<20)
      {            
            ObjectCreate(ObjectID + "1"+Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet(ObjectID + "1"+Time[shift], OBJPROP_WIDTH,3);
            ObjectSet(ObjectID + "1"+Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet(ObjectID + "1"+Time[shift], OBJPROP_COLOR, Aqua);
         }          
         if (MA[shift+1]>80 && MA[shift]<80)
      {            
            ObjectCreate(ObjectID + "2"+Time[shift], OBJ_VLINE, 0, Time[shift], 0);
            ObjectSet(ObjectID + "2"+Time[shift], OBJPROP_WIDTH,3);
            ObjectSet(ObjectID + "2"+Time[shift], OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet(ObjectID + "2"+Time[shift], OBJPROP_COLOR, Yellow);
            
         }            
      Comment( MA[shift],MA[shift+1]);
      shift--;
      
     }

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

Comments