Schaff Trend CD

Download script
Author: mladen
Schaff Trend CD

This tool is designed to provide traders with a smoothed visual representation of market momentum. It functions by analyzing the relationship between two different moving averages to identify the underlying trend of a currency pair or asset.

How the Logic Works

The script operates through a two-step calculation process to filter out "market noise" and highlight significant price movements:

1. Calculating the Momentum Gap (MACD Foundation) First, the tool looks at two different timeframes simultaneously: a "Fast" average and a "Slow" average. By subtracting the value of the slow average from the fast average, the script determines the velocity of the price. When the fast price is moving significantly higher than the slow price, it indicates upward momentum; when it falls below, it suggests downward momentum.

2. Smoothing the Signal (The Trend CD) Because raw momentum data can often be erratic and jump around quickly, the script applies a final smoothing layer. It takes the results from the first step and runs them through a third calculation period. This "smooths out" the jagged edges of the raw data, resulting in a cleaner line that is easier for a trader to read visually.

Summary of Behavior

Instead of showing you every minor fluctuation in price, this indicator focuses on the sustained direction of the market. It takes complex mathematical moving averages and condenses them into a single, steady line. This allows users to see whether the current trend is strengthening or weakening without being distracted by temporary price spikes.

Indicators Used
Moving average indicatorMoving average indicator
14 Views
0 Downloads
0 Favorites
Schaff Trend CD
//+------------------------------------------------------------------+
//|                                              Schaff Trend CD.mq4 |
//|                                                           mladen |
//|                                                                  |
//| Shaff trend CD is equal to MACD signal line                      |
//| For sake of series programing I kept                             |
//| the "Shaff trend CD" name                                        |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Red

//
//
//
//
//

extern int CDPeriod     = 25;
extern int FastMAPeriod = 23;
extern int SlowMAPeriod = 50;

//
//
//
//
//

double cdBuffer[];
double macdBuffer[];


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(2);
      SetIndexBuffer(0,cdBuffer);
      SetIndexBuffer(1,macdBuffer);
   IndicatorShortName("Schaff Trend CD ("+FastMAPeriod+","+SlowMAPeriod+","+CDPeriod+")");
   return(0);
}

int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int      counted_bars=IndicatorCounted();
   int      limit,i;

   if(counted_bars < 0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;

   //
   //
   //
   //
   //
   
   for(i = limit; i >= 0; i--) macdBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i)-
                                               iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
   for(i = limit; i >= 0; i--) cdBuffer[i]   = iMAOnArray(macdBuffer,0,CDPeriod,0,MODE_EMA,i);
   return(0);
}

Comments