UniRenko Bars Test

Posted By: Hlopetz

UniRenko Bars Test - 01/11/17 23:33

I've made UniRenko bars described here https://www.youtube.com/watch?v=V6QIKEEb-og

The code:
//UniRenko Bars 3rd edition
//////////////////////////////////////////////////////////////
#include <default.c>
var _Open = 0;
var _Close = 0;
var _High = 0;
var _Low = 0;
var _barMax = 0;
var _barMin = 0;
var _fakeOpen = 0;
int _barDirection = 0;
var _openOffset = 0;
var _trendOffset = 0;
var _reversalOffset = 0;
bool _maxExceeded = false;
bool _minExceeded = false;
var _TickTrend = 0;
var _TickReversal = 0;
var _TickOpenOffset = 0;
int _barsCount = 0;
DATE LastTickTime=0;
DATE _StartTime =0;
DATE _passOffset = 0;

var UniRenkoInit(var TickTrend, var TickOpenOffset,var TickReversal)
{
_trendOffset = TickTrend *PIP;
_reversalOffset = TickReversal*PIP;
_openOffset = TickOpenOffset*PIP;

}

int bar(vars Open, vars High, vars Low, vars Close, vars Price, DATE Start, DATE Time)
{
var thisClose =0;

if ( _barsCount == 0 )
{
_Open = Close[0];
_Low = Close[0];
_Close = Close[0];
_High = Close[0];
_barMax = Close[0]+_trendOffset;
_barMin = Close[0]-_trendOffset;

Open[0] = Close[0];
High[0] = Close[0];
Low[0] = Close[0];
_fakeOpen = Close[0];

_barsCount = 1;

LastTickTime = Time;
return 4; //Active, not close
}

if(Time-LastTickTime>= 1./24.){ // If it is a new session
Open[0]=_Open;
High[0]=_High;
Low[0]=_Low;
Close[0] = _Close;
LastTickTime = Time;
_barsCount=0;
return 1;
}

if (Close[0] > _barMax ) _maxExceeded = true;
else _maxExceeded = false;
if (Close[0] < _barMin ) _minExceeded = true;
else _minExceeded = false;

if ( _maxExceeded || _minExceeded )
{

if (_maxExceeded) {
_barDirection = 1;
thisClose = min(Close[0],_barMax);
_High = thisClose;
_barMax = thisClose + _trendOffset; // For the next bar calculation
_barMin = thisClose - _reversalOffset; // For the next bar calculation
}
else {
_barDirection = -1;
thisClose = max(Close[0],_barMin);
_Low = thisClose;
_barMax = thisClose + _reversalOffset; // For the next bar calculation
_barMin = thisClose - _trendOffset; // For the next bar calculation
}



_Close = thisClose;

//Add the new bar
Open[0] = _Open;
Close[0] = _Close;
High[0] = _High;
Low[0] = _Low;

//Prepare for the nex bar
_fakeOpen = thisClose - ( _openOffset * _barDirection ); // For the next bar calculation
_Open = _fakeOpen;
if (_maxExceeded) _Low = _Open;
if (_minExceeded) _High = _Open;


_barsCount = _barsCount + 1;


return 1;

}
//### Update Current Bar
else
{
if (Close[0] > High[0])_High = Close[0];
if (Close[0] < Low[0]) _Low = Close[0];
Open[0] = _Open;
High[0] = _High;
Low[0] = _Low;
_Close = Close[0];
return 4;
}

}

I have trade tick data for Swiss Market Index futures SMA since 21/06/2016 to 06/12/2016:

SMA.t1 file

2016.06.21 06:00:13.000 7883
2016.06.21 06:00:13.000 7880
2016.06.21 06:00:14.000 7884
....
2016.12.06 20:59:47.000 7944
2016.12.06 20:59:59.000 7943

Now I try plot it:

#include <UNIRENKOIII.c>

function run(){

UniRenkoInit(10,10,31);
set(TICKS|PLOTNOW);
History = ".t1";
StartDate =20161108;
EndDate = 20161108;
}

The questions:

1) Why do I see the different results when I change the bar period? The bars should not depend on time.
2) Why the plot is not for StartDate - EndDate range but different when I change the bar period?
3) Does it exist the way to check the start of the day session, night session?
I used if(Time-LastTickTime>= 1./24.){ // If it is a new session
However may be there is a better way?
4) I implemented these above because I try to find best Renko bar sizes for the strategy. Ninja Trader does not allow to loop the brick size of the bars. I hope Zorro is able to help...
I tried to use the similar code:
while(algo(loop("2","8","20")))
{
if(Algo == "2")
UniRenkoInit(2,2,6);
if(Algo == "8")
UniRenkoInit(8,8,21);
else if(Algo == "20")
UniRenkoInit(20,20,41);
}
But failed. It seems to me Zorro does not change the brick size. Is it possible to do what I want?
Posted By: Finstratech

Re: UniRenko Bars Test - 01/13/17 02:56

What happens is when ex. your 10 pip brick is printed in 1 minute but your time frame is 60 minutes,that brick disappears - constantly. By the end of 60th munute you get "perfect" n number of bricks in the direction of the move, completely disregarding the up and down movements that happened DURING the 60 minutes.

Zorro is lacking application of renko IMO
© 2024 lite-C Forums