Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #property indicator_chart_window
- #property indicator_buffers 6
- #property indicator_color1 Yellow
- #property indicator_color2 Gray
- #property indicator_color3 Gray
- #property indicator_color4 Aqua
- #property indicator_color5 Blue
- #property indicator_color6 Blue
- extern bool Show_NMA = true;
- extern int NMA_period = 40;
- extern int NMA_SD_len = 30;
- extern bool Show_NMA_SD_up = true;
- extern double NMA_SD_up = 2;
- extern bool Show_NMA_SD_dn = true;
- extern double NMA_SD_dn = 2;
- extern bool Show_FastNMA = true;
- extern int FastNMA_period = 40;
- extern int FastNMA_LB_min = 8;
- extern int FastNMA_SD_len = 20;
- extern bool Show_FastNMA_SD_up = true;
- extern double FastNMA_SD_up = 1.5;
- extern bool Show_FastNMA_SD_dn = true;
- extern double FastNMA_SD_dn = 1.5;
- double NMA[];
- double NMA_SDup[];
- double NMA_SDdn[];
- double FastNMA[];
- double FastNMA_SDup[];
- double FastNMA_SDdn[];
- double NMAx[];
- double FastNMAx[];
- int init()
- {
- IndicatorShortName("NMA(" + NMA_period + ", " + FastNMA_period + ", " + FastNMA_LB_min + ")");
- IndicatorBuffers(8);
- string nmaname = "NMA(" + NMA_period + ")";
- string nmasdname = "NMA_SD(" + NMA_SD_len + ")";
- string fastnmaname = "FastNMA(" + FastNMA_period + ", " + FastNMA_LB_min + ")";
- string fastnmasdname = "FastNMA_SD(" + FastNMA_SD_len + ")";
- SetIndexBuffer(0, NMA);
- SetIndexBuffer(1, NMA_SDup);
- SetIndexBuffer(2, NMA_SDdn);
- SetIndexBuffer(3, FastNMA);
- SetIndexBuffer(4, FastNMA_SDup);
- SetIndexBuffer(5, FastNMA_SDdn);
- SetIndexBuffer(6, NMAx);
- SetIndexBuffer(7, FastNMAx);
- if(Show_NMA) SetIndexLabel(0, nmaname); else SetIndexLabel(0, "unused");
- if(Show_NMA_SD_up) SetIndexLabel(1, nmasdname+"_up"); else SetIndexLabel(1, "unused");
- if(Show_NMA_SD_dn) SetIndexLabel(2, nmasdname+"_dn"); else SetIndexLabel(2, "unused");
- if(Show_FastNMA) SetIndexLabel(3, fastnmaname); else SetIndexLabel(3, "unused");
- if(Show_FastNMA_SD_up) SetIndexLabel(4, fastnmasdname+"_up"); else SetIndexLabel(4, "unused");
- if(Show_FastNMA_SD_dn) SetIndexLabel(5, fastnmasdname+"_dn"); else SetIndexLabel(5, "unused");
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- int max = MathMax(MathMax(Show_NMA * NMA_period,
- MathMax(Show_NMA_SD_up, Show_NMA_SD_dn) * MathMax(NMA_period, NMA_SD_len)),
- MathMax(Show_FastNMA * FastNMA_period,
- MathMax(Show_FastNMA_SD_up, Show_FastNMA_SD_dn) * MathMax(FastNMA_period, FastNMA_SD_len)));
- double sum, abssum, ratio, nmmnum, maxnmm;
- if(Bars <= max) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > max) limit = Bars - counted_bars;
- else limit = Bars - max - 1;
- for(i = limit; i >= 0; i--)
- {
- ratio = 0;
- sum = (MathLog(Close[i]) - MathLog(Close[i+1])) + (MathLog(Close[i+1]) - MathLog(Close[i+2])) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_period; ii++)
- sum += (MathLog(Close[i+ii]) - MathLog(Close[i+ii+1])) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_period; ii++)
- sum += MathAbs(MathLog(Close[i+ii]) - MathLog(Close[i+ii+1]));
- if(sum != 0) ratio = abssum / sum;
- NMAx[i] = NMAx[i+1] + (Close[i] - NMAx[i+1]) * ratio;
- if(Show_NMA) NMA[i] = NMAx[i];
- if(Show_NMA_SD_up) NMA_SDup[i] = NMAx[i] + NMA_SD_up * iStdDev(NULL, 0, NMA_SD_len, 0, 0, PRICE_CLOSE, i);
- if(Show_NMA_SD_dn) NMA_SDdn[i] = NMAx[i] - NMA_SD_dn * iStdDev(NULL, 0, NMA_SD_len, 0, 0, PRICE_CLOSE, i);
- }
- for(i = limit; i >= 0; i--)
- {
- maxnmm = 0; ratio = 0;
- int NMA_LB_max;
- for(ii = 1; ii <= FastNMA_period; ii++)
- {
- nmmnum = (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
- if(MathAbs(nmmnum) > maxnmm) { maxnmm = MathAbs(nmmnum); NMA_LB_max = ii; }
- }
- if(NMA_LB_max < FastNMA_LB_min) NMA_LB_max = FastNMA_LB_min;
- sum = (MathLog(Close[i]) - MathLog(Close[i+1])) + (MathLog(Close[i+1]) - MathLog(Close[i+2])) * (MathSqrt(2)-1);
- for(ii = 2; ii < NMA_LB_max; ii++)
- sum += (MathLog(Close[i+ii]) - MathLog(Close[i+ii+1])) * (MathSqrt(ii+1) - MathSqrt(ii));
- abssum = MathAbs(sum);
- sum = 0;
- for(ii = 0; ii < NMA_LB_max; ii++)
- sum += MathAbs(MathLog(Close[i+ii]) - MathLog(Close[i+ii+1]));
- if(sum != 0) ratio = abssum / sum;
- FastNMAx[i] = FastNMAx[i+1] + (Close[i] - FastNMAx[i+1]) * ratio;
- if(Show_FastNMA) FastNMA[i] = FastNMAx[i];
- if(Show_FastNMA_SD_up) FastNMA_SDup[i] = FastNMAx[i] + FastNMA_SD_up * iStdDev(NULL, 0, FastNMA_SD_len, 0, 0, PRICE_CLOSE, i);
- if(Show_FastNMA_SD_dn) FastNMA_SDdn[i] = FastNMAx[i] - FastNMA_SD_dn * iStdDev(NULL, 0, FastNMA_SD_len, 0, 0, PRICE_CLOSE, i);
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement