Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #property indicator_separate_window
- #property indicator_buffers 6
- #property indicator_color1 Magenta
- #property indicator_color2 Lime
- #property indicator_color3 Silver
- #property indicator_color4 Silver
- #property indicator_color5 Yellow
- #property indicator_color6 Aqua
- #property indicator_level1 0
- #property indicator_levelcolor Gray
- #property indicator_levelstyle 2
- extern int NMS_period = 40;
- extern bool Show_ZH = true;
- extern double ZH_displacement = 1;
- extern int ZH_symbol = 115;
- extern bool Show_SD = true;
- extern int SD_len = 30;
- extern double SD_up = 2;
- extern double SD_dn = 2;
- extern bool Show_SD_1line_only = true;
- extern bool Show_SD_2lines_up = true;
- extern bool Show_SD_2lines_dn = true;
- extern int NMA_period = 40;
- extern int NMA_LB_min = 8;
- extern bool Show_NMA = true;
- extern bool Show_FastNMA = true;
- double NMS[];
- double ZH[];
- double SD[];
- double SD2[];
- double NMS_NMA[];
- double NMS_FastNMA[];
- int init()
- {
- string nmsname = "NMS(" + NMS_period + ")";
- IndicatorShortName(nmsname);
- IndicatorBuffers(6);
- SetIndexBuffer(0, NMS);
- SetIndexLabel(0, nmsname);
- SetIndexBuffer(1, ZH);
- SetIndexLabel(1, "NMS_ZH");
- SetIndexStyle(1, DRAW_ARROW);
- SetIndexArrow(1, ZH_symbol);
- SetIndexBuffer(2, SD);
- SetIndexBuffer(3, SD2);
- if(Show_SD_1line_only)
- {
- SetIndexLabel(2, "NMS_SD(" + SD_len + ")");
- SetIndexLabel(3, "unused");
- }
- else
- {
- if(Show_SD_2lines_up) SetIndexLabel(2, "NMS_SD_up(" + SD_len + ")");
- else SetIndexLabel(2, "unused");
- if(Show_SD_2lines_dn) SetIndexLabel(3, "NMS_SD_dn(" + SD_len + ")");
- else SetIndexLabel(3, "unused");
- }
- SetIndexBuffer(4, NMS_NMA);
- SetIndexBuffer(5, NMS_FastNMA);
- if(Show_NMA) SetIndexLabel(4, "NMS_NMA(" + NMA_period + ")");
- else SetIndexLabel(4, "unused");
- if(Show_FastNMA) SetIndexLabel(5, "NMS_FastNMA(" + NMA_period + ", " + NMA_LB_min + ")");
- else SetIndexLabel(5, "unused");
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- double nms2, sum, abssum, ratio, nmsnum, maxnms;
- if(Bars <= NMS_period) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > NMS_period) limit = Bars - counted_bars;
- else limit = Bars - NMS_period - 1;
- for(i = limit; i >= 0; i--)
- {
- nms2 = 0;
- for(ii = 1; ii <= NMS_period; ii++)
- {
- double oLRSlope = 0, SumXY = 0, SumY = 0, SumX, SumXSqr, Divisor;
- if(ii > 1)
- {
- SumX = ii * (ii - 1) * 0.5;
- SumXSqr = ii * (ii - 1) * (2 * ii - 1) * 1/6;
- Divisor = (SumX * SumX) - ii * SumXSqr;
- for(int iii = 0; iii < ii; iii++)
- {
- SumXY += iii * MathLog(Close[i+iii]);
- SumY += MathLog(Close[i+iii]);
- }
- oLRSlope = (ii * SumXY - SumX * SumY) / Divisor;
- }
- nms2 += oLRSlope * MathSqrt(ii);
- }
- NMS[i] = nms2 * 100;
- if(Show_ZH) { if(NMS[i] == 0) ZH[i] = ZH_displacement; else ZH[i] = EMPTY_VALUE; }
- }
- if(Show_SD)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMS_period - 1 - SD_len)
- {
- if(Show_SD_1line_only)
- {
- if(NMS[i] == 0) SD[i] = 0;
- else if(NMS[i] > 0) SD[i] = iBandsOnArray(NMS, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- else if(NMS[i] < 0) SD[i] = iBandsOnArray(NMS, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- else
- {
- if(NMS[i] == 0)
- {
- if(Show_SD_2lines_up) SD[i] = 0;
- if(Show_SD_2lines_dn) SD2[i] = 0;
- }
- else
- {
- if(Show_SD_2lines_up) SD[i] = iBandsOnArray(NMS, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- if(Show_SD_2lines_dn) SD2[i] = iBandsOnArray(NMS, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- }
- }
- if(Show_NMA)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMS_period - 1 - NMA_period)
- {
- ratio = 0;
- sum = (NMS[i] - NMS[i+1]) + (NMS[i+1] - NMS[i+2]) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_period; ii++)
- sum += (NMS[i+ii] - NMS[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_period; ii++)
- sum += MathAbs(NMS[i+ii] - NMS[i+ii+1]);
- if(sum != 0) ratio = abssum / sum;
- NMS_NMA[i] = NMS_NMA[i+1] + (NMS[i] - NMS_NMA[i+1]) * ratio;
- }
- if(Show_FastNMA)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMS_period - 1 - NMA_period)
- {
- maxnms = 0; ratio = 0;
- int NMA_LB_max;
- for(ii = 1; ii <= NMA_period; ii++)
- {
- nmsnum = (NMS[i] - NMS[i+ii]) / MathSqrt(ii);
- if(MathAbs(nmsnum) > maxnms) { maxnms = MathAbs(nmsnum); NMA_LB_max = ii; }
- }
- if(NMA_LB_max < NMA_LB_min) NMA_LB_max = NMA_LB_min;
- sum = (NMS[i] - NMS[i+1]) + (NMS[i+1] - NMS[i+2]) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_LB_max; ii++)
- sum += (NMS[i+ii] - NMS[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_LB_max; ii++)
- sum += MathAbs(NMS[i+ii] - NMS[i+ii+1]);
- if(sum != 0) ratio = abssum / sum;
- NMS_FastNMA[i] = NMS_FastNMA[i+1] + (NMS[i] - NMS_FastNMA[i+1]) * ratio;
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement