Last active
June 13, 2018 23:29
-
-
Save askmike/f6d0b12c1ef9a9989c717fc4e12b7620 to your computer and use it in GitHub Desktop.
multiple-ema.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers | |
var _ = require('lodash'); | |
var log = require('../core/log.js'); | |
// let's create our own method | |
var method = {}; | |
// prepare everything our method needs | |
method.init = function() { | |
this.name = 'multiple-emas'; | |
// step 1: register all the EMAs you want: | |
// all the short EMAs | |
this.addIndicator('shortEma1', 'EMA', 1); | |
this.addIndicator('shortEma2', 'EMA', 2); | |
this.addIndicator('shortEma3', 'EMA', 3); | |
this.addIndicator('shortEma4', 'EMA', 4); | |
this.addIndicator('shortEma5', 'EMA', 5); | |
this.addIndicator('shortEma6', 'EMA', 6); | |
// all the long EMAs | |
this.addIndicator('longEma1', 'EMA', 20); | |
this.addIndicator('longEma2', 'EMA', 21); | |
this.addIndicator('longEma3', 'EMA', 22); | |
this.addIndicator('longEma4', 'EMA', 23); | |
this.addIndicator('longEma5', 'EMA', 24); | |
this.addIndicator('longEma6', 'EMA', 25); | |
} | |
method.check = function(candle) { | |
// step 2: check all the results | |
var shortEmas = [ | |
this.indicators.shortEma1.result, | |
this.indicators.shortEma2.result, | |
this.indicators.shortEma3.result, | |
this.indicators.shortEma4.result, | |
this.indicators.shortEma5.result, | |
this.indicators.shortEma6.result | |
]; | |
var longEmas = [ | |
this.indicators.longEma1.result, | |
this.indicators.longEma2.result, | |
this.indicators.longEma3.result, | |
this.indicators.longEma4.result, | |
this.indicators.longEma5.result, | |
this.indicators.longEma6.result | |
]; | |
// console.log('shortEmas:', shortEmas); | |
// console.log('longEmas:', longEmas); | |
var lowestShortEma = _.min(shortEmas); | |
var highestLongEma = _.max(longEmas); | |
if(lowestShortEma > highestLongEma) { | |
this.advice('long'); | |
} | |
var highestShortEma = _.max(shortEmas); | |
var lowestLongEma = _.min(longEmas); | |
if(highestShortEma < lowestLongEma) { | |
this.advice('short'); | |
} | |
} | |
module.exports = method; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Im trying to do this with three talib EMA's
I get "TypeError: Cannot read property 'long2Size' of undefined"
this.addTalibIndicator('longEMA2', 'ema', {optInTimePeriod : this.settings.long2Size});
Thoughts?