Overview of the Indicator Logic
This script is designed as a technical analysis tool for trading platforms, specifically intended to help visualize and interpret market price dynamics. Rather than relying on simple price movements, it uses a complex mathematical approach to analyze how price "velocity" and "momentum" change over time.
Here is a breakdown of the logic in non-technical terms:
1. Logarithmic Price Analysis
Instead of looking at the raw price (e.g., $100 vs $105), the script converts prices into a logarithmic scale. This is a professional way to measure percentage changes rather than absolute dollar amounts. By doing this, the indicator treats a move from $10 to $11 with the same significance as a move from $100 to $110. It calculates these differences across a wide range of past price points (up to 40 bars back).
2. Weighted Momentum Calculation
The script performs three different types of calculations to understand the "strength" of the current market trend:
- Simple Differences: It tracks the basic change between consecutive price points.
- Adjusted Differences: It applies a specific mathematical weight (based on square roots) to these changes. This effectively gives more or less importance to certain historical data points to smooth out "noise."
- Ratio Mapping: By comparing the weighted differences against the simple differences, the script creates a "Ratio." This ratio serves as a multiplier that tells the indicator how much the current market behavior deviates from the norm.
3. Multi-Zone Smoothing (The "Moving" Components)
The logic then takes these raw calculations and organizes them into three distinct zones:
- Short-Term Zone: Focuses on very recent price changes to capture immediate momentum.
- Mid-Term Zone: Looks at a balanced window of the recent past.
- Long-Term Zone: Analyzes a broader set of historical data to identify the underlying trend.
4. Exponential Smoothing and Output
Finally, the script uses these three zones to calculate "Exponential Moving Averages" (EMAs). It uses the Ratio mentioned earlier as a dynamic factor to update these averages.
The final output is displayed on your chart as four distinct lines:
- Two lines represent the primary calculated trends (the positive and negative movements of the market).
- Two lines represent the smoothed, secondary variations of those trends.
Summary for the User
Essentially, this indicator acts like a "sophisticated filter." It takes messy price data, shrinks it down to its core percentage movements, weights those movements based on their mathematical significance, and then draws four lines that represent the "true" momentum of the market. When these lines move in specific directions or converge, they provide a visual representation of whether the current trend is accelerating, slowing down, or shifting direction.
//+------------------------------------------------------------------+
//| nmm.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_buffers 4
#property indicator_separate_window
double extmapbuffer1[];
double extmapbuffer2[];
double extmapbuffer3[];
double extmapbuffer4[];
#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Yellow
#property indicator_color4 Green
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle (0,DRAW_LINE);
SetIndexStyle (1,DRAW_LINE);
SetIndexStyle (2,DRAW_LINE);
SetIndexStyle (3, DRAW_LINE);
SetIndexBuffer (0, extmapbuffer1);
SetIndexBuffer (1, extmapbuffer2);
SetIndexBuffer (2, extmapbuffer3);
SetIndexBuffer (3, extmapbuffer4);
string short_name = "NMR";
IndicatorShortName (short_name);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40;
double s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,s31,s32,s33,s34,s35,s36,s37,s38,s39,s40;
double ave, badif0,badif1,badif2,badif3,badif4,badif5,badif6,badif7,badif8,badif9,badif10,badif11,badif12,badif13,badif14,badif15,badif16,badif17,badif18,badif19,badif20,badif21,badif22,badif23,badif24,badif25,badif26,badif27,badif28,badif29,badif30,badif31,badif32,badif33,badif34,badif35,badif36,badif37,badif38,badif39,badif40;
double sum,sum2, ratio, dif0,dif1,dif2,dif3,dif4,dif5,dif6,dif7,dif8,dif9,dif10,dif11,dif12,dif13,dif14,dif15,dif16,dif17,dif18,dif19,dif20,dif21,dif22,dif23,dif24,dif25,dif26,dif27,dif28,dif29,dif30,dif31,dif32,dif33,dif34,dif35,dif36,dif37,dif38,dif39,dif40;
double adif0,adif1,adif2,adif3,adif4,adif5,adif6,adif7,adif8,adif9,adif10,adif11,adif12,adif13,adif14,adif15,adif16,adif17,adif18,adif19,adif20,adif21,adif22,adif23,adif24,adif25,adif26,adif27,adif28,adif29,adif30,adif31,adif32,adif33,adif34,adif35,adif36,adif37,adif38,adif39,adif40;
int pos = Bars - counted_bars;
while (pos>=0)
{
if (counted_bars<0) return (-1);
if (counted_bars>0) counted_bars--;
dif0 = MathAbs((MathLog(Close[pos])*100000) - (MathLog(Close [pos+1])*100000));
dif1 = MathAbs((MathLog(Close[pos+1])*100000) - (MathLog(Close [pos+2])*100000));
dif2 = MathAbs((MathLog(Close[pos+2])*100000) - (MathLog(Close [pos+3])*100000)) ;
dif3 = MathAbs((MathLog(Close[pos+3])*100000) - (MathLog(Close [pos+4])*100000)) ;
dif4 = MathAbs((MathLog(Close[pos+4])*100000) - (MathLog(Close [pos+5])*100000)) ;
dif5 = MathAbs((MathLog(Close[pos+5])*100000) - (MathLog(Close [pos+6])*100000)) ;
dif6 = MathAbs((MathLog(Close[pos+6])*100000) - (MathLog(Close [pos+7])*100000)) ;
dif7 = MathAbs((MathLog(Close[pos+7])*100000) - (MathLog(Close [pos+8])*100000)) ;
dif8 = MathAbs((MathLog(Close[pos+8])*100000) - (MathLog(Close [pos+9])*100000)) ;
dif9 = MathAbs((MathLog(Close[pos+9])*100000) - (MathLog(Close [pos+10])*100000)) ;
dif10 =MathAbs((MathLog(Close[pos+10])*100000) - (MathLog(Close [pos+11])*100000));
dif11 =MathAbs((MathLog(Close[pos+11])*100000) - (MathLog(Close [pos+12])*100000)) ;
dif12 =MathAbs((MathLog(Close[pos+12])*100000) - (MathLog(Close [pos+13])*100000)) ;
dif14 =MathAbs((MathLog(Close[pos+13])*100000) - (MathLog(Close [pos+14])*100000)) ;
dif15 =MathAbs((MathLog(Close[pos+14])*100000) - (MathLog(Close [pos+15])*100000)) ;
dif16 =MathAbs((MathLog(Close[pos+15])*100000) - (MathLog(Close [pos+16])*100000));
dif17 =MathAbs((MathLog(Close[pos+16])*100000) - (MathLog(Close [pos+17])*100000)) ;
dif18 =MathAbs((MathLog(Close[pos+17])*100000) - (MathLog(Close [pos+18])*100000)) ;
dif19 =MathAbs((MathLog(Close[pos+18])*100000) - (MathLog(Close [pos+19])*100000));
dif20 =MathAbs((MathLog(Close[pos+19])*100000) - (MathLog(Close [pos+20])*100000));
adif0 = MathAbs(MathLog(Close[pos])*100000 - MathLog(Close [pos+1])*100000);
adif1 = MathAbs(MathLog(Close[pos+1])*100000 - MathLog(Close [pos+2])*100000) * (MathSqrt(2)-MathSqrt(1));
adif2 = MathAbs(MathLog(Close[pos+2])*100000 - MathLog(Close [pos+3])*100000) * (MathSqrt(3)-MathSqrt(2));
adif3 = MathAbs(MathLog(Close[pos+3])*100000 - MathLog(Close [pos+4])*100000) * (MathSqrt(4)-MathSqrt(3));
adif4 = MathAbs(MathLog(Close[pos+4])*100000 - MathLog(Close [pos+5])*100000) * (MathSqrt(5)-MathSqrt(4));
adif5 = MathAbs(MathLog(Close[pos+5])*100000 - MathLog(Close [pos+6])*100000)* (MathSqrt(6)-MathSqrt(5));
adif6 = MathAbs(MathLog(Close[pos+6])*100000 - MathLog(Close [pos+7])*100000) * (MathSqrt(7)-MathSqrt(6));
adif7 = MathAbs(MathLog(Close[pos+7])*100000 - MathLog(Close [pos+8])*100000) * (MathSqrt(8)-MathSqrt(7));
adif8 = MathAbs(MathLog(Close[pos+8])*100000 - MathLog(Close [pos+9])*100000) * (MathSqrt(9)-MathSqrt(8));
adif9 = MathAbs(MathLog(Close[pos+9])*100000 - MathLog(Close [pos+10])*100000) * (MathSqrt(10)-MathSqrt(9));
adif10 =MathAbs (MathLog(Close[pos+10])*100000 - MathLog(Close [pos+11])*100000) * (MathSqrt(11)-MathSqrt(10));
adif11 =MathAbs (MathLog(Close[pos+11])*100000 - MathLog(Close [pos+12])*100000) * (MathSqrt(12)-MathSqrt(11));
adif12 =MathAbs (MathLog(Close[pos+12])*100000 - MathLog(Close [pos+13])*100000) * (MathSqrt(13)-MathSqrt(12));
adif14 =MathAbs (MathLog(Close[pos+13])*100000 - MathLog(Close [pos+14])*100000) * (MathSqrt(14)-MathSqrt(13));
adif15 =MathAbs (MathLog(Close[pos+14])*100000 - MathLog(Close [pos+15])*100000) * (MathSqrt(15)-MathSqrt(14));
adif16 =MathAbs (MathLog(Close[pos+15])*100000 - MathLog(Close [pos+16])*100000) * (MathSqrt(16)-MathSqrt(15));
adif17 =MathAbs (MathLog(Close[pos+16])*100000 - MathLog(Close [pos+17])*100000) * (MathSqrt(17)-MathSqrt(16));
adif18 =MathAbs (MathLog(Close[pos+17])*100000 - MathLog(Close [pos+18])*100000) * (MathSqrt(18)-MathSqrt(17));
adif19 =MathAbs (MathLog(Close[pos+18])*100000 - MathLog(Close [pos+19])*100000) * (MathSqrt(19)-MathSqrt(18));
adif20 =MathAbs (MathLog(Close[pos+19])*100000 - MathLog(Close [pos+20])*100000) * (MathSqrt(20)-MathSqrt(19));
s1 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+1])*100000);
s2 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+2])*100000);
s3 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+3])*100000);
s4 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+4])*100000);
s5 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+5])*100000);
s6 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+6])*100000);
s7 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+7])*100000);
s8 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+8])*100000);
s9 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+9])*100000);
s10 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+10])*100000);
s11 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+11])*100000);
s12 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+12])*100000);
s13 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+13])*100000);
s14 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+14])*100000);
s15 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+15])*100000);
s16 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+16])*100000);
s17 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+17])*100000);
s18 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+18])*100000);
s19 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+19])*100000);
s20 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+20])*100000);
s21 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+21])*100000);
s22 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+22])*100000);
s23 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+23])*100000);
s24 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+24])*100000);
s25 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+25])*100000);
s26 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+26])*100000);
s27 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+27])*100000);
s28 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+28])*100000);
s29 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+29])*100000);
s30 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+30])*100000);
s31 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+31])*100000);
s32 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+32])*100000);
s33 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+33])*100000);
s34 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+34])*100000);
s35 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+35])*100000);
s36 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+36])*100000);
s37 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+37])*100000);
s38 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+38])*100000);
s39 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+39])*100000);
s40 = (MathLog(Close[pos])*100000) - (MathLog(Close [pos+40])*100000);
badif1 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+1])*100000) / MathSqrt(1);
badif2 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+2])*100000) / MathSqrt(2);
badif3 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+3])*100000) / MathSqrt(3);
badif4 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+4])*100000) / MathSqrt(4);
badif5 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+5])*100000) / MathSqrt(5);
badif6 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+6])*100000) / MathSqrt(6);
badif7 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+7])*100000) / MathSqrt(7);
badif8 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+8])*100000) / MathSqrt(8);
badif9 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+9])*100000) / MathSqrt(9);
badif10 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+10])*100000) / MathSqrt(10);
badif11= (MathLog(Close[pos])*100000 - MathLog(Close [pos+11])*100000) / MathSqrt(11);
badif12 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+12])*100000) / MathSqrt(12);
badif13 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+13])*100000) / MathSqrt(13);
badif14= (MathLog(Close[pos])*100000 - MathLog(Close [pos+14])*100000) / MathSqrt(14);
badif15 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+15])*100000) / MathSqrt(15);
badif16 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+16])*100000) / MathSqrt(16);
badif17 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+17])*100000) / MathSqrt(17);
badif18= (MathLog(Close[pos])*100000 - MathLog(Close [pos+18])*100000) / MathSqrt(18);
badif19 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+19])*100000) / MathSqrt(19);
badif20 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+20])*100000) / MathSqrt(20);
badif21 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+21])*100000) / MathSqrt(21);
badif22 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+22])*100000) / MathSqrt(22);
badif23 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+23])*100000) / MathSqrt(23);
badif24 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+24])*100000) / MathSqrt(24);
badif26 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+25])*100000) / MathSqrt(25);
badif26 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+26])*100000) / MathSqrt(26);
badif27 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+27])*100000) / MathSqrt(27);
badif28 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+28])*100000) / MathSqrt(28);
badif29 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+29])*100000) / MathSqrt(29);
badif30 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+30])*100000) / MathSqrt(30);
badif31 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+31])*100000) / MathSqrt(31);
badif32 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+32])*100000) / MathSqrt(32);
badif33 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+33])*100000) / MathSqrt(33);
badif34 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+34])*100000) / MathSqrt(34);
badif35 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+35])*100000) / MathSqrt(35);
badif36 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+36])*100000) / MathSqrt(36);
badif37 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+37])*100000) / MathSqrt(37);
badif38 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+38])*100000) / MathSqrt(38);
badif39 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+39])*100000) / MathSqrt(39);
badif40 = (MathLog(Close[pos])*100000 - MathLog(Close [pos+40])*100000) / MathSqrt(40);
double x1;
Print(s1);
ave = (badif1+badif2+badif3+badif4+badif5+badif6+badif7+badif8+badif9+badif10+badif11+badif12+badif13+badif14+badif15+badif16+badif17+badif18+badif19+badif20+badif21+badif22+badif23+badif24+badif25+badif26+badif27+badif28+badif29+badif30+badif31+badif32+badif33+badif34+badif35+badif36+badif37+badif38+badif39+badif40) ;
sum = MathRound(dif1+dif2+dif3+dif4+dif5+dif6+dif7+dif8+dif9+dif10+dif11+dif12+dif13+dif14+dif15+dif16+dif17+dif18+dif19+dif20+dif21+dif22+dif23+dif24+dif25+dif26+dif27+dif28+dif29+dif30+dif31+dif32+dif33+dif34+dif35+dif36+dif37+dif38+dif39+dif40);
sum2 = MathRound(adif1+adif2+adif3+adif4+adif5+adif6+adif7+adif8+adif9+adif10+adif11+adif12+adif13+adif14+adif15+adif16+adif17+adif18+adif19+adif20+adif21+adif22+adif23+adif24+adif25+adif26+adif27+adif28+adif29+adif30+adif31+adif32+adif33+adif34+adif35+adif36+adif37+adif38+adif39+adif40);
ratio = sum2 / sum;
double thisbar, ema=0, ema2=0,ema3=0,ema4=0 , next,t,x,s,r;
thisbar=Close[pos];
r= (adif0+adif1+adif2+adif3+adif4+adif5+adif6+adif7+adif8+adif9+adif10+adif11+adif12+adif13+adif14+adif15+adif16+adif17+adif18+adif19+adif20) ;
t = (badif40+badif39+badif38+badif37+badif36+badif35+badif34+badif33+badif32+badif31+badif30+badif21+badif22+badif23+badif24+badif25+badif26+badif27+badif28+badif29+badif30) / 20;
x = (badif1+badif2+badif3+badif4+badif5+badif6+badif7+badif8+badif9+badif10+badif11+badif12+badif13+badif14+badif15+badif16+badif17+badif18+badif19+badif20) / 20;
s = (badif10+badif11+badif12+badif13+badif14+badif15+badif16+badif17+badif18+badif19+badif20+badif21+badif22+badif23+badif24+badif25+badif26+badif27+badif28+badif29+badif30 ) /20;
ema = ema + (ratio * (x - ema));
ema2 = ema2 +(ratio * (r*ratio - ema2));
ema4 = ema4 + (ratio * (((t+x+s)/3)-ema4));
extmapbuffer4[pos] = ema4;
extmapbuffer1[pos] = ema;
extmapbuffer3[pos] = -ema2;
extmapbuffer2[pos] = ema2;
pos--;
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments