ttm-trend_v1
Download scriptThis tool is designed to provide traders with a clear visual representation of market trends by analyzing price action through the lens of "Heikin Ashi" logic. Instead of looking at standard candles, which can be noisy, this script smooths out price movements to identify the underlying direction of the market more effectively.
How it Works
1. Price Smoothing (Heikin Ashi Logic) The script begins by transforming standard price data into a smoothed format. It calculates new "open" and "close" values based on the average of previous prices. This helps filter out temporary market volatility, making it easier to see if the momentum is truly moving upward or downward.
2. Trend Detection and Persistence The core logic determines whether the current price action is bullish (upward) or bearish (downward). It does this by comparing the smoothed opening and closing prices:
- If the smoothed close is higher than the open, it signals an upward trend.
- If the smoothed close is lower than the open, it signals a downward trend.
3. Momentum Validation To ensure the trend isn't just a one-time fluke, the script looks back at a specific number of previous bars (defined by the "CompBars" setting). If the current price action overlaps with the range of those previous bars, the script maintains the previous color/trend status. This prevents the visual display from flickering rapidly during "choppy" markets and ensures that colors only change when there is a significant shift in momentum.
4. Visual Representation The final output is displayed on your chart as a dual-colored histogram:
- Upward Trend: When the market shows bullish momentum, the script highlights the price range in one color (Blue).
- Downward Trend: When the market shows bearish momentum, it switches to another color (Red).
Summary for Traders
By using this indicator, you can quickly distinguish between a strong trending market and a consolidating one. Rather than reacting to every minor price tick, the script helps you stay on the right side of the trend by smoothing out "market noise" and only changing its visual signal when a meaningful shift in price direction occurs.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| ttm-trend.mq4 |
//| Copyright © 2005, Nick Bilak, beluck[AT]gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color2 Red
#property indicator_color1 Blue
//---- input parameters
extern int CompBars=6;
//---- buffers
double buf1[];
double buf2[];
double haOpen[];
double haClose[];
double icolor[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,buf1);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,buf2);
SetIndexBuffer(2,haOpen);
SetIndexBuffer(3,haClose);
SetIndexBuffer(4,icolor);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int shift,limit,i;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-4;
if(counted_bars>=1) limit=Bars-counted_bars-4;
double dip,dim,stm,sts,macdm,macds;
if (haOpen[limit+3]==0.0) haOpen[limit+3]=Open[limit+3];
haClose[limit+3] = (Open[limit+3]+High[limit+3]+Low[limit+3]+Close[limit+3])/4.0;
for(shift = limit+2; shift >= 0; shift--) {
haOpen[shift] = (haOpen[shift+1]+haClose[shift+1])/2.0;
haClose[shift] = (Open[shift]+High[shift]+Low[shift]+Close[shift])/4.0;
if (haClose[shift] > haOpen[shift]) icolor[shift] = 1;
else icolor[shift] = -1;
for (i=1; i<=CompBars; i++) {
if ( haOpen[shift] <= MathMax(haOpen[shift+i],haClose[shift+i]) &&
haOpen[shift] >= MathMin(haOpen[shift+i],haClose[shift+i]) &&
haClose[shift] <= MathMax(haOpen[shift+i],haClose[shift+i]) &&
haClose[shift] >= MathMin(haOpen[shift+i],haClose[shift+i]) )
icolor[shift] = icolor[shift+i];
}
if (icolor[shift]>0) {
buf1[shift]=High[shift];
buf2[shift]=Low[shift];
} else {
buf2[shift]=High[shift];
buf1[shift]=Low[shift];
}
}
}
//+------------------------------------------------------------------+
Comments