Advertisement
Guest User

Ocn_NMAx

a guest
Apr 8th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.85 KB | None | 0 0
  1. #property indicator_chart_window
  2. #property indicator_buffers 6
  3. #property indicator_color1 Yellow
  4. #property indicator_color2 Gray
  5. #property indicator_color3 Gray
  6. #property indicator_color4 Aqua
  7. #property indicator_color5 Blue
  8. #property indicator_color6 Blue
  9.  
  10. extern bool   Show_NMA           = true;
  11. extern int    NMA_period         = 40;
  12. extern int    NMA_SD_len         = 30;
  13. extern bool   Show_NMA_SD_up     = true;
  14. extern double NMA_SD_up          = 2;
  15. extern bool   Show_NMA_SD_dn     = true;
  16. extern double NMA_SD_dn          = 2;
  17. extern bool   Show_FastNMA       = true;
  18. extern int    FastNMA_period     = 40;
  19. extern int    FastNMA_LB_min     = 8;
  20. extern int    FastNMA_SD_len     = 20;
  21. extern bool   Show_FastNMA_SD_up = true;
  22. extern double FastNMA_SD_up      = 1.5;
  23. extern bool   Show_FastNMA_SD_dn = true;
  24. extern double FastNMA_SD_dn      = 1.5;
  25.  
  26. double NMA[];
  27. double NMA_SDup[];
  28. double NMA_SDdn[];
  29. double FastNMA[];
  30. double FastNMA_SDup[];
  31. double FastNMA_SDdn[];
  32. double NMAx[];
  33. double FastNMAx[];
  34.  
  35. int init()
  36. {
  37.   IndicatorShortName("NMA(" + NMA_period + ", " + FastNMA_period + ", " + FastNMA_LB_min + ")");
  38.   IndicatorBuffers(8);
  39.   string nmaname = "NMA(" + NMA_period + ")";
  40.   string nmasdname = "NMA_SD(" + NMA_SD_len + ")";
  41.   string fastnmaname = "FastNMA(" + FastNMA_period + ", " + FastNMA_LB_min + ")";
  42.   string fastnmasdname = "FastNMA_SD(" + FastNMA_SD_len + ")";
  43.   SetIndexBuffer(0, NMA);
  44.   SetIndexBuffer(1, NMA_SDup);
  45.   SetIndexBuffer(2, NMA_SDdn);
  46.   SetIndexBuffer(3, FastNMA);
  47.   SetIndexBuffer(4, FastNMA_SDup);
  48.   SetIndexBuffer(5, FastNMA_SDdn);
  49.   SetIndexBuffer(6, NMAx);
  50.   SetIndexBuffer(7, FastNMAx);
  51.   if(Show_NMA)       SetIndexLabel(0, nmaname);         else SetIndexLabel(0, "unused");
  52.   if(Show_NMA_SD_up) SetIndexLabel(1, nmasdname+"_up"); else SetIndexLabel(1, "unused");
  53.   if(Show_NMA_SD_dn) SetIndexLabel(2, nmasdname+"_dn"); else SetIndexLabel(2, "unused");
  54.   if(Show_FastNMA)       SetIndexLabel(3, fastnmaname);         else SetIndexLabel(3, "unused");
  55.   if(Show_FastNMA_SD_up) SetIndexLabel(4, fastnmasdname+"_up"); else SetIndexLabel(4, "unused");
  56.   if(Show_FastNMA_SD_dn) SetIndexLabel(5, fastnmasdname+"_dn"); else SetIndexLabel(5, "unused");
  57.   return(0);
  58. }
  59.  
  60. int start()
  61. {
  62.   int limit, i, ii, counted_bars = IndicatorCounted();
  63.   int max = MathMax(MathMax(Show_NMA * NMA_period,
  64.                             MathMax(Show_NMA_SD_up, Show_NMA_SD_dn) * MathMax(NMA_period, NMA_SD_len)),
  65.                     MathMax(Show_FastNMA * FastNMA_period,
  66.                             MathMax(Show_FastNMA_SD_up, Show_FastNMA_SD_dn) * MathMax(FastNMA_period, FastNMA_SD_len)));
  67.   double sum, abssum, ratio, nmmnum, maxnmm;
  68.  
  69.   if(Bars <= max) return(0);
  70.   if(counted_bars < 0) counted_bars = 0;
  71.   if(counted_bars > max) limit = Bars - counted_bars;
  72.   else                   limit = Bars - max - 1;
  73.  
  74.   for(i = limit; i >= 0; i--)
  75.     {
  76.     ratio = 0;
  77.     sum = (MathLog(Close[i]) - MathLog(Close[i+1])) + (MathLog(Close[i+1]) - MathLog(Close[i+2])) * (MathSqrt(2)-1);
  78.     for(ii = 2; ii < NMA_period; ii++)
  79.       sum += (MathLog(Close[i+ii]) - MathLog(Close[i+ii+1])) * (MathSqrt(ii+1) - MathSqrt(ii));
  80.     abssum = MathAbs(sum);
  81.     sum = 0;
  82.     for(ii = 0; ii < NMA_period; ii++)
  83.       sum += MathAbs(MathLog(Close[i+ii]) - MathLog(Close[i+ii+1]));
  84.     if(sum != 0) ratio = abssum / sum;
  85.     NMAx[i] = NMAx[i+1] + (Close[i] - NMAx[i+1]) * ratio;
  86.     if(Show_NMA)       NMA[i] = NMAx[i];
  87.     if(Show_NMA_SD_up) NMA_SDup[i] = NMAx[i] + NMA_SD_up * iStdDev(NULL, 0, NMA_SD_len, 0, 0, PRICE_CLOSE, i);
  88.     if(Show_NMA_SD_dn) NMA_SDdn[i] = NMAx[i] - NMA_SD_dn * iStdDev(NULL, 0, NMA_SD_len, 0, 0, PRICE_CLOSE, i);
  89.     }
  90.  
  91.   for(i = limit; i >= 0; i--)
  92.     {
  93.     maxnmm = 0; ratio = 0;
  94.     int NMA_LB_max;
  95.     for(ii = 1; ii <= FastNMA_period; ii++)
  96.       {
  97.       nmmnum = (MathLog(Close[i]) - MathLog(Close[i+ii])) / MathSqrt(ii);
  98.       if(MathAbs(nmmnum) > maxnmm) { maxnmm = MathAbs(nmmnum); NMA_LB_max = ii; }
  99.       }
  100.     if(NMA_LB_max < FastNMA_LB_min) NMA_LB_max = FastNMA_LB_min;
  101.     sum = (MathLog(Close[i]) - MathLog(Close[i+1])) + (MathLog(Close[i+1]) - MathLog(Close[i+2])) * (MathSqrt(2)-1);
  102.     for(ii = 2; ii < NMA_LB_max; ii++)
  103.       sum += (MathLog(Close[i+ii]) - MathLog(Close[i+ii+1])) * (MathSqrt(ii+1) - MathSqrt(ii));
  104.     abssum = MathAbs(sum);
  105.     sum = 0;
  106.     for(ii = 0; ii < NMA_LB_max; ii++)
  107.       sum += MathAbs(MathLog(Close[i+ii]) - MathLog(Close[i+ii+1]));
  108.     if(sum != 0) ratio = abssum / sum;
  109.     FastNMAx[i] = FastNMAx[i+1] + (Close[i] - FastNMAx[i+1]) * ratio;
  110.     if(Show_FastNMA)       FastNMA[i] = FastNMAx[i];
  111.     if(Show_FastNMA_SD_up) FastNMA_SDup[i] = FastNMAx[i] + FastNMA_SD_up * iStdDev(NULL, 0, FastNMA_SD_len, 0, 0, PRICE_CLOSE, i);
  112.     if(Show_FastNMA_SD_dn) FastNMA_SDdn[i] = FastNMAx[i] - FastNMA_SD_dn * iStdDev(NULL, 0, FastNMA_SD_len, 0, 0, PRICE_CLOSE, i);
  113.     }
  114.  
  115.   return(0);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement