Behaviour of user-defined bars

Posted By: JamesHH

Behaviour of user-defined bars - 02/08/20 07:29

I am testing a strategy based on Renko bars, by setting
Code
bar = Renko1
where Renko1 is from SpecialBars.c. First I ran it with
Code
BarPeriod = 1
and
Code
BarRange = 500.0
and everything went as expected. For example, in the log I have:

Code
[1: Sun 17-12-17 23:02] (19000.00)
[2: Mon 17-12-18 00:33] (18500.00)
[3: Mon 17-12-18 01:00] (18000.00)
...


and I can see in ZHistoryEditor that at the end of bar 2, the close price dips below 18500 for the first time at 00:33.

Then I wanted daily granularity rather than 1-min. The manual says BarPeriod only affects the start time and the number of allocated bars, but I tried
Code
BarPeriod = 1440
anyhow. The results made no sense to me. From the log:

Code
[1: Tue 17-12-19 09:00] (18500.00)
[2: Wed 17-12-20 02:45] (18000.00)
[3: Wed 17-12-20 18:26] (17500.00)
[4: Thu 17-12-21 10:06] (17000.00)


However, at 17-12-20 02:45 the price is nowhere near 18000 (same for all of the entries). Is this some bug, or else why is the log showing these close times for the Renko bars?
Posted By: Petra

Re: Behaviour of user-defined bars - 02/08/20 09:03

Well Barperiod = 1440 is wrong. Renko bars have no daily granularity. The manual has a chapter on special bars and there is also mentioned how you must set the bar period.

https://manual.zorro-project.com/bar.htm

The prices of some special bars are artificial but I believe renko bars have the real prices. So I dont know the problem with your prices but if you need help in detail you can get a support ticket and contact Support.
Posted By: JamesHH

Re: Behaviour of user-defined bars - 02/08/20 17:47

Originally Posted by Petra
Well Barperiod = 1440 is wrong. Renko bars have no daily granularity. The manual has a chapter on special bars and there is also mentioned how you must set the bar period.

https://manual.zorro-project.com/bar.htm

The prices of some special bars are artificial but I believe renko bars have the real prices. So I dont know the problem with your prices but if you need help in detail you can get a support ticket and contact Support.


Yes, I read the manual page.

My post wasn't very clear, but I am pointing out the strange behaviour when BarPeriod = 1440, with *your* script SpecialBars.c.

I can submit a bug report if you can't explain why the prices don't match and want to fix it.
Posted By: jcl

Re: Behaviour of user-defined bars - 02/11/20 11:25

Which price exactly does not match with which one?
Posted By: JamesHH

Re: Behaviour of user-defined bars - 02/13/20 03:05

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;
}
Posted By: Petra

Re: Behaviour of user-defined bars - 02/15/20 13:34

I understand from the manual under "bars" that a totally wrong bar period will result in not enough allocated bars. I dont know what consequences that has on prices but suppose that many things will then not work.

You code seems to allow the renko bars to have a multiple of their bar range, are you sure this is correct? I always thought that Renko bars must not exceed their bar range.
Posted By: JamesHH

Re: Behaviour of user-defined bars - 02/18/20 18:41

Originally Posted by Petra
I understand from the manual under "bars" that a totally wrong bar period will result in not enough allocated bars. I dont know what consequences that has on prices but suppose that many things will then not work.


The manual states "Set BarPeriod at the approximate average bar duration, in order to allocate enough bars for the lookback period." While I don't exactly understand this, since LookBack = 0 in the SpecialBars.c script can we not assume that there are always enough allocated bars?

Quote

You code seems to allow the renko bars to have a multiple of their bar range, are you sure this is correct? I always thought that Renko bars must not exceed their bar range.


Yes, I am new to TA. I assumed that the bar size should be the greatest multiple of the bar range within the price move, but probably they should all be the same size as you explained.
© 2024 lite-C Forums