MTF one bar

Author: Alexey Viktorov
Price Data Components
Series array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
MTF one bar
ÿþ/********************************************************************\

|                                                    MTF one bar.mq4 |

|                                            © 2024, Alexey Viktorov |

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

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

#property copyright "Alexey Viktorov"

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

#property version   "1.00"

#property strict

#property indicator_chart_window

#property indicator_buffers      	4

#property indicator_type1					DRAW_HISTOGRAM

#property indicator_type2					DRAW_HISTOGRAM

#property indicator_type3					DRAW_HISTOGRAM

#property indicator_type4					DRAW_HISTOGRAM

#property indicator_color1       	clrBlueViolet

#property indicator_color2       	clrBlueViolet

#property indicator_color3       	clrBlueViolet

#property indicator_color4       	clrBlueViolet

#property indicator_width1       	3

#property indicator_width2       	3

#property indicator_width3       	1

#property indicator_width4       	1

//---

input	ENUM_TIMEFRAMES tf 		= PERIOD_CURRENT;	//	TIMEFRAM >B>1@0605<>3> 10@0

input	int							shift	=	3;							//	A4283 2?@02> >B B5:CI53> 10@0

double buff_O[],

       buff_C[],

       buff_H[],

       buff_L[];

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

|               Custom indicator initialization function              |

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

int OnInit()

 {

  string lablTF = StringSubstr(EnumToString(tf), 7);

  IndicatorDigits(Digits);

  SetIndexBuffer(0, buff_O);

  SetIndexBuffer(1, buff_C);

  SetIndexBuffer(2, buff_H);

  SetIndexBuffer(3, buff_L);

  SetIndexLabel(0,"Open_"+lablTF);

  SetIndexLabel(1,"Close_"+lablTF);

  SetIndexLabel(2,"High_"+lablTF);

  SetIndexLabel(3,"Low_"+lablTF);

  SetIndexShift(0, shift);

  SetIndexShift(1, shift);

  SetIndexShift(2, shift);

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

   {

    ArrayInitialize(buff_O, EMPTY_VALUE);

    ArrayInitialize(buff_H, EMPTY_VALUE);

    ArrayInitialize(buff_L, EMPTY_VALUE);

    ArrayInitialize(buff_C, EMPTY_VALUE);

   }

  static datetime time_1 = 0;

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

  if(prev_calculated != rates_total || time_1 < currTime)

   {

    buff_O[1] = EMPTY_VALUE;

    buff_H[1] = EMPTY_VALUE;

    buff_L[1] = EMPTY_VALUE;

    buff_C[1] = EMPTY_VALUE;

    buff_O[0] = EMPTY_VALUE;

    buff_H[0] = EMPTY_VALUE;

    buff_L[0] = EMPTY_VALUE;

    buff_C[0] = EMPTY_VALUE;

    time_1 = currTime;

   }

  double tf_open 	= iOpen(_Symbol, tf, 0);

  double tf_high 	= iHigh(_Symbol, tf, 0);

  double tf_low 	= iLow(_Symbol, tf, 0);

  double tf_close = iClose(_Symbol, tf, 0);

  buff_O[0] = tf_open;

  buff_C[0] = tf_close;

  buff_H[0] = tf_high;

  buff_L[0] = tf_low;

//---

  return(rates_total);

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



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

void OnDeinit(const int reason)

 {

  Comment("");

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

Comments