How to read data from a cloed bar on an higher timeframe

 

Hello all. I am bit unsure about the right procedure to retrieve data from an higher timeframe.

I was trying to read the value of MACD from an higher timeframe, exactly the 4H chart looping through the data index on the 60 Minutes to show with two arrows where the signal started or not.

I had a look on few scripts and I noticed two functions:

ArrayCopySeries and Ibarshift

The first function should copy the whole Time array into another array that I can loop but I am not sure which index should correspond since the 4h contains 1h bar as well.

I used for the purpose Ibarshift in this way:


Counted_bars = IndicatorCounted(); // Number of counted bars
   i = Bars - Counted_bars - 1;           // Index of the first uncounted
   while(i >= 0) {
      
      ///I used prevbar to look at the preceding bar since I want to check the value when it's unfolded
      prevBar = i + 1;
      macdHist = iCustom(Symbol(), Period(), "MACD_Complete", 0, iBarShift(Symbol(), PERIOD_H4, prevBar, false));
      macdLine = iCustom(Symbol(), Period(), "MACD_Complete", 1, iBarShift(Symbol(), PERIOD_H4, prevBar, false));
      macdSignal = iCustom(Symbol(), Period(), "MACD_Complete", 2, iBarShift(Symbol(), PERIOD_H4, prevBar, false));
      //this function gets the value of CCI for the current timeframe in use the sixty-minute chart.
      cci1 = iCCI(Symbol(), Period(), fastcci, PRICE_TYPICAL, i);
      cci2 = iCCI(Symbol(), Period(), slowcci, PRICE_TYPICAL, i);
      c1[i] = cci1;
      c2[i] = cci2;

}

etc.....

.

Can somebody give me an advice about the right procedure to apply.

Thanks in advance, Francesco.

 
zen4x:

Hello all. I am bit unsure about the right procedure to retrieve data from an higher timeframe.

I was trying to read the value of MACD from an higher timeframe,


 macdHist = iCustom(Symbol(), Period(), "MACD_Complete", 0, iBarShift(Symbol(), PERIOD_H4, prevBar, false

  1. Don't write incomprehensible code like that. Separate the parts so you can read it.
  2. You're passing an int to iBarShift where it requires a TIME
  3. You're calling iCustom with the current chart time frame but a H4 shift.
   while(i >= 0) {
      
      ///I used prevbar to look at the preceding bar since I want to check the value when it's unfolded
      int prevBar = i + 1;
      int prevBarH4 = iBarShift(Symbol(), PERIOD_H4, Time[prevBar]);
      macdHist   = iCustom(Symbol(), PERIOD_H4, "MACD_Complete", 0, prevBarH4);
      macdLine   = iCustom(Symbol(), PERIOD_H4, "MACD_Complete", 1, prevBarH4);
      macdSignal = iCustom(Symbol(), PERIOD_H4, "MACD_Complete", 2, prevBarH4);
 
zen4x:

Hello all. I am bit unsure about the right procedure to retrieve data from an higher timeframe.

I was trying to read the value of MACD from an higher timeframe, exactly the 4H chart looping through the data index on the 60 Minutes to show with two arrows where the signal started or not.

I had a look on few scripts and I noticed two functions:

ArrayCopySeries and Ibarshift

The first function should copy the whole Time array into another array that I can loop but I am not sure which index should correspond since the 4h contains 1h bar as well.

I used for the purpose Ibarshift in this way:


Can somebody give me an advice about the right procedure to apply.

Thanks in advance, Francesco.

Hi zen4x,

DL the attachment please

Files:
Reason: