Advertisement
Guest User

NMC

a guest
Apr 7th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. #property indicator_separate_window
  2. #property indicator_buffers 2
  3. #property indicator_color1 Magenta
  4. #property indicator_color2 Silver
  5. #property indicator_level1 0
  6. #property indicator_levelcolor Gray
  7. #property indicator_levelstyle 2
  8.  
  9. extern int     NMC_period  = 40;
  10. extern bool    Show_SD     = true;
  11. extern int     SD_len      = 30;
  12. extern double  SD_up       = 2;
  13. extern double  SD_dn       = 2;
  14.  
  15. double NMC[];
  16. double SD[];
  17.  
  18. int init()
  19. {
  20.   string nmcname = "NMC(" + NMC_period + ")";
  21.   string sdname = "NMC_SD(" + SD_len + ")";
  22.   IndicatorShortName(nmcname);
  23.   IndicatorBuffers(2);
  24.   SetIndexBuffer(0, NMC);
  25.   SetIndexLabel(0, nmcname);
  26.   SetIndexBuffer(1, SD);
  27.   SetIndexLabel(1, sdname);
  28.   return(0);
  29. }
  30.  
  31. int start()
  32. {
  33.   int limit, i, ii, counted_bars = IndicatorCounted();
  34.  
  35.   if(Bars <= NMC_period) return(0);
  36.   if(counted_bars < 0) counted_bars = 0;
  37.   if(counted_bars > NMC_period) limit = Bars - counted_bars;
  38.   else                          limit = Bars - NMC_period - 1;
  39.  
  40.   for(i = limit; i >= 0; i--)
  41.     {
  42.     double nmm, nmr, nmm2 = 0, nmr2 = 0, avg, sign;
  43.     for(ii = 1; ii <= NMC_period; ii++)
  44.       {
  45.       nmm2 += (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
  46.       nmr2 += (MathLog(Close[i+ii-1]) - MathLog(Close[i+ii])) * (MathSqrt(ii) - MathSqrt(ii-1));
  47.       }
  48.     nmm = (nmm2 / NMC_period) * 1000;
  49.     nmr = nmr2 * 1000;
  50.     avg = ((MathAbs(nmm) * nmr) + (MathAbs(nmr) * nmm)) / 2;
  51.     if(avg > 0)      sign = 1;
  52.     else if(avg < 0) sign = -1;
  53.     else             sign = 0;
  54.     NMC[i] = sign * MathSqrt(MathAbs(avg));
  55.     }
  56.  
  57.   if(Show_SD)
  58.     for(i = limit; i >= 0; i--)
  59.       if(i < Bars - NMC_period - 1 - SD_len)
  60.         {
  61.         if(NMC[i] == 0)     SD[i] = 0;
  62.         else if(NMC[i] > 0) SD[i] = iBandsOnArray(NMC, 0, SD_len, SD_up, 0, MODE_UPPER, i);
  63.         else if(NMC[i] < 0) SD[i] = iBandsOnArray(NMC, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
  64.         }
  65.  
  66.   return(0);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement