NewTrend
Download scriptThe NewTrend indicator is a technical analysis tool designed to help traders identify the prevailing direction of the market by smoothing out price fluctuations and highlighting momentum. Instead of looking at raw, volatile price movements, this script processes historical data to provide a clearer picture of whether the market is trending upwards or downwards.
How the Logic Works
The indicator operates through a multi-step calculation process that focuses on "momentum" and "smoothing." Here is a breakdown of how it interprets market data:
1. Calculating Price Velocity The core logic begins by analyzing the relationship between the opening and closing prices of each candle. It calculates two distinct types of movement:
- Current Momentum: The change from the open to the close of the current price bar.
- Previous Momentum: The change from the previous bar's close to the current bar's open.
By looking at both these factors, the indicator captures a more comprehensive "flow" of the market rather than just looking at the final price.
2. Dual Smoothing (The DEMA Approach) To prevent the indicator from reacting too wildly to minor price "noise," the script applies a sophisticated smoothing technique. It maintains two separate tracking lines:
- A Fast Line reacts more quickly to recent price changes.
- A Slow Line reacts more gradually, representing the broader trend.
The script updates these lines incrementally, meaning each new value is based on a weighted average of the previous value and the current movement. This results in a fluid motion that filters out temporary spikes while staying responsive to genuine shifts in price direction.
3. The Main Trend Line The "Main Trend" shown on your chart is the mathematical difference between these two smoothed lines (the Fast Line minus the Slow Line).
- When the Fast Line moves significantly above the Slow Line, it indicates strengthening upward momentum.
- When the Slow Line sits above the Fast Line, it suggests a prevailing downward trend.
4. The Signal Line To provide an extra layer of confirmation, the script calculates a secondary Signal Line. This is essentially a "moving average" of the Main Trend line itself.
- The Signal Line acts as a stabilizer. It helps traders distinguish between a minor fluctuation in the trend and a significant reversal.
- By comparing the Main Trend to this Signal Line, you can visually identify when momentum is accelerating or losing steam before the price actually makes a major turn.
Summary for the User
In simple terms, this script acts like a sophisticated filter. It takes the chaotic "zig-zag" of market prices and converts them into two smooth, flowing lines. By measuring the distance between these lines and their respective signals, it allows you to see the underlying "current" of the market, making it easier to identify when a trend is established and when it might be starting to fade.
//+------------------------------------------------------------------+
//| NewTrend_v1.mq4 |
//| Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
#property indicator_buffers 2
//---- indicator settings
#property indicator_separate_window
#property indicator_level1 0.5
#property indicator_level2 -0.5
//----
#property indicator_color1 Silver
#property indicator_color2 Orange
//---- indicator parameters
extern int Smooth=9;
extern int Signal=9;
//---- indicator buffers
double Main_buffer[];
double Sign_buffer[];
double Fast_buffer[];
double Slow_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(3);
SetIndexBuffer(0,Main_buffer);
SetIndexBuffer(1,Sign_buffer);
SetIndexBuffer(2,Fast_buffer);
SetIndexBuffer(3,Slow_buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(0,1);
SetIndexDrawBegin(1,1);
// IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- indicator buffers mapping
// if(!SetIndexBuffer(0,Macd_buffer) && !SetIndexBuffer(1,Sign_buffer))
// Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("NewTrend("+Smooth+")");
SetIndexLabel(0,"Trend");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| MACD (DEMA) DiNapoli |
//+------------------------------------------------------------------+
int start()
{
for(int i=Bars; i>=0; i--)
{
Fast_buffer[i]=0.0;
Slow_buffer[i]=0.0;
Main_buffer[i]=0.0;
Sign_buffer[i]=0.0;
//if (i==Bars) {Fast_buffer[i]=0;Slow_buffer[i]=0;}
}
//---- macd counted in the 1-st buffer
for( i=Bars-1; i>=0; i--)
{
if (Close[i+1]>0)
{
double vA=(Close[i] - Open[i])/Open[i]/Point;
double vB=(Open[i] - Close[i+1])/Close[i+1]/Point;
//
Fast_buffer[i]=Fast_buffer[i+1]+2.0/(1.0+Smooth)*(vA-Fast_buffer[i+1]);
Slow_buffer[i]=Slow_buffer[i+1]+2.0/(1.0+Smooth)*(vB-Slow_buffer[i+1]);
Main_buffer[i]=Fast_buffer[i]-Slow_buffer[i];
}
}
//---- signal line counted in the 2-nd buffer
for(i=Bars-1; i>=0; i--)
Sign_buffer[i]=Sign_buffer[i+1]+2.0/(1.0+Signal)*(Main_buffer[i]-Sign_buffer[i+1]);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments