Author: © 2019, Alexey Viktorov
Indicators Used
MACD HistogramMoving Average of Oscillator
0 Views
0 Downloads
0 Favorites
MACD OsMA
ÿþ//+------------------------------------------------------------------+

//|                                                    MACD OsMA.mq5 |

//|                                          © 2019, Alexey Viktorov |

//|                     https://www.mql5.com/ru/users/alexeyvik/news |

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

#property copyright "© 2019, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property indicator_separate_window



#property indicator_buffers 5

#property indicator_plots   3



#property indicator_width1  2

#property indicator_color1  clrYellow, clrGreenYellow

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrRed

//#property indicator_type3   DRAW_COLOR_HISTOGRAM

#property indicator_color3  clrMediumVioletRed, clrMediumBlue

#property indicator_width3  2

enum TypeOfIndicator

{

 COLOR_HISTOGRAM,

 COLOR_LINE

};



sinput  group               "0@0<5B@K MACD"

sinput  TypeOfIndicator     TypeMACD        = COLOR_LINE;   //  Type MACD

 input  int                 MACD_fast_ema   = 12;           //  Fast EMA

 input  int                 MACD_slow_ema   = 26;           //  Slow EMA

 input  int                 MACD_signal     = 9;            //  MACD SMA

 input  ENUM_APPLIED_PRICE  MACD_appled     = PRICE_CLOSE;  //  Appled price

sinput  group               "0@0<5B@K OsMA"

sinput  TypeOfIndicator     TypeOsMA        = COLOR_LINE;   //  Type OsMA

 input  int                 OsMA_fast_ema   = 12;           //  Fast EMA

 input  int                 OsMA_slow_ema   = 26;           //  Slow EMA

 input  int                 OsMA_signal     = 9;            //  MACD SMA

 input  ENUM_APPLIED_PRICE  OsMA_appled     = PRICE_CLOSE;  //  Appled price

int handleMACD, handleOsMA;

/****************indicator buffers****************/

double bufMACD_MINE[]

     , bufMACD_SIGN[]

     , bufOsMA_MINE[]

     , colorsMACD[]

     , colorsOsMA[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   //myOnInit();

   SetIndexBuffer(0, bufMACD_MINE);

   if(TypeMACD == COLOR_LINE)

    PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_COLOR_LINE);

   if(TypeMACD == COLOR_HISTOGRAM)

    PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_COLOR_HISTOGRAM);

   PlotIndexSetString(0, PLOT_LABEL, "MACD ("+(string)MACD_fast_ema+", "+(string)MACD_slow_ema+", "+(string)MACD_signal);

   SetIndexBuffer(1, colorsMACD, INDICATOR_COLOR_INDEX);

//---

   SetIndexBuffer(2, bufMACD_SIGN);

   PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrRed);

   PlotIndexSetString(1, PLOT_LABEL, "Signal");

//---

   SetIndexBuffer(3, bufOsMA_MINE);

   if(TypeOsMA == COLOR_LINE)

    PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_COLOR_LINE);

   if(TypeOsMA == COLOR_HISTOGRAM)

    PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_COLOR_HISTOGRAM);

   PlotIndexSetString(2, PLOT_LABEL, "OsMA ("+(string)OsMA_fast_ema+", "+(string)OsMA_slow_ema+", "+(string)OsMA_signal);

   SetIndexBuffer(4, colorsOsMA, INDICATOR_COLOR_INDEX);

//---

   handleMACD = iMACD(_Symbol, PERIOD_CURRENT, MACD_fast_ema, MACD_slow_ema, MACD_signal, MACD_appled);

   handleOsMA = iOsMA(_Symbol, PERIOD_CURRENT, OsMA_fast_ema, OsMA_slow_ema, OsMA_signal, OsMA_appled);

//---

   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[])

  {

//---

   if(rates_total-prev_calculated > 1)

    {

     if(CopyBuffer(handleMACD, 0, 0, rates_total, bufMACD_MINE) < 1) return(0);

     if(CopyBuffer(handleMACD, 1, 0, rates_total, bufMACD_SIGN) < 1) return(0);

     if(CopyBuffer(handleOsMA, 0, 0, rates_total, bufOsMA_MINE) < 1) return(0);

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

      {

       colorsMACD[i] = bufMACD_MINE[i] > bufMACD_MINE[i-1] ? 1 : 0;

       colorsOsMA[i] = bufOsMA_MINE[i] > bufOsMA_MINE[i-1] ? 1 : 0;

      }

    }

   else

    {

     if(CopyBuffer(handleMACD, 0, 0, 1, bufMACD_MINE) < 1) return(0);

     if(CopyBuffer(handleMACD, 1, 0, 1, bufMACD_SIGN) < 1) return(0);

     if(CopyBuffer(handleOsMA, 0, 0, 1, bufOsMA_MINE) < 1) return(0);

     colorsMACD[rates_total-1] = bufMACD_MINE[rates_total-1] > bufMACD_MINE[rates_total-2] ? 1 : 0;

     colorsOsMA[rates_total-1] = bufOsMA_MINE[rates_total-1] > bufOsMA_MINE[rates_total-2] ? 1 : 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 ---