OHLC breakdown

Author: Copyright © 2020, Vladimir Karputov
2 Views
0 Downloads
0 Favorites
OHLC breakdown
ÿþ//+------------------------------------------------------------------+

//|                                               OHLC breakdown.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

#property copyright "Copyright © 2020, Vladimir Karputov"

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

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_plots   4

//--- plot Upper

#property indicator_label1  "Upper"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Up

#property indicator_label2  "Up"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrLimeGreen

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot Low

#property indicator_label3  "Low"

#property indicator_type3   DRAW_ARROW

#property indicator_color3  clrLightSkyBlue

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- plot Lower

#property indicator_label4  "Lower"

#property indicator_type4   DRAW_ARROW

#property indicator_color4  clrTomato

#property indicator_style4  STYLE_SOLID

#property indicator_width4  1

//--- input parameters

input group             "Upper"

input uchar    InpUpperCode      = 159;   // Upper: symbol code from the Wingdings font

input int      InpUpperShift     = 15;    // Upper: vertical shift of arrows in pixels

input group             "Up"

input uchar    InpUpCode         = 159;   // Up: symbol code from the Wingdings font

input int      InpUpShift        = 5;     // Up: vertical shift of arrows in pixels

input group             "Low"

input uchar    InpLowCode        = 159;   // Low: symbol code from the Wingdings font

input int      InpLowShift       = 5;     // Low: vertical shift of arrows in pixels

input group             "Lower"

input uchar    InpLowerCode      = 159;   // Lower: symbol code from the Wingdings font

input int      InpLowerShift     = 15;    // Lower: vertical shift of arrows in pixels

//--- indicator buffers

double   UpperBuffer[];

double   UpBuffer[];

double   LowBuffer[];

double   LowerBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,UpperBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,UpBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,LowerBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpUpperCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpUpCode);

   PlotIndexSetInteger(2,PLOT_ARROW,InpLowCode);

   PlotIndexSetInteger(3,PLOT_ARROW,InpLowerCode);

//--- setting a vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-InpUpperShift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-InpUpShift);

   PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,InpLowShift);

   PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,InpLowerShift);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(3,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)

     {

      UpperBuffer[0]=0.0;

      UpBuffer[0]=0.0;

      LowBuffer[0]=0.0;

      LowerBuffer[0]=0.0;

      limit=1;

     }

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

     {

      //--- previous bar

      UpperBuffer[i-1]=0.0;

      UpBuffer[i-1]=0.0;

      LowBuffer[i-1]=0.0;

      LowerBuffer[i-1]=0.0;

      //--- current bar

      UpperBuffer[i]=0.0;

      UpBuffer[i]=0.0;

      LowBuffer[i]=0.0;

      LowerBuffer[i]=0.0;

      if(open[i-1]<close[i-1] && open[i]>close[i]) // previous bar bullish and current bar bearish

        {

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

            UpBuffer[i-1]=high[i-1];

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

            UpperBuffer[i-1]=high[i-1];

         //---

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

            LowBuffer[i-1]=low[i-1];

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

            LowerBuffer[i-1]=low[i-1];

         //---

         continue;

        }

      if(open[i-1]>close[i-1] && open[i]<close[i]) // previous bar bearish and current bar bullish

        {

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

            UpBuffer[i-1]=high[i-1];

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

            UpperBuffer[i-1]=high[i-1];

         //---

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

            LowBuffer[i-1]=low[i-1];

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

            LowerBuffer[i-1]=low[i-1];

        }

     }

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