Is this renko implementation an error?

Posted By: Oligon

Is this renko implementation an error? - 11/28/17 19:33

Hi guys!

I tried to experiment these last few days with the renko bars example found on the zorro manual:

Code:
var BarRange = 0.0005;

int bar(vars Open,vars High,vars Low,vars Close)
{
  Open[0] = round(Close[1],BarRange);
  if(Close[0]-Open[0] >= BarRange) {
    Close[0] = Open[0]+BarRange;
    High[0] = Close[0];
    Low[0] = Open[0];
    return 1;
  }
  if(Open[0]-Close[0] >= BarRange) {
    Close[0] = Open[0]-BarRange;
    High[0] = Open[0];
    Low[0] = Close[0];
    return 1;
  }
  return 4;
}



Then I coded a very simple strategy to buy after two consecutive bullish bars and sell after two consecutive renko bars. The results were too good to be true, so I thought that there must be something wrong. The logic seems fine and when I zoomed on the resulting chart, it seemed ok and to be executing the trades correctly.

My last experiment was to trade it live on a demo account yesterday and today I did the simulation for yesterday just to compare. When I did that, I found that Zorro is not doing the same on the demo account as it did on the simulation. Of course, the demo test was a complete fail, with trades resulting in fractions of a cent and doing a ton more trades than the simulation on the same period of time.

Can anyone help me understand what is going on here? Is there a bug on the backtesting of renko bars? Do I have to set up something additional to make it work in live or demo trading?

Any help would be very helpful, thank you!!
Posted By: jcl

Re: Is this renko implementation an error? - 11/29/17 07:48

"Modified prices affect the corresponding price functions (priceOpen, priceHigh, priceLow, priceClose, price) and price-dependent indicators. They also affect simulated trade results when the TICKS flag is not set. For realistic results set the TICKS flag."

Take that serious. Have you set TICKS?
Posted By: Oligon

Re: Is this renko implementation an error? - 11/30/17 05:48

Yes, I have set the TICKS flag, that's another thing that should be working fine, but on the live test, it was not the same.

Here is the rest of the code, it's very simple:

Code:
function run()
{
	set(PLOTNOW+TICKS);
	StartDate = 2005;
	BarPeriod = 60;
	
	if(priceClose(0) > priceClose(1) and priceClose(1) > priceClose(2)){
		reverseLong(1);
	}
	if(priceClose(0) < priceClose(1) and priceClose(1) < priceClose(2)){
		reverseShort(1);
	}
}




What could be going wrong?

Thanks jcl!!
Posted By: jcl

Re: Is this renko implementation an error? - 12/01/17 07:39

Looks ok to me. But it should not produce a too good backtest. Can you contact Support with that script? They'll check what the problem is, and will send you a fix if it's backtest bias.
Posted By: Oligon

Re: Is this renko implementation an error? - 12/01/17 18:05

Alright, will sure do that!

I hope it can be fixed, it would be nice to keep experimenting with special bars.

Thank you for your help!
Posted By: atr

Re: Is this renko implementation an error? - 12/03/17 14:14

I tried to test the following script with multiple assets and I got the following error message:

Chart...Error 47: No bars to plot!

Does anybody know how to do a script with Renko bars and multiple assets?

This is the script:


var BarRange = 0.0030; // 0.3 cents bar range

// Renko Bars, variant 1
int bar(vars Open,vars High,vars Low,vars Close)
{
Open[0] = round(Close[1],BarRange);
if(Close[0]-Open[0] >= BarRange) {
Close[0] = Open[0]+BarRange;
High[0] = Close[0];
Low[0] = Open[0];
return 1;
}
if(Open[0]-Close[0] >= BarRange) {
Close[0] = Open[0]-BarRange;
High[0] = Open[0];
Low[0] = Close[0];
return 1;
}
return 4;
}

function run()
{
set(PLOTNOW+TICKS+TESTNOW);
StartDate = 20050101;
BarPeriod = 60;

while(asset(loop("EUR/USD","GBP/USD","USD/JPY")))
{
if(priceClose(0) > priceClose(1)
and priceClose(1) > priceClose(2)){
reverseLong(1);
}
if(priceClose(0) < priceClose(1)
and priceClose(1) < priceClose(2)){
reverseShort(1);
}

}

}
Posted By: atr

Re: Is this renko implementation an error? - 12/03/17 14:18

By the way, testing only the EUR/USD with the script above I got the following results:

Simulated account AssetsFix
Bar period 1 hour (avg 350 min)
Test period 2005-01-03..2017-12-01 (19380 bars)
Lookback period 80 bars (3 days)
Montecarlo cycles 200
Simulation mode Realistic ticks (slippage 5.0 sec)
Avg bar 240.0 ticks 30.0 pips range
Spread 0.5 pips (roll -0.02/0.01)
Commission 0.60
Contracts per lot 1000.0

Gross win/loss 8891$ / -7019$ (+21493p)
Average profit 145$/year, 12$/month, 0.55770707b/day
Max drawdown -157$ 8.4% (MAE -162$ 8.7%)
Total down time 81% (TAE 95%)
Max down time 18 weeks from Apr 2009
Max open margin 10$
Max open risk 14$
Trade volume 3608500$ (279508$/year)
Transaction costs -137$ spr, -132$ slp, -1.60$ rol, -189$ com
Capital required 86$

Number of trades 3149 (244/year, 5/week, 1/day)
Percent winning 34.4%
Max win/loss 52$ / -13$
Avg trade profit 0.59448257b 6.8p (+94.3p / -39.0p)
Avg trade slippage -0.04204255b -0.5p (+2.8p / -2.2p)
Avg trade bars 5 (+9 / -2)
Max trade bars 44 (44 hours)
Time in market 84%
Max open trades 1
Max loss streak 14 (uncorrelated 20)

Annual return 169%
Profit factor 1.27 (PRR 1.20)
Sharpe ratio 1.28
Kelly criterion 0.97
R2 coefficient 0.980
Ulcer index 2.3%

Confidence level AR DDMax Capital

10% 225% 113$ 64$
20% 202% 128$ 72$
30% 189% 138$ 77$
40% 181% 146$ 80$
50% 172% 154$ 84$
60% 163% 163$ 89$
70% 155% 173$ 93$
80% 142% 192$ 102$
90% 130% 211$ 112$
95% 113% 246$ 128$
100% 81% 350$ 179$

Portfolio analysis OptF ProF Win/Loss Wgt%

EUR/USD .137 1.27 1083/2066 100.0
EUR/USD:L .133 1.25 545/1030 46.1
EUR/USD:S .141 1.28 538/1036 53.9
Posted By: atr

Re: Is this renko implementation an error? - 12/04/17 21:00

In the manual it is written that

"User-defined bar lengths can normally be used with single-asset strategies only, as different assets would produce different bars. For a portfolio system, user-defined bars had to be simulated with the TimeFrame mechanism or with a tick function. "

Can anyone can help me about how to write correctly the following script with renko bars and multiple assets?

var BarRange = 0.0030; // 0.3 cents bar range

// Renko Bars, variant 1
int bar(vars Open,vars High,vars Low,vars Close)
{
Open[0] = round(Close[1],BarRange);
if(Close[0]-Open[0] >= BarRange) {
Close[0] = Open[0]+BarRange;
High[0] = Close[0];
Low[0] = Open[0];
return 1;
}
if(Open[0]-Close[0] >= BarRange) {
Close[0] = Open[0]-BarRange;
High[0] = Open[0];
Low[0] = Close[0];
return 1;
}
return 4;
}

function run()
{
set(PLOTNOW+TICKS+TESTNOW);
StartDate = 20050101;
BarPeriod = 60;

while(asset(loop("EUR/USD","GBP/USD","USD/JPY")))
{
if(priceClose(0) > priceClose(1)
and priceClose(1) > priceClose(2)){
reverseLong(1);
}
if(priceClose(0) < priceClose(1)
and priceClose(1) < priceClose(2)){
reverseShort(1);
}

}

}


Thanks!
Posted By: ricky_k

Re: Is this renko implementation an error? - 09/02/19 15:32

Hey atr,

Have you tried looking at the (fairly) new SpecialBars.c script?
Perhaps that can help.

ricky
© 2024 lite-C Forums