Advertisement
Guest User

NMM_X-Ray_1

a guest
Apr 5th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. #property indicator_separate_window
  2. #property indicator_minimum 0
  3. #property indicator_maximum 40
  4. #property indicator_buffers 3
  5. #property indicator_color1 Yellow
  6. #property indicator_color2 CLR_NONE
  7. #property indicator_color3 CLR_NONE
  8. #property indicator_level1 20
  9. #property indicator_levelcolor Gray
  10. #property indicator_levelstyle 2
  11.  
  12. extern int     NMM_period  = 40;
  13. extern bool    Show_Pct    = false;
  14.  
  15. double NMM[];
  16. double NegCnt[];
  17. double ZeroCnt[];
  18.  
  19. int init()
  20. {
  21.   string nmmname = "NMM_X-Ray_1";
  22.   IndicatorShortName(nmmname + "(" + NMM_period + ")");
  23.   IndicatorBuffers(3);
  24.   SetIndexBuffer(0, NMM);
  25.   SetIndexLabel(0, nmmname + "(" + NMM_period + ")");
  26.   SetIndexBuffer(1, NegCnt);
  27.   SetIndexLabel(1, nmmname + "_NegCnt");
  28.   SetIndexBuffer(2, ZeroCnt);
  29.   SetIndexLabel(2, nmmname + "_ZeroCnt");
  30.   return(0);
  31. }
  32.  
  33. int start()
  34. {
  35.   int limit, i, ii, counted_bars = IndicatorCounted();
  36.  
  37.   if(Bars <= NMM_period) return(0);
  38.   if(counted_bars < 0) counted_bars = 0;
  39.   if(counted_bars > NMM_period) limit = Bars - counted_bars;
  40.   else                          limit = Bars - NMM_period - 1;
  41.  
  42.   for(i = limit; i >= 0; i--)
  43.     {
  44.     double nmmnum, Pos = 0, Neg = 0, Zero = 0;
  45.     for(ii = 1; ii <= NMM_period; ii++)
  46.       {
  47.       nmmnum = (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
  48.       if(nmmnum > 0)      Pos++;
  49.       else if(nmmnum < 0) Neg++;
  50.       else                Zero++;
  51.       }
  52.     if(Show_Pct)
  53.       {
  54.       NMM[i] = Pos / NMM_period * 100;
  55.       NegCnt[i] = Neg / NMM_period * 100;
  56.       ZeroCnt[i] = Zero / NMM_period * 100;
  57.       }
  58.     else
  59.       {
  60.       NMM[i] = Pos;
  61.       NegCnt[i] = Neg;
  62.       ZeroCnt[i] = Zero;
  63.       }
  64.     }
  65.  
  66.   return(0);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement