max_min_3_days

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

|                                                  max_min_3_days.mq4 |

|                                             © 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.00"

#property strict

#property indicator_chart_window

#property indicator_buffers      	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

//---

int shift;

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

  SetIndexLabel(0, "High");

  SetIndexLabel(1, "Low");

  IndicatorDigits(_Digits);

  SetIndexShift(0, shift);

  SetIndexShift(1, shift);

  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(IsNewBar(PERIOD_D1))

   {

    int copied_time = CopyTime(_Symbol, PERIOD_D1, 0, 5, time_);

    int bars_L = Bars(_Symbol, PERIOD_CURRENT, time[0], time_[0])-1,

        bars_M = Bars(_Symbol, PERIOD_CURRENT, time[0], time_[1])-1,

        bars_R = Bars(_Symbol, PERIOD_CURRENT, time[0], time_[4])-1;

    int indexHigh = ArrayMaximum(high, bars_M-bars_R, bars_R),

        indexLow = ArrayMinimum(low, bars_M-bars_R, bars_R);

    ArrayInitialize(buffHigh, EMPTY_VALUE);

    ArrayFill(buffHigh, rates_total-bars_L, bars_L-bars_R, high[indexHigh]);

    ArrayInitialize(buffLow, EMPTY_VALUE);

    ArrayFill(buffLow, rates_total-bars_L, bars_L-bars_R, low[indexLow]);

    DebugBreak();

   }

  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