ttm-trend-2
Download scriptThis tool is designed to help traders visualize the prevailing market trend by identifying and highlighting significant price movements on your trading chart. Rather than relying on standard price action alone, it uses a specialized calculation method to smooth out "noise" and determine the direction of the market more clearly.
How the Logic Works
1. Identifying the Core Price Movement The script begins by calculating specific types of price data based on the hourly timeframe. Instead of looking only at the most recent closing price, it looks at a mathematical average of the opening prices and the lowest points reached during those periods. This helps establish a more balanced "base" for what the market is actually doing.
2. Determining Market Sentiment (Color Coding) The script evaluates the relationship between these calculated prices to decide if the sentiment is positive or negative:
- If the current price movement is higher than its previous base, it identifies a bullish (upward) trend.
- If the price movement is lower than its previous base, it identifies a bearish (downward) trend.
3. Trend Persistence & Continuity A key feature of this logic is its ability to "remember" the trend. The script doesn't just look at the current bar in isolation; it looks back at several previous bars (based on a customizable setting). If the current price movement overlaps with the range of those previous bars, the script maintains the previous trend color. This prevents the visual display from flickering or changing colors prematurely during minor consolidations, ensuring that only significant shifts in momentum are highlighted.
4. Visual Representation Finally, the script translates these calculations into a visual histogram on your chart:
- Bullish Trends: When the logic detects an upward trend, it highlights the price movement with one color (Blue).
- Bearish Trends: When the logic detects a downward trend, it highlights the price movement with another color (Red).
By using this logic, the tool provides a cleaner, more consistent view of market direction, making it easier for traders to see the overall flow of the market at a glance.
//+------------------------------------------------------------------+
//| 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]=iOpen(NULL,PERIOD_H1,limit+3);
haClose[limit+3] = (iOpen(NULL,PERIOD_H1,limit+3)+iOpen(NULL,PERIOD_H1,limit+3)+iLow(NULL,PERIOD_H1,limit+3)+iLow(NULL,PERIOD_H1,limit+3))/4.0;
for(shift = limit+2; shift >= 0; shift--) {
haOpen[shift] = (haOpen[shift+1]+haClose[shift+1])/2.0;
haClose[shift] = (iOpen(NULL,PERIOD_H1,shift)+iOpen(NULL,PERIOD_H1,shift)+iLow(NULL,PERIOD_H1,shift)+iLow(NULL,PERIOD_H1,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