Bearish Bullish Engulfing

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

//|                                    Bearish Bullish Engulfing.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                      https://www.mql5.com/en/users/barabashkakvn |

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

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/en/users/barabashkakvn"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot BearishHarami

#property indicator_label1  "Bearish Engulfing"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot BullishHarami

#property indicator_label2  "Bullish Engulfing"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uchar                Inp_Bearish_Code        = 164;         // Bearish Engulfing: symbol code from the Wingdings font

input uchar                Inp_Bullish_Code        = 164;         // Bullish Engulfing: vertical shift of arrows in pixels

input int                  Inp_Arrow_Shift         = 10;          // Vertical shift of arrows in pixels

//--- indicator buffers

double   BearishEngulfingBuffer[];

double   BullishEngulfingBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BearishEngulfingBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BullishEngulfingBuffer,INDICATOR_DATA);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//--- define the symbol code for drawing in PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,Inp_Bearish_Code);

   PlotIndexSetInteger(1,PLOT_ARROW,Inp_Bullish_Code);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,Inp_Arrow_Shift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-Inp_Arrow_Shift);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

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

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      BearishEngulfingBuffer[0]=0.0;

      BullishEngulfingBuffer[0]=0.0;

      limit=1;

     }

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

     {

      BearishEngulfingBuffer[i]=0.0;

      BullishEngulfingBuffer[i]=0.0;

      //--- Bearish Engulfing

      if(open[i-1]<close[i-1])

         if(open[i]>close[i])

            if(close[i]<open[i-1])

               if(open[i]>close[i-1])

                  BearishEngulfingBuffer[i]=low[i];

      //--- Bullish Engulfing

      if(open[i-1]>close[i-1])

         if(open[i]<close[i])

            if(close[i]>open[i-1])

               if(open[i]<close[i-1])

                  BullishEngulfingBuffer[i]=high[i];

     }

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