at_ZDn
Download scriptThis tool is designed to analyze and smooth out price movements on a trading chart to help identify significant trends and potential reversal points. Instead of simply following the raw, jagged price action, the script applies a mathematical smoothing process to clarify the overall direction of the market.
How the Logic Works
The script functions through three distinct stages:
1. Data Smoothing and Weighting The tool begins by collecting a specific window of recent price data. It uses a weighted calculation (similar to a moving average) to strip away "market noise"—those small, insignificant fluctuations that can often distract from the bigger picture. By looking at a predefined range of past prices, it creates a more stable baseline of where the price is actually heading.
2. Dual-Layer Trend Refinement The script performs a sophisticated "double pass" on the data:
- First, it calculates a smoothed trend line based on historical progression.
- Second, it takes that result and blends it with the most recent price points. By combining these two perspectives—the historical trend and the current momentum—the tool generates a refined curve that represents a "filtered" version of the market's path. This makes it easier to see the underlying flow of the assets without being misled by temporary spikes.
3. Peak and Trough Identification Once the smooth curve is established, the script scans for specific structural changes in price direction. It monitors the "peaks" (where the price stops rising and begins to turn) and "troughs" (where the price stops falling and begins to climb).
Specifically, it looks for the exact moment a trend reverses. When the market switches from an upward move to a downward move, the script identifies that high point and marks it. This allows you to see clearly defined price levels where momentum shifted, helping to highlight potential areas of interest on the chart.
Summary for the User
In simple terms, this script acts like a filter. It takes messy market data, smooths it out into a readable trend line, and then automatically identifies the "turning points" where the trend changed direction. It is designed to help you ignore the minor distractions of the market and focus on the broader movement and significant price shifts.
//**********************************
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightSkyBlue
#property indicator_color2 Pink
#property indicator_width1 2
#property indicator_width2 2
//==================================
extern int p=6;
extern int s=3;
extern int cb=300;
//==================================
double fx[],fxL[],za[];
double z1,z2,ki;
int fs;
//**********************************
int init()
{
IndicatorBuffers(3);
//-------------------
SetIndexBuffer(0,fx); SetIndexEmptyValue(0,0.0);
SetIndexBuffer(1,fxL); SetIndexEmptyValue(1,0.0);
//-------------------
SetIndexBuffer(2,za);
//--------------------------
ki=2.0/(p+1);
//--------------------------
return(0);
}
//***************************************************************************
int start()
{
SetIndexDrawBegin(0,Bars-cb);
SetIndexDrawBegin(1,Bars-cb);
for (int i=cb; i>=0; i--) {fx[i]=Close[i];}
for (int m=0; m<=s; m++)
{
z1=fx[0];
for (i=0; i<=cb; i++) {z1=z1+(fx[i]-z1)*ki; za[i]=z1;}
z2=fx[cb];
for (i=cb; i>=0; i--) {z2=z2+(fx[i]-z2)*ki; fx[i]=(za[i]+z2)/2;}
}
fs=0;
for (i=cb; i>=0; i--)
{
if (fx[i]>fx[i+1]) fs=1;
if (fx[i]<fx[i+1]) {if (fs==1) fxL[i+1]=fx[i+1]; fs=2;}
if (fs==2) fxL[i]=fx[i]; else fxL[i]=0.0;
}
return(0);
}
//************************************************************
Comments