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 6 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'
}
55 changes: 55 additions & 0 deletions extensions/strategies/stddev/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
GNU nano 2.5.3 File: extensions/strategies/stddev/strategy.js
Copy link
Owner

Choose a reason for hiding this comment

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

?


var z = require('zero-fill')
var stats = require('stats-lite')
var n = require('numbro')
var tl0mp = []
var tl1mp = []
var tlst0p = []
var tlst1p = []
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, '1s')
this.option('trendtrades_1', "Trades for trend 1", Number, 100)
this.option('trendtrades_2', "Trades for trend 2", Number, 1000)
this.option('selector', "Selector", String, 'Gdax.BTC-USD')
this.option('min_periods', "min_periods", Number, 1250)
},


calculate: function (s) {
get('lib.ema')(s, 'stddev', s.options.stddev)
var tl0 = []
var tl1 = []
if (s.lookback[s.options.min_periods]) {
for (let i = 0; i < s.options.trendtrades_1; i++) { tl0.push(s.lookback[i].close) }
for (let i = 0; i < s.options.trendtrades_2; i++) { tl1.push(s.lookback[i].close) }
var tlst0 = stats.stdev(tl0)
Copy link
Owner

Choose a reason for hiding this comment

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

weird indentation starts here

var tlst1 = stats.stdev(tl1)
s.devi = tlst1 - tlst0
}
},

onPeriod: function (s, cb) {
if (
s.devi1 > 0
Copy link
Owner

Choose a reason for hiding this comment

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

weird indentation block

) {
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>';
}
}
}
?>