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

Stddev - simple version #886

Closed
wants to merge 1 commit into from
Closed
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
49 changes: 27 additions & 22 deletions extensions/strategies/stddev/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@ module.exports = function container (get, set, clear) {
name: 'stddev',
description: 'Buy when standard deviation and mean increase, sell on mean decrease.',
getOptions: function () {
this.option('period', 'period length, set poll trades to 100ms, poll order 1000ms', String, '100ms')
this.option('trendtrades_1', "Trades for array 1 to be subtracted stddev and mean from", Number, 5)
this.option('trendtrades_2', "Trades for array 2 to be calculated stddev and mean from", Number, 53)
this.option('min_periods', "min_periods", Number, 1250)
this.option('period', 'period length, set poll trades to 100ms, poll order 1000ms', String, '1s')
this.option('trendtrades_1', "Trades for array 1 to be subtracted stddev and mean from", Number, 100)
this.option('min_periods', "min_periods", Number, 3000)
},
calculate: function (s) {
calculated = null
},
onPeriod: function (s, cb) {
get('lib.ema')(s, 'stddev', s.options.stddev)
var tl0 = []
var tl1 = []
if (s.lookback[s.options.min_periods]) {
if (s.lookback[s.options.trendtrades_1 + 500]) {
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) }
s.std0 = stats.stdev(tl0) / 2
s.std1 = stats.stdev(tl1) / 2
s.std0 = stats.stdev(tl0)
s.mean0 = math.mean(tl0)
s.mean1 = math.mean(tl1)
s.sig0 = s.std0 > s.std1 ? 'Up' : 'Down';
s.sig1 = s.mean0 > s.mean1 ? 'Up' : 'Down';
}
if (s.sig1 === 'Down') {
s.signal = 'sell'
}
else if (s.sig0 === 'Up' && s.sig1 === 'Up') {
s.signal = 'buy'
}
s.low = tl0[0] - s.std0
s.high = tl0[0] + s.std0
s.buylow = s.mean0 < s.low
s.sellhigh = s.mean0 > s.high
}
},
onPeriod: function (s, cb) {
if (
s.sellhigh === true
)
{
s.signal = 'sell'
}
if (
s.buylow === true
)
{
s.signal = 'buy'
}
cb()
},
onReport: function (s) {
var cols = []
cols.push(z(s.signal, ' ')[s.signal === false ? 'red' : 'green'])
cols.push(z(8, n(s.mean0).format('0.00000')))
cols.push(' ')
cols.push(z(8, n(s.std0).format('0.00000')))
return cols
},
}
Expand Down