Skip to content

Commit bfdc1d2

Browse files
committed
add dice entry for "noop" example strategy for a full workflow; and some ui tweaks
1 parent b813d4a commit bfdc1d2

File tree

8 files changed

+59
-10
lines changed

8 files changed

+59
-10
lines changed

src/modules/backtest.js

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ module.exports = class Backtest {
193193
signals: signals.slice().reverse(),
194194
candles: JSON.stringify(candles),
195195
extra_fields: this.strategyManager.getBacktestColumns(strategy),
196+
strategy: strategy,
197+
start: new Date(start * 1000),
198+
end: candles[0] ? candles[0].date : new Date(),
196199
configuration: {
197200
exchange: exchange,
198201
symbol: pair,

src/modules/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = class Http {
143143
return {
144144
pair: pair,
145145
result: await this.backtest.getBacktestResult(
146-
parseInt(req.body.ticker_interval),
146+
parseInt(req.body.ticker_interval, 10),
147147
req.body.hours,
148148
req.body.strategy,
149149
req.body.candle_period,

src/modules/strategy/dict/indicator_period.js

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ module.exports = class IndicatorPeriod {
2020
return this.strategyContext.getProfit();
2121
}
2222

23+
isShort() {
24+
return this.getLastSignal() === 'short';
25+
}
26+
27+
isLong() {
28+
return this.getLastSignal() === 'long';
29+
}
30+
2331
/**
2432
* Context return for the current strategy, usable to get the previous strategy signals and current positions.
2533
*

src/modules/strategy/strategies/noop.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,35 @@ module.exports = class {
6565
.map(v => `${intl.format(v.rangeStart)}-${intl.format(v.rangeEnd)}`)
6666
.join(', ');
6767

68-
return SignalResult.createEmptySignal(currentValues);
68+
const emptySignal = SignalResult.createEmptySignal(currentValues);
69+
70+
// entry or exit
71+
if (!indicatorPeriod.getLastSignal()) {
72+
const dice = parseFloat(options.dice || 6);
73+
const diceSize = parseFloat(options.dice_size || 12);
74+
75+
const number = Math.floor(Math.random() * diceSize) + 1;
76+
emptySignal.addDebug('message', `${number}`);
77+
if (number === dice) {
78+
const longOrShort = Math.random() > 0.5 ? 'long' : 'short';
79+
emptySignal.setSignal(longOrShort);
80+
}
81+
}
82+
83+
// close on profit or lose
84+
if (indicatorPeriod.getLastSignal()) {
85+
if (indicatorPeriod.getProfit() > 2) {
86+
// take profit
87+
emptySignal.addDebug('message', 'TP');
88+
emptySignal.setSignal('close');
89+
} else if (indicatorPeriod.getProfit() < -2) {
90+
// stop loss
91+
emptySignal.addDebug('message', 'SL');
92+
emptySignal.setSignal('close');
93+
}
94+
}
95+
96+
return emptySignal;
6997
}
7098

7199
getBacktestColumns() {
@@ -110,6 +138,10 @@ module.exports = class {
110138
label: 'Top Volume Ranges',
111139
value: 'ranges'
112140
},
141+
{
142+
label: 'dice',
143+
value: 'message'
144+
},
113145
{
114146
label: 'zigzag',
115147
value: row => (row.zigzag && row.zigzag.turningPoint === true ? 'warning' : undefined),
@@ -121,6 +153,8 @@ module.exports = class {
121153
getOptions() {
122154
return {
123155
period: '15m',
156+
dice: 6,
157+
dice_size: 12,
124158
foreign_pair_exchange: 'binance',
125159
foreign_pair_symbol: 'BTCUSDT',
126160
foreign_pair_period: '15m'

templates/backtest_submit.html.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="container">
1515
<div class="row mb-2">
1616
<div class="col-sm-6">
17-
<h1>Backtesting Results</h1>
17+
<h1>Backtesting Results <span class="text-muted"> - {{ strategy }} - {{ configuration.period }}</span></h1>
1818
</div>
1919
<div class="col-sm-6">
2020
<ol class="breadcrumb float-sm-right">
@@ -34,7 +34,7 @@
3434
<div class="col-md-12">
3535
<div class="card">
3636
<div class="card-header">
37-
<h3 class="card-title">Summary</h3>
37+
<h3 class="card-title">Summary <span class="text-muted"> - {{ start|date('y-m-d H:i:s') }} - {{ end|date('y-m-d H:i:s') }}</span></h3>
3838
</div>
3939
<!-- /.card-header -->
4040
<div class="card-body">
@@ -52,7 +52,7 @@
5252
</div>
5353
<!-- /.card-header -->
5454
<div class="card-body table-responsive p-0">
55-
<div class="chart" data-candles="{{ candles|e('html') }}" data-title="{{ configuration.exchange }} - {{ configuration.symbol }} - {{ configuration.period }} - espend.de"></div>
55+
<div class="chart" data-candles="{{ candles|e('html') }}" data-title="{{ configuration.exchange }} - {{ configuration.symbol }} - {{ strategy }} - {{ configuration.period }} - espend.de"></div>
5656
</div>
5757
<!-- /.card-body -->
5858
</div>

templates/backtest_submit_multiple.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<div class="col-md-12">
3636
<div class="card">
3737
<div class="card-header">
38-
<h3 class="card-title">{{ backtest.pair }}</h3>
38+
<h3 class="card-title">{{ backtest.pair }} <span class="text-muted"> - {{ backtest.result.strategy }} - {{ backtest.result.configuration.period }} - {{ backtest.result.start|date('y-m-d H:i:s') }} - {{ backtest.result.end|date('y-m-d H:i:s') }}</span></h3>
3939
</div>
4040
<!-- /.card-header -->
4141
<div class="card-body">

templates/components/backtest_table.html.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<tbody>
1818
{% for row in rows %}
1919
<tr>
20-
<td style="white-space: nowrap">{{ row.time|date('y-m-d H:i:s') }}</td>
21-
<td>{{ row.price|default }}</td>
22-
<td>
20+
<td class="no-wrap">{{ row.time|date('y-m-d H:i:s') }}</td>
21+
<td class="no-wrap">{{ row.price|default }}</td>
22+
<td class="no-wrap">
2323
{% if row.profit is defined %}
2424
<span class="{{ row.profit > 0 ? 'text-success' : 'text-danger' }} {{ row.result.signal|default == 'close' ? ' font-weight-bold' : '' }}">{{ row.profit|round(2) }} %</span>
2525
{% endif %}

web/static/css/style.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ nav {
6363
writing-mode: vertical-rl;
6464
transform: rotate(180deg);
6565
display: inline-block;
66-
}
66+
}
67+
68+
.no-wrap {
69+
white-space: nowrap;
70+
}

0 commit comments

Comments
 (0)