This trading indicator, titled "Trand," is designed to analyze market trends by measuring the relationship and momentum between two different moving averages. Instead of just showing you the price, it calculates specific mathematical deviations to help visualize how the trend is behaving over time.
How the Logic Works
1. The Foundation: Dual Moving Averages The script uses two distinct types of Exponential Moving Averages (EMA). One represents a "Long" timeframe (set by default to 80 periods) and the other a "Short" timeframe (set by default to 21 periods). By looking at these two different speeds, the tool can distinguish between the overall major trend and the immediate, smaller price movements.
2. Measuring the Gap (Momentum) The core logic focuses on the "distance" or gap between these two averages. The script doesn't just look at where the lines are now; it compares the current distance between them to where that distance was a few periods ago.
- It calculates the difference between the Long and Short averages at the current moment.
- It then looks back in time (based on the "Short" period setting) to see what that gap was previously.
3. Calculating Volatility and Direction The indicator transforms these distances into a numerical value (a percentage). This is achieved by:
- Determining the change in the gap size.
- Comparing the current average prices to find a relative weight.
- Multiplying these factors together to create a visual "swing."
4. Visual Indicators The script produces two distinct data streams to help with analysis:
- Directional Movement: It identifies whether the gap between the averages is expanding or contracting. If the current gap is smaller than it was in the past, the logic assigns a negative value; if it is larger, it assigns a positive value. This helps traders see if the "push" of the market is accelerating or slowing down.
- Trend Smoothing: A secondary calculation combines the relative positions of the short and long averages to provide a clearer picture of the overall trend flow.
Summary for the User
In simple terms, this script acts like a "speedometer" for market trends. By calculating how fast the gap between a slow-moving average and a fast-moving average is widening or narrowing, it provides a visual representation of momentum. It helps traders identify not just which way the price is going, but how much strength is behind that move at any given moment.
//+------------------------------------------------------------------+
//| Trand.mq4 |
//| Copyright © 2006, Âèêòîð ×åáîòàð¸â |
//| http://www.chebotariov.co.ua/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Âèêòîð ×åáîòàð¸â"
#property link "http://www.chebotariov.co.ua/"
extern int LONG = 80;
extern int SHORT = 21;
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("Trand("+LONG+","+SHORT+")");
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Trand |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
i=Bars-counted_bars-1;
while(i>=0)
{
double MALONG = iMA(NULL,0,LONG,0,MODE_EMA,PRICE_CLOSE,i);
double MALONG2 = iMA(NULL,0,LONG,0,MODE_EMA,PRICE_CLOSE,i+SHORT-1);
double MASHORT = iMA(NULL,0,SHORT,0,MODE_EMA,PRICE_CLOSE,i);
double MASHORT2 = iMA(NULL,0,SHORT,0,MODE_EMA,PRICE_CLOSE,i+SHORT-1);
double RAZNICA = MathAbs(MathAbs(MALONG-MASHORT)-MathAbs(MALONG-MASHORT2));
double RAZNICA2 = MathAbs(MALONG-MASHORT)+MathAbs(MALONG2-MASHORT2)/2;
double PERCENT = RAZNICA*100*((MALONG+MALONG2)/2)*RAZNICA2;
if(MathAbs(MALONG-MASHORT)-MathAbs(MALONG-MASHORT2)<0){int ZNAK=-1;}else{ZNAK=1;}
ExtMapBuffer1[i]=PERCENT*ZNAK;
ExtMapBuffer2[i]=(MASHORT-MALONG)+(MALONG-MALONG2);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments