MAX Moving Average_01
Download scriptThis script is designed as a visual analysis tool for the MetaTrader platform, aimed at helping traders identify trends and potential turning points in price action. Rather than simply plotting the raw price of an asset, it calculates two distinct mathematical "weighted" averages to smooth out market noise and highlight significant movements.
Core Logic and Mechanics
The tool functions by calculating two different layers of moving data:
1. The Weighted Moving Averages The script looks back at a specific number of historical price bars (defined by the user) and calculates a weighted average for each. Unlike a simple average where every day or hour carries the same importance, this logic applies a "power" multiplier to the data. This means that prices closer to the current moment are given significantly more mathematical weight than older prices. By doing this twice—once with a long historical window and once with a shorter window—the script creates two distinct lines on your chart.
2. Trend Smoothing
- The Primary Line: Represents a broader, slower trend based on a larger set of historical data.
- The Secondary Line: Represents a faster, more reactive trend based on a smaller set of recent data.
By comparing these two lines against each other, the script helps traders visualize whether the current market momentum is accelerating or decelerating relative to its long-term history.
Visual Signals and Alerts
Beyond just drawing these two lines, the script contains built-in logic to identify "crossovers" or shifts in momentum. It monitors the relationship between the fast line and the slow line:
- Trend Intersection: The logic detects when the fast and slow lines cross paths. These crossovers often indicate a shift in market sentiment (e.g., moving from an uptrend to a downtrend, or vice versa).
- Automated Markers: When these specific mathematical conditions are met—where the relationship between the two averages flips—the script automatically places visual arrows on the chart.
Practical Application
For a user, this means you don't have to manually guess where a trend is shifting. The script does the heavy lifting by calculating the weighted pressure of recent prices versus historical ones. It then highlights those specific moments of transition with visual markers, allowing you to see potential entry or exit points more clearly by observing when the short-term momentum pulls away from or cuts through the long-term average.
#property link "http://www.themovingaverage.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Crimson
#property indicator_color4 DarkTurquoise
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
extern int firstback=50;
extern int secondback=14;
extern int countbars=5000;
extern int power=2;
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_ARROW);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_ARROW);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexArrow(2,108);
SetIndexArrow(3,108);
return(0);
}
int deinit()
{
return(0);
}
int last = 0;
int start(){
if(last == Bars) return (0);
last = Bars;
int counted_bars=IndicatorCounted();
int pos;
int cnt;
int mult;
double first,second;
ArrayInitialize(ExtMapBuffer1,0);
ArrayInitialize(ExtMapBuffer2,0);
pos=countbars;
while (pos>-1){
mult=firstback+1;
first=0;
second=0;
for (cnt=pos;cnt<pos+firstback;cnt++){
mult--;
first=first+(Close[cnt]*MathPow(mult,power));
//Print (cnt);
}
mult=firstback+1;
for (cnt=pos;cnt<pos+firstback;cnt++){
mult--;
second=second+MathPow(mult,power);
}
ExtMapBuffer1[pos]=first/second;
pos--;
}
pos=countbars;
while (pos>-1){
mult=secondback+1;
first=0;
second=0;
for (cnt=pos;cnt<pos+secondback;cnt++){
mult--;
first=first+(Close[cnt]*MathPow(mult,power));
//Print (cnt);
}
mult=secondback+1;
for (cnt=pos;cnt<pos+secondback;cnt++){
mult--;
second=second+MathPow(mult,power);
}
ExtMapBuffer2[pos]=first/second;
if((ExtMapBuffer2[pos]-ExtMapBuffer1[pos])*(ExtMapBuffer2[pos+1]-ExtMapBuffer1[pos+1])<0){
if((ExtMapBuffer2[pos]-ExtMapBuffer1[pos])<0)
ExtMapBuffer3[pos] = ExtMapBuffer1[pos];
else
ExtMapBuffer4[pos] = ExtMapBuffer2[pos];
}
pos--;
}
return(0);
}
Comments