MK_Laguerre

Author: Emerald King
0 Views
0 Downloads
0 Favorites
MK_Laguerre
//+------------------------------------------------------------------+
//|                                                     Laguerre.mq4 |
//|                                                     Emerald King |
//|                                     mailto:info@emerald-king.com |
//|                                              MK_Laguerre.mq4     |
//|         the code is optimized for testing by  Mikhail Kozhemyako |
//|                                                ua3xcm@obninsk.ru |
//+------------------------------------------------------------------+
#property copyright "Emerald King"
#property link      "mailto:info@emerald-king.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_level2 0.85
#property indicator_level3 0.5
#property indicator_level4 0.15
#property indicator_color1 Magenta
#property indicator_width1 2
#property indicator_label1  "MK Laguerre"
//---- input parameters
input double gamma=0.66;

double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
double val1[];
int    oldbar;
//| Custom indicator initialization function                         |
int OnInit()
  {
   SetIndexBuffer(0,val1);
   string shortname=StringConcatenate("Laguerre(",DoubleToString(gamma,3),")");
   IndicatorShortName(shortname);
   oldbar=Bars-1;
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,       //  êîëè÷åñòâî áàðîâ, äîñòóïíûõ èíäèêàòîðó äëÿ ðàñ÷åòà
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,limit;
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0) limit++;
   for(i=limit-1; i>=0; i--)
      {
       if(oldbar<Bars || prev_calculated==0)
         {
          oldbar=Bars;
          L0A = L0;
          L1A = L1;
          L2A = L2;
          L3A = L3;
         }
       L0 = (1 - gamma)*Close[i] + gamma*L0A;
       L1 = - gamma *L0 + L0A + gamma *L1A;
       L2 = - gamma *L1 + L1A + gamma *L2A;
       L3 = - gamma *L2 + L2A + gamma *L3A;
       CU = 0;
       CD = 0;
       if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
       if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
       if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;
       if (CU + CD != 0) LRSI = CU / (CU + CD);
       val1[i] = LRSI;
      }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---