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 NMA_period = 40;
- extern bool FastNMA = true;
- extern int NMA_LB_min = 8;
- extern bool Show_SD = true;
- extern int SD_len = 30;
- extern double SD_up = 2;
- extern double SD_dn = 2;
- double Price_Osc[];
- double SD[];
- double NMA[];
- int init()
- {
- string nmaname = "NMA_Price_Osc(" + NMA_period + ")";
- if(FastNMA) nmaname = "Fast_NMA_Price_Osc(" + NMA_period + ", " + NMA_LB_min + ")";
- string sdname = "NMA_Price_Osc_SD(" + SD_len + ")";
- IndicatorShortName(nmaname);
- IndicatorBuffers(3);
- SetIndexBuffer(0, Price_Osc);
- SetIndexLabel(0, nmaname);
- SetIndexBuffer(1, SD);
- SetIndexLabel(1, sdname);
- SetIndexBuffer(2, NMA);
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- if(Bars <= NMA_period) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > NMA_period) limit = Bars - counted_bars;
- else limit = Bars - NMA_period - 1;
- for(i = limit; i >= 0; i--)
- {
- double nmmnum, maxnmm = 0, sum, abssum, ratio = 0;
- int NMA_LB_max;
- if(FastNMA)
- {
- for(ii = 1; ii <= NMA_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 < NMA_LB_min) NMA_LB_max = NMA_LB_min;
- }
- else NMA_LB_max = NMA_period;
- 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;
- NMA[i] = NMA[i+1] + (Close[i] - NMA[i+1]) * ratio;
- Price_Osc[i] = Close[i] - NMA[i];
- }
- if(Show_SD)
- for(i = limit; i >= 0; i--)
- if(i < Bars - NMA_period - 1 - SD_len)
- {
- if(Price_Osc[i] == 0) SD[i] = 0;
- else if(Price_Osc[i] > 0) SD[i] = iBandsOnArray(Price_Osc, 0, SD_len, SD_up, 0, MODE_UPPER, i);
- else if(Price_Osc[i] < 0) SD[i] = iBandsOnArray(Price_Osc, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement