max_min_3_days

Author: © Alexey Viktorov 2023
0 Views
0 Downloads
0 Favorites
max_min_3_days
ÿþ/*********************************************************************\

|                                                  max_min_3_days.mq5 |

|                                             © 2023, Alexey Viktorov |

|                        https://www.mql5.com/ru/users/alexeyvik/news |

\*********************************************************************/

#property copyright "© Alexey Viktorov 2023"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.30"

#property strict

#property indicator_chart_window

#property indicator_buffers       2

#property indicator_plots         2

#property indicator_type1     DRAW_LINE

#property indicator_color1    clrBlueViolet

#property indicator_width1    2

#property indicator_type2     DRAW_LINE

#property indicator_color2    clrDeepPink

#property indicator_width2    2

//---

input int Days = 3; //  >;8G5AB2> 4=59 4;O 0=0;870?

int shift, days;

datetime time_[];

double high_[],

       low_[],

       buffHigh[],

       buffLow[];

long chartID;

/*********************************************************************\

|               Custom indicator initialization function              |

\*********************************************************************/

int OnInit()

 {

  chartID = ChartID();

  shift = PeriodSeconds(PERIOD_D1)/PeriodSeconds();

  SetIndexBuffer(0, buffHigh);

  SetIndexBuffer(1, buffLow);

  PlotIndexSetString(0, PLOT_LABEL, "High");

  PlotIndexSetString(1, PLOT_LABEL, "Low");

  PlotIndexSetInteger(0, PLOT_SHIFT, _Digits);

  PlotIndexSetInteger(1, PLOT_SHIFT, _Digits);

  PlotIndexSetInteger(0, PLOT_SHIFT, shift);

  PlotIndexSetInteger(1, PLOT_SHIFT, shift);

  days = Days < 1 ? 1 : Days;

  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(prev_calculated == 0)

    return(rates_total);

  if(IsNewBar(PERIOD_D1))

   {

    if(Period() > PERIOD_D1)

     {

      ArrayInitialize(buffHigh, EMPTY_VALUE);

      ArrayInitialize(buffLow, EMPTY_VALUE);

      return(rates_total);

     }

    int copied_time = CopyTime(_Symbol, PERIOD_D1, 0, days+2, time_);// Left Right Middle

    int barsLeft = rates_total-iBarShift(_Symbol, PERIOD_CURRENT, time_[0]),

        bars_Middle = rates_total-iBarShift(_Symbol, PERIOD_CURRENT, time_[1]),

        bars_Right = rates_total-iBarShift(_Symbol, PERIOD_CURRENT, time_[days+1]);

    int indexHigh = ArrayMaximum(high, bars_Middle, bars_Right),

        indexLow = ArrayMinimum(low, bars_Middle, bars_Right);

    ArrayInitialize(buffHigh, EMPTY_VALUE);

    ArrayFill(buffHigh, barsLeft-1, bars_Right-barsLeft, high[indexHigh]);

    ArrayInitialize(buffLow, EMPTY_VALUE);

    ArrayFill(buffLow, barsLeft-1, bars_Right-barsLeft, low[indexLow]);

   }

  return(rates_total);

 }/*******************************************************************/



/**********************Expert OnDeinit function**********************

void OnDeinit(const int reason)

 {

 }/******************************************************************/



/*****************************IsNewBar*******************************/

bool IsNewBar(ENUM_TIMEFRAMES tf)

 {

  datetime tm = iTime(_Symbol, tf, 0);

  static datetime time = 0;

  if(tm != time)

   {

    time = tm;

    return true;

   }

  return false;

 }/*******************************************************************/

Comments