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 NMR_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 NMR[];
- double ZH[];
- double SD[];
- double SD2[];
- double NMR_NMA[];
- double NMR_FastNMA[];
- int init()
- {
- string nmrname = "NMR(" + NMR_period + ")";
- IndicatorShortName(nmrname);
- IndicatorBuffers(6);
- SetIndexBuffer(0, NMR);
- SetIndexLabel(0, nmrname);
- SetIndexBuffer(1, ZH);
- SetIndexLabel(1, "NMR_ZH");
- SetIndexStyle(1, DRAW_ARROW);
- SetIndexArrow(1, ZH_symbol);
- SetIndexBuffer(2, SD);
- SetIndexBuffer(3, SD2);
- if(Show_SD_1line_only)
- {
- SetIndexLabel(2, "NMR_SD(" + SD_len + ")");
- SetIndexLabel(3, "unused");
- }
- else
- {
- if(Show_SD_2lines_up) SetIndexLabel(2, "NMR_SD_up(" + SD_len + ")");
- else SetIndexLabel(2, "unused");
- if(Show_SD_2lines_dn) SetIndexLabel(3, "NMR_SD_dn(" + SD_len + ")");
- else SetIndexLabel(3, "unused");
- }
- SetIndexBuffer(4, NMR_NMA);
- SetIndexBuffer(5, NMR_FastNMA);
- if(Show_NMA) SetIndexLabel(4, "NMR_NMA(" + NMA_period + ")");
- else SetIndexLabel(4, "unused");
- if(Show_FastNMA) SetIndexLabel(5, "NMR_FastNMA(" + NMA_period + ", " + NMA_LB_min + ")");
- else SetIndexLabel(5, "unused");
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- double nmr2, sum, abssum, ratio, nmrnum, maxnmr;
- if(Bars <= NMR_period) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > NMR_period) limit = Bars - counted_bars;
- else limit = Bars - NMR_period - 1;
- for(i = limit; i >= 0; i--)
- {
- nmr2 = 0;
- for(ii = 1; ii <= NMR_period; ii++)
- nmr2 += (MathLog(Close[i+ii-1]) - MathLog(Close[i+ii])) * (MathSqrt(ii) - MathSqrt(ii-1));
- NMR[i] = nmr2 * 1000;
- if(Show_ZH) { if(NMR[i] == 0) ZH[i] = ZH_displacement; else ZH[i] = EMPTY_VALUE; }
- }
- if(Show_SD)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMR_period - 1 - SD_len)
- {
- if(Show_SD_1line_only)
- {
- if(NMR[i] == 0) SD[i] = 0;
- else if(NMR[i] > 0) SD[i] = iBandsOnArray(NMR, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- else if(NMR[i] < 0) SD[i] = iBandsOnArray(NMR, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- else
- {
- if(NMR[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(NMR, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- if(Show_SD_2lines_dn) SD2[i] = iBandsOnArray(NMR, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- }
- }
- if(Show_NMA)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMR_period - 1 - NMA_period)
- {
- ratio = 0;
- sum = (NMR[i] - NMR[i+1]) + (NMR[i+1] - NMR[i+2]) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_period; ii++)
- sum += (NMR[i+ii] - NMR[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_period; ii++)
- sum += MathAbs(NMR[i+ii] - NMR[i+ii+1]);
- if(sum != 0) ratio = abssum / sum;
- NMR_NMA[i] = NMR_NMA[i+1] + (NMR[i] - NMR_NMA[i+1]) * ratio;
- }
- if(Show_FastNMA)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMR_period - 1 - NMA_period)
- {
- maxnmr = 0; ratio = 0;
- int NMA_LB_max;
- for(ii = 1; ii <= NMA_period; ii++)
- {
- nmrnum = (NMR[i] - NMR[i+ii]) / MathSqrt(ii);
- if(MathAbs(nmrnum) > maxnmr) { maxnmr = MathAbs(nmrnum); NMA_LB_max = ii; }
- }
- if(NMA_LB_max < NMA_LB_min) NMA_LB_max = NMA_LB_min;
- sum = (NMR[i] - NMR[i+1]) + (NMR[i+1] - NMR[i+2]) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_LB_max; ii++)
- sum += (NMR[i+ii] - NMR[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_LB_max; ii++)
- sum += MathAbs(NMR[i+ii] - NMR[i+ii+1]);
- if(sum != 0) ratio = abssum / sum;
- NMR_FastNMA[i] = NMR_FastNMA[i+1] + (NMR[i] - NMR_FastNMA[i+1]) * ratio;
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement