Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #property indicator_separate_window
- #property indicator_buffers 2
- #property indicator_color1 Magenta
- #property indicator_color2 Silver
- #property indicator_level1 0
- #property indicator_levelcolor Gray
- #property indicator_levelstyle 2
- extern int NMC_period = 40;
- extern bool Show_SD = true;
- extern int SD_len = 30;
- extern double SD_up = 2;
- extern double SD_dn = 2;
- double NMC[];
- double SD[];
- int init()
- {
- string nmcname = "NMC(" + NMC_period + ")";
- string sdname = "NMC_SD(" + SD_len + ")";
- IndicatorShortName(nmcname);
- IndicatorBuffers(2);
- SetIndexBuffer(0, NMC);
- SetIndexLabel(0, nmcname);
- SetIndexBuffer(1, SD);
- SetIndexLabel(1, sdname);
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- if(Bars <= NMC_period) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > NMC_period) limit = Bars - counted_bars;
- else limit = Bars - NMC_period - 1;
- for(i = limit; i >= 0; i--)
- {
- double nmm, nmr, nmm2 = 0, nmr2 = 0, avg, sign;
- for(ii = 1; ii <= NMC_period; ii++)
- {
- nmm2 += (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
- nmr2 += (MathLog(Close[i+ii-1]) - MathLog(Close[i+ii])) * (MathSqrt(ii) - MathSqrt(ii-1));
- }
- nmm = (nmm2 / NMC_period) * 1000;
- nmr = nmr2 * 1000;
- avg = ((MathAbs(nmm) * nmr) + (MathAbs(nmr) * nmm)) / 2;
- if(avg > 0) sign = 1;
- else if(avg < 0) sign = -1;
- else sign = 0;
- NMC[i] = sign * MathSqrt(MathAbs(avg));
- }
- if(Show_SD)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMC_period - 1 - SD_len)
- {
- if(NMC[i] == 0) SD[i] = 0;
- else if(NMC[i] > 0) SD[i] = iBandsOnArray(NMC, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- else if(NMC[i] < 0) SD[i] = iBandsOnArray(NMC, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement