Originally Posted by jcl
Which price exactly does not match with which one?


I was just trying to understand what BarPeriod does when using the bar function, since I am not clear on what the manual says. However, I am not actually using bar now for what I am working on.

Anyhow, when I ran SpecialBars.c with BarPeriod = 1, setting the dates and the asset to my own and turning on logging, the log entries are "correct" as shown in my original post. The bars are timestamped in the log exactly when the OHLC data completes a Renko bar. On the other hand, with BarPeriod = 1440, the log entries are nowhere near the actual value of the Renko bar, which is what I meant when I said the prices do not match.

While I don't know what BarPeriod really does here, I wanted to point out that the code in the script for the function Renko1 is incorrect. I am not sure if that has something do with what I am seeing with the large BarPeriod. It is incorrect because it is possible for the price to move by more than
Code
2 * BarRange
in one OHLCV bar and then Close[0] will not get the correct value.

Here is what I think it should be:
Code
// Renko Bars, variant 1 
int Renko(vars Open, vars High, vars Low, vars Close)
{
  Open[0] = round(Close[1], BarRange);
  var delta = Close[0] - Open[0];
  if (delta >= BarRange) {
    int num_ranges = floor(delta / BarRange);
    Close[0] = Open[0] + num_ranges * BarRange;
    High[0] = Close[0];
    Low[0] = Open[0];
    return 1;
  }
  if (delta <= -BarRange) {
    int num_ranges = floor(-delta / BarRange);
    Close[0] = Open[0] - num_ranges * BarRange;
    High[0] = Open[0];
    Low[0] = Close[0];
    return 1;
  }
  return 4;
}