Breakdown OHLC

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Breakdown OHLC
ÿþ//+------------------------------------------------------------------+

//|                                               Breakdown OHLC.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.000"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_plots   1

//--- plot Crossing

#property indicator_label1  "Breakdown"

#property indicator_type1   DRAW_COLOR_ARROW

#property indicator_color1  clrRoyalBlue,clrOrangeRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input uchar    InpCode  = 174;         // Arrow code for style DRAW_ARROW (font Wingdings)

//--- indicator buffers

double         BreakdownBuffer[];

double         BreakdownColors[];

double         arrow_shift=0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BreakdownBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BreakdownColors,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpCode);

//--- an empty value for plotting, for which there is no drawing

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   arrow_shift=Point()*3.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);

//--- main loop

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      BreakdownBuffer[0]=0.0;

      BreakdownColors[0]=0.0;

      limit=1;

     }

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

     {

      BreakdownBuffer[i]=0.0;

      BreakdownColors[i]=0.0;

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

        {

         BreakdownBuffer[i]=high[i]+arrow_shift;

         BreakdownColors[i]=0.0;

         continue;

        }

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

        {

         BreakdownBuffer[i]=low[i]-arrow_shift;

         BreakdownColors[i]=1.0;

         continue;

        }

     }

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

   return(rates_total);

  }

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

//| Filling indicator buffers from the MA indicator                  |

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

bool FillArrayFromBuffer(double &values[],   // indicator buffer of Moving Average values

                         int shift,          // shift

                         int ind_handle,     // handle of the iMA indicator

                         int amount          // number of copied values

                        )

  {

//--- reset error code

   ResetLastError();

//--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index

   if(CopyBuffer(ind_handle,0,-shift,amount,values)<0)

     {

      //--- if the copying fails, tell the error code

      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated

      return(false);

     }

//--- everything is fine

   return(true);

  }

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

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