MAX Moving Average_01_v1
Download scriptThis custom indicator is designed to analyze price movements by calculating two distinct types of weighted averages. By comparing these two averages, the script identifies specific momentum shifts and potential trend reversals on your trading chart.
How the Logic Works
1. Weighted Price Calculation Unlike a standard moving average that treats every past price point equally, this script applies a "power" weight to historical data. This means it gives more mathematical significance to certain periods in the lookback range. It creates two separate calculations based on different timeframes:
- Long-Term Analysis: A wider lookback period used to determine the broader trend of the market.
- Short-Term Analysis: A narrower lookback period used to capture immediate, current price fluctuations.
2. The Comparison Engine The script plots two lines on your chart representing these different weighted averages. The core "intelligence" of the tool lies in how it measures the relationship between these two lines:
- It constantly calculates the distance between the Short-Term and Long-Term averages.
- It monitors whether this distance is expanding, contracting, or flipping directions.
3. Visual Signals (Arrows) The primary goal of the script is to highlight "crossovers" or significant changes in momentum where the short-term trend contradicts the long-term trend.
- When the mathematical relationship between the two averages flips—meaning the short-term price action has moved from being above the long-term average to below it (or vice versa)—the script triggers a visual signal.
- These signals appear as arrows on the chart, alerting you to moments where the current price velocity may be shifting, potentially indicating a change in market direction.
Summary for Traders
Instead of just showing you where the price was, this tool attempts to show you how fast and in what direction the price is moving relative to its historical average. It filters out minor "noise" by using weighted math and only provides visual alerts when the short-term momentum makes a significant enough turn to potentially signal a new trend.
#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=200;
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