Advertisement
ipsbruno2016

Media Móvel OkCoin Moving Average

Jan 19th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const SMA = require('technicalindicators').SMA;
  2.  
  3.  
  4. function movingAverage() {
  5.     var toBuy = false;
  6.  
  7.     publicClient.getKline (function(error, data) {     
  8.  
  9.         if(error)
  10.             return false;
  11.  
  12.         var prices = [];
  13.        
  14.         var ema = [];
  15.         var ama = [];
  16.  
  17.         data.forEach(function(val){
  18.             prices.push(val[1]);
  19.         })
  20.  
  21.         var sma = new SMA({period : 7, values : prices});
  22.         var sme = new SMA({period : 30, values : prices});
  23.  
  24.         prices.forEach(function(val){
  25.                        
  26.             var csma = sma.nextValue(val);
  27.             var csme = sme.nextValue(val); 
  28.            
  29.             if(  csme < csma && toBuy == false) {
  30.                 toBuy = true;
  31.             }
  32.            
  33.             if(toBuy == true && csme > csma  ) {
  34.                 toBuy = false;
  35.             }
  36.    
  37.         })
  38.     }, 'btc_cny', '3min', 2000);
  39.  
  40.     return toBuy;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement