Highest _ Lowest Indicator

Author: Saullo Algotrader
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
2 Views
0 Downloads
0 Favorites
Highest _ Lowest Indicator
ÿþ//+------------------------------------------------------------------+

//|                                   Highest   Lowest Indicator.mq5 |

//|                                                Saullo Algotrader |

//|                   https://www.instagram.com/saulloop_algotrader/ |

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

#property copyright "Saullo Algotrader"

#property link      "https://www.instagram.com/saullo_algotrader/"

#property version   "1.20"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots 2

//indicator buffers 1

#property indicator_label1 "Highest"

#property indicator_type1 DRAW_LINE

#property indicator_color1 clrRed

#property indicator_style1 STYLE_DASH

#property indicator_width1  1

//indicator buffer 2

#property indicator_label2 "Lowest"

#property indicator_type2 DRAW_LINE

#property indicator_color2 clrRed

#property indicator_style2 STYLE_DASH

#property indicator_width2  1

//--- input parameters

input int       Range_n = 20;//Range

//--- buffers



double HiBuffer[], LoBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//---

   SetIndexBuffer(0,HiBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,LoBuffer,INDICATOR_DATA);



   PlotIndexSetInteger(0,PLOT_LINE_STYLE,1);

   PlotIndexSetInteger(1,PLOT_LINE_STYLE,1);



   IndicatorSetInteger(INDICATOR_DIGITS, _Digits);



   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Range_n);

   PlotIndexSetInteger(0,PLOT_SHIFT,0);



   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,Range_n);

   PlotIndexSetInteger(1,PLOT_SHIFT,0);



   IndicatorSetString(INDICATOR_SHORTNAME, "Highest   Lowest Indicator"+Range_n);

   

   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 < Range_n+1)

     {

      Print("Not enough data to calculate");

      return(0);

     }

//calculate

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

     {

      double xHig = 0.0;

      double xLo = 0.0;

      HiBuffer[i]=xHig;

      LoBuffer[i]=xLo;

      if(i>Range_n)

        {

         int iHi=iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,Range_n,rates_total-i);        //Highest bar in n bars

         xHig=iHigh(_Symbol,PERIOD_CURRENT,iHi);                  //Value of highest in n bars

         HiBuffer[i-1]=xHig;



         int iLo=iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,Range_n,rates_total-i);          //Lowest bar in n bars

         xLo=iLow(_Symbol,PERIOD_CURRENT,iLo);                    //Value of lowest in n bars

         LoBuffer[i-1]=xLo;

        }

     }

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