Created
May 4, 2017 11:41
-
-
Save Pedro942/b05d4340d44ecd7c02ecbe2bcfeab1ae to your computer and use it in GitHub Desktop.
Start.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
// Let's create our own strategy | |
var strat = {}; | |
// Prepare everything our strat needs | |
strat.init = function() { | |
// start of with no investment | |
this.currentTrend = 'short'; | |
// your code! | |
// add a native MACD | |
var parameters = {short: 12, long: 26, signal: 9,down = -0.0001, | |
up = 0.005,persistence = 1}; | |
this.addIndicator('mynativemacd', 'MACD', parameters); | |
//add native RSI | |
var parameters1 = {interval = 14,low = 30, high = 70, persistence = 2}; | |
this.addIndicator('mynativeRSI', 'RSI', parameters1); | |
//add native CCI | |
var parameters2 = {constant = 0.015,history = 90,up = 100,down = -100,persistence = 0}; | |
this.addIndicator('mynativeCCI','CCI',parameters2); | |
} | |
// What happens on every new candle? | |
strat.update = function(candle) { | |
// your code! | |
} | |
// For debugging purposes. | |
strat.log = function() { | |
// your code! | |
} | |
// Based on the newly calculated | |
// information, check if we should | |
// update or not. | |
strat.check = function() { | |
// your code! | |
//setting vars for MACD results | |
var MACD = this.indicators.macd.macd; | |
var MACDsaysBUY = down < -0.0001; | |
var MACDsaysSELL = up > 0.005; | |
// setting vars for RSI results | |
var RSI = this.indicators.rsi.rsi; | |
var RSIsaysBUY = RSI > RSIhigh; | |
var RSIsaysSELL = RSI < RSIlow; | |
// setting vars for CCI results | |
var CCI = this.indicators.cci.cci; | |
var CCIsaysBUY = down < -100; | |
var CCIsaysSELL = up > 100; | |
/// Setting conditions | |
if(this.currentTrend === 'long') { | |
// maybe we need to advice short now? | |
// only if BOTH MACD and RSI and CCI say so: | |
if(MACDsaysSELL && RSIsaysSELL && CCIsaysSELL ) { | |
this.currentTrend = 'short'; | |
this.advice('short') | |
} | |
} else if(this.currentTrend === 'short') { | |
// maybe we need to advice long now? | |
// only if BOTH MACD and RSI and CCI say so: | |
if(MACDsaysBUY && RSIsaysBUY && CCIsaysBUY) { | |
this.currentTrend = 'long'; | |
this.advice('long') | |
} | |
} | |
module.exports = strat; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment