Skip to content

Commit 851a563

Browse files
Re-add autoscale_cb.js
1 parent 637c7b1 commit 851a563

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
.env
33
/dist
44
*.pyc
5-
*.js

stratback/backtesting/autoscale_cb.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
if (!window._bt_scale_range) {
2+
window._bt_scale_range = function (range, min, max, pad) {
3+
"use strict";
4+
if (min !== Infinity && max !== -Infinity) {
5+
pad = pad ? (max - min) * .03 : 0;
6+
range.start = min - pad;
7+
range.end = max + pad;
8+
} else console.error('backtesting: scale range error:', min, max, range);
9+
};
10+
}
11+
12+
clearTimeout(window._bt_autoscale_timeout);
13+
14+
window._bt_autoscale_timeout = setTimeout(function () {
15+
/**
16+
* @variable cb_obj `fig_ohlc.x_range`.
17+
* @variable source `ColumnDataSource`
18+
* @variable ohlc_range `fig_ohlc.y_range`.
19+
* @variable volume_range `fig_volume.y_range`.
20+
*/
21+
"use strict";
22+
23+
let i = Math.max(Math.floor(cb_obj.start), 0),
24+
j = Math.min(Math.ceil(cb_obj.end), source.data['ohlc_high'].length);
25+
26+
let max = Math.max.apply(null, source.data['ohlc_high'].slice(i, j)),
27+
min = Math.min.apply(null, source.data['ohlc_low'].slice(i, j));
28+
_bt_scale_range(ohlc_range, min, max, true);
29+
30+
if (volume_range) {
31+
max = Math.max.apply(null, source.data['Volume'].slice(i, j));
32+
_bt_scale_range(volume_range, 0, max * 1.03, false);
33+
}
34+
35+
}, 50);

0 commit comments

Comments
 (0)