Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SMA = require('technicalindicators').SMA;
- function movingAverage() {
- var toBuy = false;
- publicClient.getKline (function(error, data) {
- if(error)
- return false;
- var prices = [];
- var ema = [];
- var ama = [];
- data.forEach(function(val){
- prices.push(val[1]);
- })
- var sma = new SMA({period : 7, values : prices});
- var sme = new SMA({period : 30, values : prices});
- prices.forEach(function(val){
- var csma = sma.nextValue(val);
- var csme = sme.nextValue(val);
- if( csme < csma && toBuy == false) {
- toBuy = true;
- }
- if(toBuy == true && csme > csma ) {
- toBuy = false;
- }
- })
- }, 'btc_cny', '3min', 2000);
- return toBuy;
- }
- RAW Paste Data
- const SMA = require('technicalindicators').SMA;
- function movingAverage() {
- var toBuy = false;
- publicClient.getKline (function(error, data) {
- if(error)
- return false;
- var prices = [];
- var ema = [];
- var ama = [];
- data.forEach(function(val){
- prices.push(val[1]);
- })
- var sma = new SMA({period : 7, values : prices});
- var sme = new SMA({period : 30, values : prices});
- prices.forEach(function(val){
- var csma = sma.nextValue(val);
- var csme = sme.nextValue(val);
- if( csme < csma && toBuy == false) {
- toBuy = true;
- }
- if(toBuy == true && csme > csma ) {
- toBuy = false;
- }
- })
- }, 'btc_cny', '3min', 2000);
- return toBuy;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement