Author: #Copyright � 2008, XrustSolution.#
Xma[1]

This script is designed to function as a specialized technical indicator for trading platforms, specifically aimed at smoothing out price fluctuations to help identify trends more clearly. Instead of following every minor "zig" and "zag" of the market price, it uses a filtering logic to create a more stable visual line on your chart.

How the Logic Works

The tool operates by analyzing two different versions of a Moving Average—a standard mathematical calculation used to find the average price over a specific number of bars. Here is the step-by-step breakdown of its behavior:

1. Dual Comparison The script simultaneously calculates two different moving averages. The primary difference between these two is a slight shift in their parameters (specifically, one looks at the current data while the other looks at slightly offset data). By comparing these two values, the script can determine if the market is moving with significant momentum or just experiencing minor "noise."

2. The Threshold Filter (The "Stability" Rule) This is the core logic of the script. It looks at the difference between the two moving averages it calculated.

  • If the difference is small: The script decides that the price movement isn't significant enough to warrant a change in the indicator's line. In this case, it simply carries over the previous value, keeping the line flat and steady.
  • If the difference exceeds a specific "Threshold": If the gap between the two averages becomes larger than a limit you set, the script recognizes this as a meaningful move in the market. It then updates the indicator's line to reflect this new price level.

3. Visual Output The result is a blue line on your chart that remains "rigid" during periods of consolidation (sideways movement) and only shifts when there is a distinct, sustained move in price. This helps traders avoid reacting to small, insignificant price flickers, aiming instead to follow the broader trend of the market.

Summary of Key Variables

  • Period: Determines how many past candles are averaged to calculate the movement.
  • Threshold (Porog): Controls how "sensitive" the indicator is. A higher number means the line will stay flat longer, only moving when a very large price change occurs; a lower number makes it more reactive to smaller moves.
  • Methods: These define the mathematical style of the averaging (e.g., Simple or Exponential), which dictates how heavily the script weights recent prices versus older ones.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Xma[1]
//+------------------------------------------------------------------+
//|                                                          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 |
//|      Õîòü äàííàÿ ïðîãðàììà è ÿâëÿåòñÿ ñâîáîäíî ðàñïðîñòðàíÿåìîé, |
//|           ïóáëèêàöèÿ åå áåç óêàçàíèÿ íà ïåðâîèñòî÷íèê çàïðåùåíà  |   
//-------------------------------------------------------------------+
#property copyright "#Copyright © 2008, XrustSolution.#"
#property link      "#http://www.xrust.ucoz.net#"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue

extern int period=12;
extern int porog =3;
extern int metod =1;
extern int metod2=1;
extern int prise =0;
//---- buffers
double Signal[];
//+------------------------------------------------------------------+
void init(){
   SetIndexStyle(0,DRAW_LINE);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(0,Signal);
   IndicatorShortName("Xma"+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];
     }
   }
   return(0);}
//+------------------------------------------------------------------+   

Comments