double line

Author: 公众号 Luyuanmw 微信 wentxiong
Indicators Used
MACD Histogram
0 Views
0 Downloads
0 Favorites
double line
ÿþ//+------------------------------------------------------------------+

//|                                                 double line.mq5 |

//|                                        wx-> wentxiong |

//|                                        http://www.popoding.club/ |

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

#property copyright "lQO÷S Luyuanmw ®_áO wentxiong"

#property link      "https://www.mql5.com/zh/users/xiongsir/seller"

#property version   "1.00"

#property indicator_separate_window

#property indicator_buffers 10

#property indicator_plots   7

//--- plot macd

#property indicator_label1  "macd"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot signal

#property indicator_label2  "signal"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot upper

#property indicator_label3  "upper"

#property indicator_type3   DRAW_COLOR_HISTOGRAM

#property indicator_color3  clrBlueViolet,clrDarkGray

#property indicator_style3  STYLE_SOLID

#property indicator_width3  2

//--- plot down

#property indicator_label4  "down"

#property indicator_type4   DRAW_COLOR_HISTOGRAM

#property indicator_color4  clrBlueViolet,clrDarkGray

#property indicator_style4  STYLE_SOLID

#property indicator_width4  2

//--- plot fill

#property indicator_label5  "fill"

#property indicator_type5   DRAW_FILLING

#property indicator_color5  clrRed,clrBlue

#property indicator_style5  STYLE_SOLID

#property indicator_width5  1

//--- plot arrow1

#property indicator_label6  "arrow1"

#property indicator_type6   DRAW_ARROW

#property indicator_color6  clrRed

#property indicator_style6  STYLE_SOLID

#property indicator_width6  1

//--- plot arrow2

#property indicator_label7  "arrow2"

#property indicator_type7   DRAW_ARROW

#property indicator_color7  clrBlue

#property indicator_style7  STYLE_SOLID

#property indicator_width7  1

//--- indicator buffers

double         macdBuffer[];

double         signalBuffer[];

double         upperBuffer[];

double         upperColors[];

double         downBuffer[];

double         downColors[];

double         fillBuffer1[];

double         fillBuffer2[];

double         arrow1Buffer[];

double         arrow2Buffer[];



int macd_handle = 0;



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,macdBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,signalBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,upperBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,upperColors,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4,downBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,downColors,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(6,fillBuffer1,INDICATOR_DATA);

   SetIndexBuffer(7,fillBuffer2,INDICATOR_DATA);

   SetIndexBuffer(8,arrow1Buffer,INDICATOR_DATA);

   SetIndexBuffer(9,arrow2Buffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(5,PLOT_ARROW,225);

   PlotIndexSetInteger(6,PLOT_ARROW,226);



   PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0);



   macd_handle = iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE);

//---

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

  {

//---



   CopyBuffer(macd_handle,0,0,rates_total,macdBuffer);

   CopyBuffer(macd_handle,1,0,rates_total,signalBuffer);





   int start = 1;

   if(prev_calculated > 1)

     {

      start = prev_calculated - 1;

     }



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

     {





      if(macdBuffer[i] > signalBuffer[i])

        {

         upperBuffer[i] = macdBuffer[i] - signalBuffer[i];

        }

      else

        {

         downBuffer[i] = macdBuffer[i] - signalBuffer[i];

        }



      if(upperBuffer[i - 1] < upperBuffer[i])

        {

         upperColors[i] = 0;

        }

      else

        {

         upperColors[i] = 1;

        }

      if(downBuffer[i - 1] > downBuffer[i])

        {

         downColors[i] = 0;

        }

      else

        {

         downColors[i] = 1;

        }



      fillBuffer1[i] = macdBuffer[i];

      fillBuffer2[i] = signalBuffer[i];





      if(macdBuffer[i] > signalBuffer[i] && macdBuffer[i - 1] < signalBuffer[i - 1])

        {

         arrow1Buffer[i] = macdBuffer[i - 1] - 0.0005;

        }

      else

         if(macdBuffer[i] < signalBuffer[i] && macdBuffer[i - 1] > signalBuffer[i - 1])

           {

            arrow2Buffer[i] = macdBuffer[i - 1] + 0.0003 ;

           }

     }



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