Fetch Indicator values from higher timeframe

 

Any idea to fetch indicator values from higher timeframe to current time frame 

I have written this code which is not giving correct result.

//+------------------------------------------------------------------+
//|                                                  CCI_Sampled.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      LookBackPeriod=50;
//--- indicator buffers
double         Label1Buffer[], prevDayHigh[];
int handle_1,sma;
input double step = 0.02;
input double maximum = 0.2;
int handle; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,prevDayHigh,INDICATOR_CALCULATIONS);
  handle = iMA(Symbol(),PERIOD_D1,LookBackPeriod,0,MODE_SMA,PRICE_CLOSE);
  //handle=iSAR(Symbol(),PERIOD_D1,step,maximum);
   
//---
   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[])
  {
CopyBuffer(handle,0,0,rates_total,Label1Buffer);
  return(rates_total);
  }

Need something like this


 

Learn to search!

E.g. "multi timeframe" would have you given this (beside others): https://www.mql5.com/en/articles/13578

Creating multi-symbol, multi-period indicators
Creating multi-symbol, multi-period indicators
  • www.mql5.com
In this article, we will look at the principles of creating multi-symbol, multi-period indicators. We will also see how to access the data of such indicators from Expert Advisors and other indicators. We will consider the main features of using multi-indicators in Expert Advisors and indicators and will see how to plot them through custom indicator buffers.
 
Carl Schreiber #:

Learn to search!

E.g. "multi timeframe" would have you given this (beside others): https://www.mql5.com/en/articles/13578

Very hard to follow

 
Good morning
I actually looked at the article.
It must be a little simpler, I think
 
  handle = iMA(Symbol(),PERIOD_D1,LookBackPeriod,0,MODE_SMA,PRICE_CLOSE);
⋮
CopyBuffer(handle,0,0,rates_total,Label1Buffer);

You are mixing apples and oranges. Find out what D1 bar corresponds to your charts rates_total-1 bar.