Disliked{quote} You would not notice any difference in either 4/5 when using predefined arrays inside oncalc, or timeseries functions for the current sym/tf. The 2 indicators also work differently, the mt4 indicator only uses the chart candle times and decides on new day/week/month on those times, the mt5 indicator gets higher tf times for use, which is where the timeseries functions come in, and decides on new day/week/month times that way. The mt5 indicator could use time[]/open[]/etc arrays inside oncalc.Ignored
I don't really understand much on how timeseries function operates, but I tried to translate the MT4 indicator logic to MT5, but somehow it doesn't appear. I tried to write it with as little timeseries function as possible (I think I only used iTime since TimeMonth and TimeDay is not available), by using the MT4 version as reference in MT5, but it didn't seem to work.
Inserted Code
//+------------------------------------------------------------------+ //| HiLoChannel.mq5 | //| | //+------------------------------------------------------------------+ #property copyright "Testing" #property link "https://www.google.com/" #property description "PrevHiLoChannel" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 3 //---- drawing the levels as lines #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE //---- selection of levels colors #property indicator_color1 clrBlue #property indicator_color2 clrDarkOrange #property indicator_color3 clrNONE //---- selection of line style #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_DOT //---- levels width is equal to 1 #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 //---- display levels labels #property indicator_label1 "Channels Upper" #property indicator_label2 "Channels Lower" #property indicator_label3 "Channels Mid" int min_rates_total; input ENUM_TIMEFRAMES TimeFrame=PERIOD_W1; double PrevWeekHiBuffer[]; double PrevWeekLoBuffer[]; double PrevWeekMidBuffer[]; int fontsize=10; double x; double PrevWeekHi, PrevWeekLo, LastWeekHi, LastWeekLo, PrevWeekMid; string Space; //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=50; //---- setting dynamic arrays as indicator buffers SetIndexBuffer(0,PrevWeekHiBuffer,INDICATOR_DATA); SetIndexBuffer(1,PrevWeekLoBuffer,INDICATOR_DATA); SetIndexBuffer(2,PrevWeekMidBuffer,INDICATOR_DATA); //---- set the position, from which the levels drawing starts PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total); //---- restriction to draw empty values for the indicator PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- indexing buffer elements as time series ArraySetAsSeries(PrevWeekHiBuffer,true); ArraySetAsSeries(PrevWeekLoBuffer,true); ArraySetAsSeries(PrevWeekMidBuffer,true); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"PrevHiLo_Channel"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); 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, i; limit=(rates_total-prev_calculated)-1; for(i=limit; i>=0;i--) { if (high[i+1]>LastWeekHi) LastWeekHi=high[i+1]; if (low[i+1]<LastWeekLo) LastWeekLo=low[i+1]; if(iTime(NULL,TimeFrame,1) != iTime(NULL,TimeFrame,0)) { PrevWeekHi = LastWeekHi; PrevWeekLo = LastWeekLo; LastWeekHi = open[i]; LastWeekLo = open[i]; PrevWeekMid= (PrevWeekHi + PrevWeekLo)/2; } PrevWeekHiBuffer[i]=PrevWeekHi; PrevWeekLoBuffer[i]=PrevWeekLo; PrevWeekMidBuffer[i]=PrevWeekMid; } return(rates_total); }