Ichimoku MTF Kijun line MQL5

 

Hello I'm trying to write indicator that show me Kijunsen line from various timeframes but something is wrong, can anyone help? 

//+------------------------------------------------------------------+
//|                                                        H1 KJ.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window 

#property indicator_chart_window 
#property indicator_buffers 1  
#property indicator_plots   1
#property indicator_color1 Blue  
#property indicator_type1   DRAW_LINE

input  ENUM_TIMEFRAMES TimeFrame=0; 
int kijun =26; 

double KijunBuffer[]; 
int a_begin; 
int k =1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   k=1;
   if (TimeFrame>0)
//----
    SetIndexBuffer(0,KijunBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,kijun);
    PlotIndexSetString(0,PLOT_LABEL,"Kijun-sen("+string(kijun)+")"); 
    
     ArraySetAsSeries(KijunBuffer,true);
//---
   
  }
//+------------------------------------------------------------------+
//| 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,pos; 
 double high1,low1,price;
 int    counted_bars=prev_calculated;

limit=rates_total-counted_bars-1;
   if (limit>1) {
      limit=rates_total-kijun-1;
   }
   for (i=limit;i>=0;i--) {
      pos=iBarShift(NULL, TimeFrame, time[i]);
      high1=iHigh(NULL, TimeFrame,iHighest(NULL,TimeFrame,MODE_HIGH, kijun, pos));
      low1 =iLow(NULL,TimeFrame, iLowest( NULL,TimeFrame,MODE_LOW,  kijun, pos));
      price=(high1+low1)*0.5;
      KijunBuffer[i]=price; 
     }
   
//--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+
 
Michał Lipa :

Hello I'm trying to write indicator that show me Kijunsen line from various timeframes but something is wrong, can anyone help? 

Why do you use iBarShift, iHigh and iLow - you already have ready-made arrays:

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[])