Pattern Support Resistance Indicator

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Pattern Support Resistance Indicator
ÿþ//+------------------------------------------------------------------+

//|                         Pattern Support Resistance Indicator.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot Buy

#property indicator_label1  "Buy"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrRoyalBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Sell

#property indicator_label2  "Sell"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrOrangeRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- indicator buffers

double   ExtBuyBuffer[];

double   ExtSellBuffer[];

//---

int      ExtDigits   = 0;  //

datetime ExtPrevBars = 0;  // "0" -> D'1970.01.01 00:00';

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,ExtBuyBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtSellBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,241);

   PlotIndexSetInteger(1,PLOT_ARROW,242);

//--- sets first bar from which index will be drawn 

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,1);

//--- sets drawing line to empty value 

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,15);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-15);

//--

   ExtDigits=(Digits()>0)?Digits()-1: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<9)

      return(0);



   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      ArrayInitialize(ExtBuyBuffer,0.0);

      ArrayInitialize(ExtSellBuffer,0.0);

      limit=2;

      ExtPrevBars=0;

     }

//--- we work only at the time of the birth of new bar

   if(time[rates_total-1]==ExtPrevBars)

      return(rates_total);

   ExtPrevBars=time[rates_total-1];



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

     {

      ExtBuyBuffer[i]=0.0;

      ExtSellBuffer[i]=0.0;



      if(CompareDoubles(low[i-2],low[i-1],ExtDigits))

        {

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

           {

            ExtBuyBuffer[i]=low[i];

            ExtSellBuffer[i]=0.0;

           }

        }

      else if(CompareDoubles(high[i-2],high[i-1],ExtDigits))

        {

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

           {

            ExtBuyBuffer[i]=0.0;

            ExtSellBuffer[i]=high[i];

           }

        }

     }

//---



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

   return(rates_total);

  }

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

//| Compare doubles                                                  |

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

bool CompareDoubles(double number1,double number2,int digits)

  {

   digits--;

   if(digits<0)

      digits=0;

   if(NormalizeDouble(number1-number2,digits)==0)

      return(true);

   else

      return(false);

  }

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

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