Missing Custom Bars

Posted By: ozgur

Missing Custom Bars - 09/13/20 18:44

Custom bars are not constructed correctly when bar range of custom bar is less than source data (1M in this case).

Above is median renko bars with 10 pip range. Below is 1 minute chart.
Some 1M bars are bigger than 20 pips which should generate 2 renko bars normally. I guess that's not the case here.

[Linked Image]

Zoomed:

[Linked Image]


Source code:

Code
var BarRange = 0.0010;

// Mean Renko Bars
int Renko3(vars Open, vars High, vars Low, vars Close)
{
  Open[0] = 0.5*(Close[1]+Open[1]);
  if(Close[0] <= Open[0] - BarRange) {
    Close[0] = Open[0] - BarRange;
    return 1;
  } else if(Close[0] >= Open[0] + BarRange) {
    Close[0] = Open[0] + BarRange;
    return 1;
  }
  return 4;
}

int bar() {} // dummy function to be set to the real bar function

void run()
{
	bar = Renko3;
	BarPeriod = 1; // determines only the number of allocated bars, not the bar period
	StartDate = 20180603;
	EndDate = 20180605;
	LookBack = 2;
	set(PLOTNOW, LOGFILE);
	
	Verbose = 3;
	// ... perform the algorithm.
}



Log:

Quote

V 2.307 on Sun 20-09-13 19:33:37
Load AssetsFix
EUR/USD 375840 ticks read
173 Bars 2018-05-30..2018-06-06 generated
EUR/USD: 0..172, 2018-05-30..2018-06-06
Test: shiftedRenkoTrials EUR/USD (TICKS) 2018

[1: Thu 18-05-31 00:13c] 1.16677/1.16712\1.16565/1.16577 -0.00013
End of lookback period

[2: Thu 18-05-31 01:31c] 1.16627/1.16667\1.16523/1.16527 -0.00013
[3: Thu 18-05-31 03:19c] 1.16577/1.16694\1.16482/1.16677 -0.00013
[4: Thu 18-05-31 05:34c] 1.16627/1.16742\1.16592/1.16727 -0.00013
[5: Thu 18-05-31 05:37c] 1.16677/1.16853\1.16731/1.16777 -0.00013
[6: Thu 18-05-31 05:38c] 1.16727/1.16887\1.16829/1.16827 -0.00013
[7: Thu 18-05-31 06:39c] 1.16777/1.16890\1.16662/1.16677 -0.00013
[8: Thu 18-05-31 06:47c] 1.16727/1.16855\1.16647/1.16827 -0.00013
[9: Thu 18-05-31 06:49c] 1.16777/1.16936\1.16823/1.16877 -0.00013
[10: Thu 18-05-31 06:50c] 1.16827/1.16956\1.16923/1.16927 -0.00013
[11: Thu 18-05-31 07:33c] 1.16877/1.16988\1.16793/1.16977 -0.00013
[12: Thu 18-05-31 07:38c] 1.16927/1.17031\1.16948/1.17027 -0.00013
[13: Thu 18-05-31 07:45c] 1.16977/1.17098\1.16995/1.17077 -0.00013
[14: Thu 18-05-31 07:46c] 1.17027/1.17135\1.17078/1.17127 -0.00013
[15: Thu 18-05-31 07:57c] 1.17077/1.17188\1.17098/1.17177 -0.00013
[16: Thu 18-05-31 08:21c] 1.17127/1.17238\1.17040/1.17227 -0.00013
[17: Thu 18-05-31 09:05c] 1.17177/1.17244\1.17048/1.17077 -0.00013
[18: Thu 18-05-31 09:12c] 1.17127/1.17091\1.16994/1.17027 -0.00013
[19: Thu 18-05-31 09:45] 1.17077/1.17103\1.16961/1.16977 -0.00013
[20: Thu 18-05-31 09:48] 1.17027/1.17000\1.16922/1.16927 -0.00013
[21: Thu 18-05-31 10:07] 1.16977/1.17063\1.16855/1.16877 -0.00013
[22: Thu 18-05-31 10:23] 1.16927/1.16915\1.16812/1.16827 -0.00013
[23: Thu 18-05-31 10:30] 1.16877/1.16817\1.16762/1.16777 -0.00013
[24: Thu 18-05-31 11:27] 1.16827/1.16944\1.16733/1.16927 -0.00013
[25: Thu 18-05-31 11:38] 1.16877/1.16996\1.16902/1.16977 -0.00013
[26: Thu 18-05-31 11:49] 1.16927/1.17030\1.16977/1.17027 -0.00013
[27: Thu 18-05-31 12:35] 1.16977/1.17089\1.16822/1.16877 -0.00013
[28: Thu 18-05-31 12:46] 1.16927/1.16984\1.16818/1.16827 -0.00013
[29: Thu 18-05-31 12:53] 1.16877/1.16868\1.16753/1.16777 -0.00013
[30: Thu 18-05-31 12:59] 1.16827/1.16781\1.16720/1.16727 -0.00013
[31: Thu 18-05-31 13:02] 1.16777/1.16747\1.16651/1.16677 -0.00013
[32: Thu 18-05-31 13:09] 1.16727/1.16713\1.16625/1.16627 -0.00013
[33: Thu 18-05-31 13:22] 1.16677/1.16672\1.16549/1.16577 -0.00013
[34: Thu 18-05-31 13:57] 1.16627/1.16722\1.16496/1.16527 -0.00013
[35: Thu 18-05-31 14:04] 1.16577/1.16696\1.16459/1.16677 -0.00013
[36: Thu 18-05-31 14:31] 1.16627/1.16752\1.16548/1.16727 -0.00013
[37: Thu 18-05-31 14:39] 1.16677/1.16797\1.16726/1.16777 -0.00013
[38: Thu 18-05-31 15:08] 1.16727/1.16824\1.16541/1.16627 -0.00013
[39: Thu 18-05-31 15:10] 1.16677/1.16601\1.16536/1.16577 -0.00013
[40: Thu 18-05-31 15:26] 1.16627/1.16638\1.16481/1.16527 -0.00013
[41: Thu 18-05-31 15:27] 1.16577/1.16521\1.16459/1.16477 -0.00013
[42: Thu 18-05-31 15:35] 1.16527/1.16635\1.16414/1.16627 -0.00013
[43: Thu 18-05-31 15:39] 1.16577/1.16731\1.16537/1.16677 -0.00013
[44: Thu 18-05-31 15:40] 1.16627/1.16880\1.16715/1.16727 -0.00013
[45: Thu 18-05-31 15:41] 1.16677/1.16944\1.16813/1.16777 -0.00013
[46: Thu 18-05-31 15:42] 1.16727/1.16942\1.16840/1.16827 -0.00013
[47: Thu 18-05-31 15:43] 1.16777/1.16906\1.16849/1.16877 -0.00013
[48: Thu 18-05-31 15:44] 1.16827/1.16986\1.16877/1.16927 -0.00013
[49: Thu 18-05-31 15:51] 1.16877/1.16986\1.16763/1.16777 -0.00013
[50: Thu 18-05-31 15:58] 1.16827/1.16805\1.16687/1.16727 -0.00013
[51: Thu 18-05-31 16:08c] 1.16777/1.16751\1.16665/1.16677 -0.00013
[52: Thu 18-05-31 16:19c] 1.16727/1.16719\1.16590/1.16627 -0.00013
[53: Thu 18-05-31 17:05c] 1.16677/1.16800\1.16578/1.16777 -0.00013
[54: Thu 18-05-31 17:08c] 1.16727/1.16893\1.16786/1.16827 -0.00013
[55: Thu 18-05-31 18:29c] 1.16777/1.16891\1.16725/1.16877 -0.00013
[56: Thu 18-05-31 18:51c] 1.16827/1.16940\1.16826/1.16927 -0.00013
[57: Thu 18-05-31 22:23c] 1.16877/1.16990\1.16832/1.16977 -0.00013
[58: Thu 18-05-31 22:42c] 1.16927/1.17040\1.16977/1.17027 -0.00013
[59: Fri 18-06-01 00:14c] 1.16977/1.17068\1.16872/1.16877 -0.00013
[60: Fri 18-06-01 03:18c] 1.16927/1.16968\1.16818/1.16827 -0.00013
[61: Fri 18-06-01 04:37c] 1.16877/1.16839\1.16773/1.16777 -0.00013
[62: Fri 18-06-01 05:06c] 1.16827/1.16796\1.16701/1.16727 -0.00013
[63: Fri 18-06-01 05:09c] 1.16777/1.16716\1.16666/1.16677 -0.00013
[64: Fri 18-06-01 06:59c] 1.16727/1.16863\1.16656/1.16827 -0.00013
[65: Fri 18-06-01 07:01c] 1.16777/1.16947\1.16826/1.16877 -0.00013
[66: Fri 18-06-01 07:24c] 1.16827/1.16956\1.16809/1.16927 -0.00013
[67: Fri 18-06-01 07:32c] 1.16877/1.17013\1.16892/1.16977 -0.00013
[68: Fri 18-06-01 07:54c] 1.16927/1.17030\1.16823/1.16827 -0.00013
[69: Fri 18-06-01 09:58] 1.16877/1.16981\1.16775/1.16977 -0.00013
[70: Fri 18-06-01 10:00] 1.16927/1.17083\1.16971/1.17027 -0.00013
[71: Fri 18-06-01 10:01] 1.16977/1.17159\1.17043/1.17077 -0.00013
[72: Fri 18-06-01 10:02] 1.17027/1.17182\1.17130/1.17127 -0.00013
[73: Fri 18-06-01 11:31] 1.17077/1.17174\1.16940/1.16977 -0.00013
[74: Fri 18-06-01 11:42] 1.17027/1.16985\1.16894/1.16927 -0.00013
[75: Fri 18-06-01 11:51] 1.16977/1.16908\1.16835/1.16877 -0.00013
[76: Fri 18-06-01 11:55] 1.16927/1.16871\1.16797/1.16827 -0.00013
[77: Fri 18-06-01 11:56] 1.16877/1.16807\1.16724/1.16777 -0.00013
[78: Fri 18-06-01 11:58] 1.16827/1.16765\1.16719/1.16727 -0.00013
[79: Fri 18-06-01 12:19] 1.16777/1.16780\1.16664/1.16677 -0.00013
[80: Fri 18-06-01 12:31] 1.16727/1.16742\1.16481/1.16627 -0.00013
[81: Fri 18-06-01 12:32] 1.16677/1.16639\1.16503/1.16577 -0.00013
[82: Fri 18-06-01 12:38] 1.16627/1.16830\1.16561/1.16727 -0.00013
[83: Fri 18-06-01 12:39] 1.16677/1.16851\1.16776/1.16777 -0.00013
[84: Fri 18-06-01 12:40] 1.16727/1.16881\1.16787/1.16827 -0.00013
[85: Fri 18-06-01 12:51] 1.16777/1.16855\1.16631/1.16677 -0.00013
[86: Fri 18-06-01 12:58] 1.16727/1.16749\1.16590/1.16627 -0.00013
[87: Fri 18-06-01 12:59] 1.16677/1.16609\1.16562/1.16577 -0.00013
[88: Fri 18-06-01 13:10] 1.16627/1.16750\1.16541/1.16727 -0.00013
[89: Fri 18-06-01 13:20] 1.16677/1.16800\1.16711/1.16777 -0.00013
[90: Fri 18-06-01 14:12] 1.16727/1.16837\1.16561/1.16627 -0.00013
[91: Fri 18-06-01 14:13] 1.16677/1.16586\1.16459/1.16577 -0.00013
[92: Fri 18-06-01 14:14] 1.16627/1.16515\1.16451/1.16527 -0.00013
[93: Fri 18-06-01 14:16] 1.16577/1.16518\1.16220/1.16477 -0.00013
[94: Fri 18-06-01 14:17] 1.16527/1.16310\1.16172/1.16427 -0.00013
[95: Fri 18-06-01 14:24] 1.16477/1.16618\1.16278/1.16577 -0.00013
[96: Fri 18-06-01 14:27] 1.16527/1.16670\1.16563/1.16627 -0.00013
[97: Fri 18-06-01 14:45] 1.16577/1.16653\1.16455/1.16477 -0.00013
[98: Fri 18-06-01 14:59] 1.16527/1.16638\1.16458/1.16627 -0.00013
[99: Fri 18-06-01 15:12] 1.16577/1.16734\1.16612/1.16677 -0.00013
[100: Fri 18-06-01 15:14] 1.16627/1.16766\1.16705/1.16727 -0.00013
[101: Fri 18-06-01 15:52] 1.16677/1.16799\1.16679/1.16777 -0.00013
[102: Fri 18-06-01 16:53c] 1.16727/1.16815\1.16624/1.16627 -0.00013
[103: Fri 18-06-01 17:55c] 1.16677/1.16695\1.16556/1.16577 -0.00013
[104: Mon 18-06-04 00:04c] 1.16627/1.16737\1.16537/1.16727 -0.00013
[105: Mon 18-06-04 00:15c] 1.16677/1.16784\1.16710/1.16777 -0.00013
[106: Mon 18-06-04 01:35c] 1.16727/1.16861\1.16725/1.16827 -0.00013
[107: Mon 18-06-04 01:49c] 1.16777/1.16895\1.16850/1.16877 -0.00013
[108: Mon 18-06-04 03:16c] 1.16827/1.16933\1.16857/1.16927 -0.00013
[109: Mon 18-06-04 06:38c] 1.16877/1.16971\1.16766/1.16777 -0.00013
[110: Mon 18-06-04 07:13c] 1.16827/1.16932\1.16754/1.16927 -0.00013
[111: Mon 18-06-04 07:19c] 1.16877/1.17000\1.16927/1.16977 -0.00013
[112: Mon 18-06-04 07:20c] 1.16927/1.17065\1.16988/1.17027 -0.00013
[113: Mon 18-06-04 07:21c] 1.16977/1.17088\1.17057/1.17077 -0.00013
[114: Mon 18-06-04 07:27c] 1.17027/1.17147\1.17052/1.17127 -0.00013
[115: Mon 18-06-04 07:56c] 1.17077/1.17151\1.16965/1.16977 -0.00013
[116: Mon 18-06-04 07:59c] 1.17027/1.16981\1.16924/1.16927 -0.00013
[117: Mon 18-06-04 08:10c] 1.16977/1.16974\1.16844/1.16877 -0.00013
[118: Mon 18-06-04 08:27c] 1.16927/1.17060\1.16850/1.17027 -0.00013
[119: Mon 18-06-04 08:32c] 1.16977/1.17089\1.17035/1.17077 -0.00013
[120: Mon 18-06-04 08:39c] 1.17027/1.17183\1.17057/1.17127 -0.00013
[121: Mon 18-06-04 09:06c] 1.17077/1.17236\1.17038/1.17177 -0.00013
[122: Mon 18-06-04 09:13c] 1.17127/1.17232\1.17193/1.17227 -0.00013
[123: Mon 18-06-04 09:24c] 1.17177/1.17280\1.17190/1.17277 -0.00013
[124: Mon 18-06-04 09:28c] 1.17227/1.17340\1.17278/1.17327 -0.00013
[125: Mon 18-06-04 12:01] 1.17277/1.17445\1.17203/1.17377 -0.00013
[126: Mon 18-06-04 12:02] 1.17327/1.17447\1.17420/1.17427 -0.00013
[127: Mon 18-06-04 12:31] 1.17377/1.17447\1.17242/1.17277 -0.00013
[128: Mon 18-06-04 12:39] 1.17327/1.17272\1.17214/1.17227 -0.00013
[129: Mon 18-06-04 13:00] 1.17277/1.17249\1.17157/1.17177 -0.00013
[130: Mon 18-06-04 13:25] 1.17227/1.17237\1.17108/1.17127 -0.00013
[131: Mon 18-06-04 13:42] 1.17177/1.17158\1.17064/1.17077 -0.00013
[132: Mon 18-06-04 14:17] 1.17127/1.17237\1.17074/1.17227 -0.00013
[133: Mon 18-06-04 14:32] 1.17177/1.17254\1.17070/1.17077 -0.00013
[134: Mon 18-06-04 14:39] 1.17127/1.17091\1.17022/1.17027 -0.00013
[135: Mon 18-06-04 14:44] 1.17077/1.17068\1.16971/1.16977 -0.00013
[136: Mon 18-06-04 15:18] 1.17027/1.17035\1.16921/1.16927 -0.00013
[137: Mon 18-06-04 15:20] 1.16977/1.16945\1.16866/1.16877 -0.00013
[138: Mon 18-06-04 15:38] 1.16927/1.16905\1.16783/1.16827 -0.00013
[139: Mon 18-06-04 18:00c] 1.16877/1.16989\1.16774/1.16977 -0.00013
[140: Tue 18-06-05 00:03c] 1.16927/1.17036\1.16931/1.17027 -0.00013
[141: Tue 18-06-05 04:40c] 1.16977/1.17037\1.16870/1.16877 -0.00013
[142: Tue 18-06-05 06:58c] 1.16927/1.17062\1.16835/1.17027 -0.00013
[143: Tue 18-06-05 07:09c] 1.16977/1.17084\1.17022/1.17077 -0.00013
[144: Tue 18-06-05 07:29c] 1.17027/1.17078\1.16915/1.16927 -0.00013
[145: Tue 18-06-05 07:35c] 1.16977/1.16925\1.16861/1.16877 -0.00013
[146: Tue 18-06-05 08:10c] 1.16927/1.17032\1.16858/1.17027 -0.00013
[147: Tue 18-06-05 08:12c] 1.16977/1.17117\1.17028/1.17077 -0.00013
[148: Tue 18-06-05 08:21c] 1.17027/1.17152\1.17031/1.17127 -0.00013
[149: Tue 18-06-05 09:11c] 1.17077/1.17170\1.16964/1.16977 -0.00013
[150: Tue 18-06-05 10:16] 1.17027/1.17035\1.16914/1.16927 -0.00013
[151: Tue 18-06-05 10:55] 1.16977/1.16979\1.16866/1.16877 -0.00013
[152: Tue 18-06-05 10:58] 1.16927/1.16883\1.16796/1.16827 -0.00013
[153: Tue 18-06-05 10:59] 1.16877/1.16820\1.16765/1.16777 -0.00013
[154: Tue 18-06-05 12:16] 1.16827/1.16880\1.16705/1.16727 -0.00013
[155: Tue 18-06-05 12:21] 1.16777/1.16726\1.16665/1.16677 -0.00013
[156: Tue 18-06-05 13:03] 1.16727/1.16750\1.16609/1.16627 -0.00013
[157: Tue 18-06-05 14:03] 1.16677/1.16753\1.16557/1.16577 -0.00013
[158: Tue 18-06-05 15:08] 1.16627/1.16732\1.16528/1.16727 -0.00013
[159: Tue 18-06-05 15:11] 1.16677/1.16818\1.16714/1.16777 -0.00013
[160: Tue 18-06-05 16:01c] 1.16727/1.16985\1.16687/1.16827 -0.00013
[161: Tue 18-06-05 16:02c] 1.16777/1.17035\1.16943/1.16877 -0.00013
[162: Tue 18-06-05 16:03c] 1.16827/1.17003\1.16932/1.16927 -0.00013
[163: Tue 18-06-05 16:12c] 1.16877/1.17020\1.16865/1.16977 -0.00013
[164: Tue 18-06-05 16:14c] 1.16927/1.17046\1.16974/1.17027 -0.00013
[165: Tue 18-06-05 16:16c] 1.16977/1.17094\1.17030/1.17077 -0.00013
[166: Tue 18-06-05 16:22c] 1.17027/1.17190\1.17044/1.17127 -0.00013
[167: Tue 18-06-05 16:25c] 1.17077/1.17204\1.17134/1.17177 -0.00013
[168: Tue 18-06-05 16:31c] 1.17127/1.17271\1.17159/1.17227 -0.00013
[169: Tue 18-06-05 17:09c] 1.17177/1.17316\1.17079/1.17277 -0.00013
[170: Tue 18-06-05 19:04c] 1.17227/1.17324\1.17118/1.17127 -0.00013
[171: Tue 18-06-05 23:38c] 1.17177/1.17290\1.17086/1.17277 -0.00013
[172: Wed 18-06-06 01:49c] 1.17227/1.17348\1.17184/1.17327 -0.0001



Posted By: AndrewAMD

Re: Missing Custom Bars - 09/13/20 19:44

The "Mean Renko Bars" function looks suspicious. I would debug it.
Posted By: ozgur

Re: Missing Custom Bars - 09/15/20 18:32

Well, I think renko bar creation should have been based on comparing low/high instead of close price. However I think the issue here is a bit different.

From manual:
Quote
The bar function is automatically called whenever a new price quote arrives or a price tick is read from a historical file.

'tick' in above case is 1 minute bars in t6 file. Sometimes, (e.g. news event, price gap) a 1M 'tick' can be several times bigger than renko bar size. As a result, you would expect several renko bars being created. But bar() function can only return "4" (closing custom bar) once per 'tick' and generates only 1 renko bar instead.
Posted By: ozgur

Re: Missing Custom Bars - 09/15/20 18:36

Here's geometric renko bars but similar issue can be seen.

Code
var BarRange = 0.0010;
var shiftPct = 0.125;

// Shifted Renko Bars V2
int Renko5(vars Open, vars High, vars Low, vars Close)
{
	if (Close[1] > Open[1]) {
		Open[0] = Open[1] + BarRange * shiftPct;
		
		if(Low[0] <= Open[1] - BarRange * shiftPct) {
			Open[0] = Open[1] + BarRange * (1 - shiftPct);
			
			Close[0] = Open[0] - BarRange;
			
			return 1;
		} else if (High[0] >= Open[0] + BarRange) {
			Close[0] = Open[0] + BarRange;
			
			return 1;
		}
	} else if (Close[1] < Open[1]) {
		Open[0] = Open[1] - BarRange * shiftPct;
		
		if(High[0] >= Open[1] + BarRange * shiftPct) {
			Open[0] = Open[1] - BarRange * (1 - shiftPct);
			
			Close[0] = Open[0] + BarRange;
			
			return 1;
		} else if (Low[0] <= Open[0] - BarRange) {
			Close[0] = Open[0] - BarRange;
			
			return 1;
		}
	}
	
	return 4;
}


[Linked Image]
Posted By: AndrewAMD

Re: Missing Custom Bars - 09/15/20 20:50

Originally Posted by ozgur
But bar() function can only return "4" (closing custom bar) once per 'tick' and generates only 1 renko bar instead.
This could be it.

https://zorro-project.com/manual/en/bar.htm
Quote
Returns:
0 - close the bar at the normal end of the BarPeriod.
1 - close the bar now.
4 - keep the bar open until closed by returning 1, and call the bar function at every price tick.
8 - call the bar function only once at the end of every bar.
This could use a fifth return: "Close the bar now, but create a new bar with the current priceClose() value." Zorro would in turn call the bar() function again.
Posted By: jcl

Re: Missing Custom Bars - 09/18/20 10:55

The problem is then that this new bar would not match any price or time stamp of the historical data. The chart would look better, but had bars that do not exist in the price history.
Posted By: AndrewAMD

Re: Missing Custom Bars - 09/18/20 12:49

Are you saying that a drawn bar necessarily has a unique timestamp?
Posted By: jcl

Re: Missing Custom Bars - 09/18/20 17:13

Normally yes, from its last price quote.
Posted By: AndrewAMD

Re: Missing Custom Bars - 09/18/20 17:53

Then for a true "timeless Renko", it seems there are three workarounds:
1) With bar(), use tick data instead of 1-minute bar data, and it'll solve 99.9% of the problem.
2) With bar(), draw an extra-long Renko bar when the price moves too far.
3) Using tick() or run(), make your own homebrew Renko bars. But these bars would not plot on the price chart. You can check it by printing OHLC etc to CSV.
Posted By: ozgur

Re: Missing Custom Bars - 09/20/20 16:32

Originally Posted by AndrewAMD
Then for a true "timeless Renko", it seems there are three workarounds:
1) With bar(), use tick data instead of 1-minute bar data, and it'll solve 99.9% of the problem.
2) With bar(), draw an extra-long Renko bar when the price moves too far.
3) Using tick() or run(), make your own homebrew Renko bars. But these bars would not plot on the price chart. You can check it by printing OHLC etc to CSV.


The first solution alone would work for single asset and single renko frame scenario.

Otherwise, I think series holding renko values should be managed with tick() function using tick data. Because, according to manual, bar() cannot be used in multi-asset strategies, or in strategies with multiple bar types. The manual also suggest managing series in run() which still depends on BarPeriod. This would lead the same issue above unless run() can be called tick by tick? Isn't 1 second is the minimum BarPeriod?
Posted By: jcl

Re: Missing Custom Bars - 09/21/20 06:43

It should work also with ticks, you only need then to use the tick() function instead of run() for determining the end of the special bar, and shift all series manually.
© 2024 lite-C Forums