Reverse No Repair

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each barSeries array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
Reverse No Repair
ÿþ//+------------------------------------------------------------------+

//|                                                     Reverse No Repair.mq4 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_chart_window



#property indicator_buffers 2

#property indicator_plots 2

#property indicator_color1 clrRed

#property indicator_width1 1

#property indicator_type1 DRAW_ARROW





#property indicator_color2 clrBlue

#property indicator_width2 1

#property indicator_type2 DRAW_ARROW



input int FilterCandle=12;

double bufferUp[];

double bufferDown[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,bufferUp);

   SetIndexBuffer(1,bufferDown);

   SetIndexArrow(0,233);

   SetIndexArrow(1,234);



   ArraySetAsSeries(bufferDown,true);

   ArraySetAsSeries(bufferUp,true);

//---

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

  {

//---

   int limit;

   if(prev_calculated>0)

      limit=rates_total-prev_calculated -1;

   else

      limit=rates_total -1;



   for(int i=limit; i>=0; i--)

     {

      if(i+FilterCandle+2<rates_total)

        {

         if(isUp(i+1))

           {



            bufferUp[i+2]=low[i+2];

           }

         else if(isDown(i+1))

           {



            bufferDown[i+2]=high[i+2];

           }

        }

     }



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

   return(rates_total);

  }

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



bool isUp(int index)

  {

   bool flag=true;

   int preIndex=index+1;

   if(

      iLow(Symbol(),0,index)>iLow(Symbol(),0,preIndex)

      && iHigh(Symbol(),0,index)>iHigh(Symbol(),0,preIndex)

      && iClose(Symbol(),0,index)>iClose(Symbol(),0,preIndex)

      )

     {

      int startIndex=preIndex+1;

      int endIndex=preIndex+FilterCandle-1;

      for(int i=startIndex; i<=endIndex; i++)

        {

         if(iLow(Symbol(),0,i)<iLow(Symbol(),0,preIndex))

           {

            flag=false;

            break;

           }

        }

     }

   else

     {

      flag=false;

     }



   return flag;

  }

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



bool isDown(int index)

  {

   bool flag=true;

   int preIndex=index+1;

   if(

      iLow(Symbol(),0,index)<iLow(Symbol(),0,preIndex)

      && iHigh(Symbol(),0,index)<iHigh(Symbol(),0,preIndex)

      && iClose(Symbol(),0,index)<iClose(Symbol(),0,preIndex)

      )

     {

      int start=preIndex+1;

      int end=preIndex+FilterCandle-1;

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

        {

         if(iHigh(Symbol(),0,i)>iHigh(Symbol(),0,preIndex))

           {

            flag=false;

            break;

           }

        }

     }

   else

     {

      flag=false;

     }



   return flag;

  }

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

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