Advertisement
Guest User

Ocn_NMM_Ocean_Indexx

a guest
Apr 8th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.07 KB | None | 0 0
  1. #property indicator_separate_window
  2. #property indicator_buffers 6
  3. #property indicator_color1 Magenta
  4. #property indicator_color2 Lime
  5. #property indicator_color3 Silver
  6. #property indicator_color4 Silver
  7. #property indicator_color5 Yellow
  8. #property indicator_color6 Aqua
  9. #property indicator_level1 0
  10. #property indicator_levelcolor Gray
  11. #property indicator_levelstyle 2
  12.  
  13. extern int    NMM_LB              = 21;
  14. extern bool   Show_ZH             = true;
  15. extern double ZH_displacement     = 1;
  16. extern int    ZH_symbol           = 115;
  17. extern bool   Show_SD             = true;
  18. extern int    SD_len              = 30;
  19. extern double SD_up               = 2;
  20. extern double SD_dn               = 2;
  21. extern bool   Show_SD_1line_only  = true;
  22. extern bool   Show_SD_2lines_up   = true;
  23. extern bool   Show_SD_2lines_dn   = true;
  24. extern int    NMA_period          = 40;
  25. extern int    NMA_LB_min          = 8;
  26. extern bool   Show_NMA            = true;
  27. extern bool   Show_FastNMA        = true;
  28.  
  29. double NMM[];
  30. double ZH[];
  31. double SD[];
  32. double SD2[];
  33. double NMM_NMA[];
  34. double NMM_FastNMA[];
  35.  
  36. int init()
  37. {
  38.   string nmmname = "NMM_Ocean_Index(" + NMM_LB + ")";
  39.   IndicatorShortName(nmmname);
  40.   IndicatorBuffers(6);
  41.   SetIndexBuffer(0, NMM);
  42.   SetIndexLabel(0, nmmname);
  43.   SetIndexBuffer(1, ZH);
  44.   SetIndexLabel(1, "NMM_Ocean_Index_ZH");
  45.   SetIndexStyle(1, DRAW_ARROW);
  46.   SetIndexArrow(1, ZH_symbol);
  47.   SetIndexBuffer(2, SD);
  48.   SetIndexBuffer(3, SD2);
  49.   if(Show_SD_1line_only)
  50.     {
  51.     SetIndexLabel(2, "NMM_Ocean_Index_SD(" + SD_len + ")");
  52.     SetIndexLabel(3, "unused");
  53.     }
  54.   else
  55.     {
  56.     if(Show_SD_2lines_up) SetIndexLabel(2, "NMM_Ocean_Index_SD_up(" + SD_len + ")");
  57.     else                  SetIndexLabel(2, "unused");
  58.     if(Show_SD_2lines_dn) SetIndexLabel(3, "NMM_Ocean_Index_SD_dn(" + SD_len + ")");
  59.     else                  SetIndexLabel(3, "unused");
  60.     }
  61.   SetIndexBuffer(4, NMM_NMA);
  62.   SetIndexBuffer(5, NMM_FastNMA);
  63.   if(Show_NMA) SetIndexLabel(4, "NMM_Ocean_Index_NMA(" + NMA_period + ")");
  64.   else         SetIndexLabel(4, "unused");
  65.   if(Show_FastNMA) SetIndexLabel(5, "NMM_Ocean_Index_FastNMA(" + NMA_period + ", " + NMA_LB_min + ")");
  66.   else             SetIndexLabel(5, "unused");
  67.   return(0);
  68. }
  69.  
  70. int start()
  71. {
  72.   int limit, i, ii, counted_bars = IndicatorCounted();
  73.   double sum, abssum, ratio, nmmnum, maxnmm;
  74.  
  75.   if(Bars <= NMM_LB) return(0);
  76.   if(counted_bars < 0) counted_bars = 0;
  77.   if(counted_bars > NMM_LB) limit = Bars - counted_bars;
  78.   else                      limit = Bars - NMM_LB - 1;
  79.  
  80.   for(i = limit; i >= 0; i--)
  81.     {
  82.     NMM[i] = (MathLog(Close[i]) - MathLog(Close[i+NMM_LB])) / MathSqrt(NMM_LB) * 1000;
  83.     if(Show_ZH) { if(NMM[i] == 0) ZH[i] = ZH_displacement; else ZH[i] = EMPTY_VALUE; }
  84.     }
  85.  
  86.   if(Show_SD)
  87.     for(i = limit; i >= 0; i--)
  88.       if(i < Bars - NMM_LB - 1 - SD_len)
  89.         {
  90.         if(Show_SD_1line_only)
  91.           {
  92.           if(NMM[i] == 0)     SD[i] = 0;
  93.           else if(NMM[i] > 0) SD[i] = iBandsOnArray(NMM, 0, SD_len, SD_up, 0, MODE_UPPER, i);
  94.           else if(NMM[i] < 0) SD[i] = iBandsOnArray(NMM, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
  95.           }
  96.         else
  97.           {
  98.           if(NMM[i] == 0)
  99.             {
  100.             if(Show_SD_2lines_up) SD[i] = 0;
  101.             if(Show_SD_2lines_dn) SD2[i] = 0;
  102.             }
  103.           else
  104.             {
  105.             if(Show_SD_2lines_up) SD[i] = iBandsOnArray(NMM, 0, SD_len, SD_up, 0, MODE_UPPER, i);
  106.             if(Show_SD_2lines_dn) SD2[i] = iBandsOnArray(NMM, 0, SD_len, SD_dn, 0, MODE_LOWER, i);
  107.             }
  108.           }
  109.         }
  110.  
  111.   if(Show_NMA)
  112.     for(i = limit; i >= 0; i--)
  113.       if(i < Bars - NMM_LB - 1 - NMA_period)
  114.         {
  115.         ratio = 0;
  116.         sum = (NMM[i] - NMM[i+1]) + (NMM[i+1] - NMM[i+2]) * (MathSqrt(2)-1);
  117.         for(ii = 2; ii < NMA_period; ii++)
  118.           sum += (NMM[i+ii] - NMM[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
  119.         abssum = MathAbs(sum);
  120.         sum = 0;
  121.         for(ii = 0; ii < NMA_period; ii++)
  122.           sum += MathAbs(NMM[i+ii] - NMM[i+ii+1]);
  123.         if(sum != 0) ratio = abssum / sum;
  124.         NMM_NMA[i] = NMM_NMA[i+1] + (NMM[i] - NMM_NMA[i+1]) * ratio;
  125.         }
  126.  
  127.   if(Show_FastNMA)
  128.     for(i = limit; i >= 0; i--)
  129.       if(i < Bars - NMM_LB - 1 - NMA_period)
  130.         {
  131.         maxnmm = 0; ratio = 0;
  132.         int NMA_LB_max;
  133.         for(ii = 1; ii <= NMA_period; ii++)
  134.           {
  135.           nmmnum = (NMM[i] - NMM[i+ii]) / MathSqrt(ii);
  136.           if(MathAbs(nmmnum) > maxnmm) { maxnmm = MathAbs(nmmnum); NMA_LB_max = ii; }
  137.           }
  138.         if(NMA_LB_max < NMA_LB_min) NMA_LB_max = NMA_LB_min;
  139.         sum = (NMM[i] - NMM[i+1]) + (NMM[i+1] - NMM[i+2]) * (MathSqrt(2)-1);
  140.         for(ii = 2; ii < NMA_LB_max; ii++)
  141.           sum += (NMM[i+ii] - NMM[i+ii+1]) * (MathSqrt(ii+1) - MathSqrt(ii));
  142.         abssum = MathAbs(sum);
  143.         sum = 0;
  144.         for(ii = 0; ii < NMA_LB_max; ii++)
  145.           sum += MathAbs(NMM[i+ii] - NMM[i+ii+1]);
  146.         if(sum != 0) ratio = abssum / sum;
  147.         NMM_FastNMA[i] = NMM_FastNMA[i+1] + (NMM[i] - NMM_FastNMA[i+1]) * ratio;
  148.         }
  149.  
  150.   return(0);
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement