Xma_3col[1]
Download scriptThis tool is designed as a visual trend indicator for the MetaTrader trading platform. It functions by smoothing out price fluctuations to help traders identify the underlying direction of the market more clearly. By filtering out "noise"—the minor, jagged price movements that can often mislead beginners—it provides a cleaner view of whether the current momentum is moving upward or downward.
How the Logic Works
The core logic of this script relies on three main steps: calculation, stability checking, and trend visualization.
1. Double Smoothing Calculation The script looks at two different versions of a Moving Average (a standard tool that averages price over a set number of bars). By comparing these two calculations simultaneously, the indicator attempts to find a "consensus" on where the price is heading. Instead of reacting instantly to every tiny tick in the market, it looks for broader movements.
2. The Stability Threshold (The "Filter") One of the most important features of this logic is the sensitivity threshold. The script doesn't update its main signal line every time the price moves even slightly. It requires a specific amount of movement (a "gap") between the two moving averages before it decides to shift the primary signal.
- If the difference between the calculations is small, the indicator remains steady.
- If the difference exceeds your predefined limit, the indicator updates its position. This prevents the trend line from "wiggling" excessively during sideways markets or low-volatility periods.
3. Dynamic Color Coding and Trend Tracking The script translates these mathematical calculations into visual cues on your chart:
- Trend Direction: It constantly monitors whether the signal line is rising or falling compared to its previous position.
- Visual Continuity: When the trend changes (e.g., from up to down), the script recognizes the shift and applies specific colors. It tracks these movements to ensure that the visual lines on your chart are connected logically, making it easier to see exactly where a trend started and where it reversed.
Summary for the User
Essentially, this script acts as a "stabilized" trend line. It ignores minor market jitters by requiring a minimum amount of movement before acknowledging a change in direction. This helps you stay on the side of the dominant trend without being distracted by the constant small fluctuations inherent in live trading.
//+------------------------------------------------------------------+
//| Xma.mq4 |
//| Copyright © 2009, XrustSolution. Toys from Vinin.|
//| http://www.xrust.ucoz.net http://www.vinin.ucoz.ru |
//| xrust@land.ru xrust@gmail.com xrust@mksat.net |
//| Õîòü äàííàÿ ïðîãðàììà è ÿâëÿåòñÿ ñâîáîäíî ðàñïðîñòðàíÿåìîé, |
//| ïóáëèêàöèÿ åå áåç óêàçàíèÿ íà ïåðâîèñòî÷íèê çàïðåùåíà |
//-------------------------------------------------------------------+
//mod 3col granit http://codebase.mql4.com/ru/5899
#property copyright "#Copyright © 2008, XrustSolution.#"
#property link "#http://www.xrust.ucoz.net#"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Red
extern int period=12;
extern int porog =3;
extern int metod =1;
extern int metod2=1;
extern int prise =0;
//---- buffers
double Signal[];
double Up[];
double Dn[];
double Up1[];
double Dn1[];
//+------------------------------------------------------------------+
void init(){
SetIndexBuffer(0,Signal);
SetIndexBuffer(1,Up1);
SetIndexBuffer(2,Up);
SetIndexBuffer(3,Dn1);
SetIndexBuffer(4,Dn);
IndicatorShortName("Xma_color"+period+porog);
return;}
//+------------------------------------------------------------------+
int start() {
int limit;
double tmp1,tmp2;
int counted_bars=IndicatorCounted();
int i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for (i = limit;i>=0;i--){
tmp1=iMA(Symbol(),0,period,0,metod,prise,i);
tmp2=iMA(Symbol(),0,period,1,metod2,prise,i);
if(MathAbs(tmp1-tmp2)>=porog*Point)
Signal[i]=tmp2;
else
Signal[i]=Signal[i+1];
Up[i] =EMPTY_VALUE; Dn[i] =EMPTY_VALUE;
Up1[i]=EMPTY_VALUE; Dn1[i]=EMPTY_VALUE;
if (Signal[i]<Signal[i+1]) {
if (Dn[i+2]!=EMPTY_VALUE) { Dn1[i]=Signal[i]; Dn1[i+1]=Signal[i+1]; }
else { Dn[i] =Signal[i]; Dn[i+1] =Signal[i+1]; }
}
if (Signal[i]>Signal[i+1]) {
if (Up[i+2]!=EMPTY_VALUE) { Up1[i]=Signal[i]; Up1[i+1]=Signal[i+1]; }
else { Up[i] =Signal[i]; Up[i+1] =Signal[i+1]; }
}
}
return(0);
}
Comments