Advertisement
Guest User

NMM_X-Ray_2

a guest
Apr 5th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 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 Red
  6. #property indicator_color2 Blue
  7. #property indicator_color3 Aqua
  8. #property indicator_level1 0
  9. #property indicator_level2 20
  10. #property indicator_levelcolor Gray
  11. #property indicator_levelstyle 2
  12.  
  13. extern int     NMM_period  = 40;
  14. extern bool    Show_value  = false;
  15. extern bool    Show_LB     = true;
  16.  
  17. double NMMmaxratio[];
  18. double NMMsign[];
  19. double LBlen[];
  20.  
  21. int init()
  22. {
  23.   string nmmname = "NMM_X-Ray_2";
  24.   IndicatorShortName(nmmname + "(" + NMM_period + ")");
  25.   if(Show_value) IndicatorDigits(2); else IndicatorDigits(0);
  26.   IndicatorBuffers(3);
  27.   SetIndexBuffer(0, NMMmaxratio);
  28.   SetIndexLabel(0, nmmname + "(" + NMM_period + ")");
  29.   SetIndexBuffer(1, NMMsign);
  30.   SetIndexLabel(1, nmmname + "_sign");
  31.   SetIndexBuffer(2, LBlen);
  32.   SetIndexLabel(2, nmmname + "_LBlen");
  33.   return(0);
  34. }
  35.  
  36. int start()
  37. {
  38.   int limit, i, ii, counted_bars = IndicatorCounted();
  39.  
  40.   if(Bars <= NMM_period) return(0);
  41.   if(counted_bars < 0) counted_bars = 0;
  42.   if(counted_bars > NMM_period) limit = Bars - counted_bars;
  43.   else                          limit = Bars - NMM_period - 1;
  44.  
  45.   for(i = limit; i >= 0; i--)
  46.     {
  47.     double nmmnum, nmmmax = -1, nmmsign, nmmlb;
  48.     for(ii = 1; ii <= NMM_period; ii++)
  49.       {
  50.       nmmnum = (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
  51.       if(MathAbs(nmmnum) > nmmmax)
  52.         {
  53.         nmmmax = MathAbs(nmmnum);
  54.         nmmlb = ii;
  55.         if(nmmnum > 0)      nmmsign = 1;
  56.         else if(nmmnum < 0) nmmsign = -1;
  57.         else                nmmsign = 0;
  58.         }
  59.       }
  60.     if(Show_value) { NMMmaxratio[i] = nmmmax * 1000; NMMsign[i] = nmmsign; }
  61.     if(Show_LB) LBlen[i] = nmmlb;
  62.     }
  63.  
  64.   return(0);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement