EhlersDecyclerOscillator Arrow

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
EhlersDecyclerOscillator Arrow
ÿþ//+------------------------------------------------------------------+

//|                               EhlersDecyclerOscillator Arrow.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.000"

#property description "EhlersDecyclerOscillator ++ Arrow: 'BUY' and 'SELL'"

#property description "The code is made based on 'EhlersDecyclerOscillator'"

#property description "by the author Andrei Novichkov ( https://www.mql5.com/ru/code/30857 )"

#property version   "1.00"

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots   3

//--- plot Dec

#property indicator_label1  "Dec"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrLimeGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- plot BUY

#property indicator_label2  "BUY"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot SELL

#property indicator_label3  "SELL"

#property indicator_type3   DRAW_ARROW

#property indicator_color3  clrRed

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- input parameters

input group             "Dec"

input int                  Input_period_1          = 10;    // Period 1

input int                  Input_period_2          = 20;    // Period 2

input group             "Arrow"

input uchar                Inp_Arrow_BUY_Code      = 241;   // BUY: symbol code from the Wingdings font

input int                  Inp_Arrow_BUY_Shift     = 10;    // BUY: vertical shift of arrows in pixels

input uchar                Inp_Arrow_SELL_Code     = 242;   // SELL: symbol code from the Wingdings font

input int                  Inp_Arrow_SELL_Shift    = 10;    // SELL: vertical shift of arrows in pixels

//--- indicator buffers

double   DecBuffer[];

double   BUYBuffer[];

double   SELLBuffer[];

double   Period_1_Buffer[];

double   Period_2_Buffer[];

//---

int      MINBAR=5;

double   a1, a1k, a1l, a2, a2k, a2l;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,DecBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BUYBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,SELLBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,Period_1_Buffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,Period_2_Buffer,INDICATOR_CALCULATIONS);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(1,PLOT_ARROW,Inp_Arrow_BUY_Code);

   PlotIndexSetInteger(2,PLOT_ARROW,Inp_Arrow_SELL_Code);

//--- Set the vertical shift of arrows in pixels

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,Inp_Arrow_BUY_Shift);

   PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,-Inp_Arrow_SELL_Shift);

//--- Set as an empty value 0

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//---

   double k = M_SQRT1_2 * 2 * M_PI;

   double t1 = (MathCos(k / Input_period_1) + MathSin(k / Input_period_1) - 1) / MathCos(k / Input_period_1);

   a1 = 1 - t1;

   a1k = 1 - t1 / 2;

   a1k *= a1k;

   a1l = MathPow(a1, 2);

   a1 *= 2;

   double t2 = (MathCos(k / Input_period_2) + MathSin(k / Input_period_2) - 1) / MathCos(k / Input_period_2);

   a2 = 1 - t2;

   a2k = 1 - t2 / 2;

   a2k *= a2k;

   a2l = MathPow(a2, 2);

   a2 *= 2;

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const int begin,

                const double &price[])

  {

//---

   if(rates_total<MINBAR)

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      limit=MINBAR;

      for(int i=0; i<=limit; i++)

        {

         DecBuffer[i]=EMPTY_VALUE;

         BUYBuffer[i]=EMPTY_VALUE;

         SELLBuffer[i]=EMPTY_VALUE;

         Period_1_Buffer[i]=0.0;

         Period_2_Buffer[i]=0.0;

        }

     }

//--- main loop

   for(int i=limit; i<rates_total; i++)

     {

      Period_1_Buffer[i] = a1k * (price[i] - 2 * price[i - 1] + price[i - 2]) +

                           a1 * Period_1_Buffer[i - 1] - a1l * Period_1_Buffer[i - 2];

      Period_2_Buffer[i] = a2k * (price[i] - 2 * price[i - 1] + price[i - 2]) +

                           a2 * Period_2_Buffer[i - 1] - a2l * Period_2_Buffer[i - 2];

      DecBuffer[i] = Period_2_Buffer[i] - Period_1_Buffer[i];

      //--- Arrow

      BUYBuffer[i]=EMPTY_VALUE;

      SELLBuffer[i]=EMPTY_VALUE;

      if(DecBuffer[i-1]<0.0 && DecBuffer[i]>0.0)

         BUYBuffer[i]=0.0;

      if(DecBuffer[i-1]>0.0 && DecBuffer[i]<0.0)

         SELLBuffer[i]=0.0;

     }

//--- return value of prev_calculated for next call

   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 ---