# Simple question about closing Price!

82

Hi all,

i only want a line of close price H1 in timeframe M5. I am using this code but.... i dont understand where i am failing:

```int start()

{

int counted_bars=IndicatorCounted();

if(counted_bars>0)
counted_bars--;

int limit=Bars-counted_bars;

for(int i=limit;i>=0;i--)

{

int shift=iBarShift(NULL,PERIOD_H1,iTime(NULL,Period(),i));

h1Value[i]=iClose(NULL,PERIOD_H1,shift);

}

return(0);

}

```

Thank you very much

82

i dont understand when i have to use iBarshift.

Anyone can explain me and of this way maybe i understand where i am failing in the code above.

Thank you very much!!

16096

1. No need for the decrement Contradictory information on IndicatorCounted() - MQL4 forum
```int counted = IndicatorCounted();
int lookback = ... // iMA(period) has look back of period.
// buffer[i+2] has look back of 2
// use maximum of all.
for(int iBar = Bars - 1 - MathMax(lookback, counted); iBar >= 0; --iBar) ...
```

2. `iTime(NULL,Period(),i)`
This is identical to Time[i]
3. Since the close[0] changes per tick, you must change the above to repaint all M5 bars that are part of the H1[0]
```datetime Time0H1 = Time[0] - Time[0] % 3600;  // Start of the H1 bar zero
int iH1_0 = iBarShift(NULL, 0, Time0H1);      // Bar starting H1
int iLast = Bars - 1 - MathMax(lookback, counted);
for(int iBar = MathMax(iH1_0, iLast); iBar >= 0; --iBar) ...```
82

Thank you very much WHRoeder,

i am going to study your message and prove. I think i understand  but like always i use the same structure, it can that i coded wrong

82

```int counted=IndicatorCounted();

int lookback=200;

datetime Time0H1 = Time[0] - Time[0] % 3600;  // Start of the H1 bar zero
int iH1_0 = iBarShift(NULL, 0, Time0H1);      // Bar starting H1
int iLast = Bars - 1 - MathMax(lookback, counted);
for(int iBar = MathMax(iH1_0, iLast); iBar >= 0; --iBar)
{

h1Value[iBar]=iClose(NULL,PERIOD_H1,iH1_0);

}

return(0);
}```

I prove this code. Still i have some errors...