Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Standard Deviation Strategy #688

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/strategies/stddev/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
_ns: 'zenbot',

'strategies.stddev': require('./strategy'),
'strategies.list[]': '#strategies.stddev'
}
51 changes: 51 additions & 0 deletions extensions/strategies/stddev/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//"sudo ./zenbot.sh sim --strategy=stddev --trendtrades_1=2500 --days=7 --period=100ms --min_periods=3000";
var z = require('zero-fill')
var stats = require('stats-lite')
var n = require('numbro')
var math = require('mathjs');
var tl0mp = []
module.exports = function container (get, set, clear) {
return {
name: 'stddev',
description: 'Trade when % change from last two 1m periods is higher than average.',

getOptions: function () {
this.option('period', 'period length', String, '100ms')
this.option('trendtrades_1', "Trades for trend 1", Number, 2500)
this.option('selector', "Selector", String, 'Gdax.BTC-USD')
this.option('min_periods', "min_periods", Number, 3000)
},


calculate: function (s) {
get('lib.ema')(s, 'stddev', s.options.stddev)
var tl0 = []
if (s.lookback[s.options.trendtrades_1]) {
for (let i = 0; i < s.options.trendtrades_1; i++) { tl0.push(s.lookback[i].close) }
s.tlst0 = stats.stdev(tl0)
s.mean = math.mean(tl0)
s.sign = s.mean - s.tlst0
s.sig = tl0[0] - s.sign
}
},

onPeriod: function (s, cb) {
if (
s.sig > 0

) {
s.signal = 'buy'
}
else {
s.signal = 'sell'
}
cb()
},

onReport: function (s) {
var cols = []
cols.push(z(s.signal, ' ')[s.signal === false ? 'red' : 'green'])
return cols
},
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"talib": "^1.0.3",
"timebucket": "^0.4.0",
"ws": "^3.2.0",
"zero-fill": "^2.2.3"
"zero-fill": "^2.2.3",
"stats-lite": "2.1.0",
"stats-array": "0.1.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

},
"devDependencies": {
"eslint": "^4.7.1"
Expand Down
23 changes: 23 additions & 0 deletions simulations/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. php?

$path_to_check = '';
$needle = 'end balance:';
$needle2 = 'error rate: ';
foreach(glob($path_to_check . '*.html') as $filename)
{
foreach(file($filename) as $fli=>$fl)
{
if(strpos($fl, $needle)!==false)
{
echo $filename . ' on line ' . ($fli+1) . ': ' . $fl;
}
}
foreach(file($filename) as $fli=>$fly)
{
if(strpos($fly, $needle2)!==false)
{
echo $fly;
echo '<br>';
}
}
}
?>