Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var jsonfile = require('jsonfile')
- var file = 'data/BTC_ETH.json';
- var analyze = {
- averagePrice: function(prices){
- var totalPrice = 0;
- for(price of prices){
- totalPrice+=price;
- }
- return totalPrice / prices.length;
- },
- lowestPrice: function(prices){
- var lowest = 9999999;
- for(price of prices){
- if(price < lowest){
- lowest = price;
- }
- }
- return lowest;
- },
- highestPrice: function(prices){
- var highest = 0;
- for(price of prices){
- if(price > highest){
- highest = price;
- }
- }
- return highest;
- },
- support: function(prices){
- var termCounter = 0, supportPrice = prices[0], supportPrices = [];
- for(price of prices){
- if(price < supportPrice){
- supportPrice = price;
- termCounter = 0;
- } else{
- termCounter++;
- if(termCounter == 5000){
- supportPrices.push(supportPrice);
- termCounter = 0;
- supportPrice = price;
- }
- }
- }
- return supportPrices;
- },
- resistance: function(prices){
- var termCounter = 0, resistance = prices[0], reistancePrices = [];
- for(price of prices){
- if(price > resistancePrice){
- }
- }
- },
- all: function(prices){
- console.log("average price is " + analyze.averagePrice(prices));
- console.log("lowest price is " + analyze.lowestPrice(prices));
- console.log("highest price is " + analyze.highestPrice(prices));
- console.log("support prices are at " + analyze.support(prices));
- }
- }
- function readData(obj){
- console.log("file is " + obj.length + " candles long");
- var Xcandle = 0;
- var prices = [];
- var averagePrice;
- for(candle of obj){
- Xcandle++;
- prices.push(candle.c);
- }
- analyze.all(prices);
- console.log("done, modeled " + Xcandle + " candles.");
- }
- jsonfile.readFile(file, function(err, obj) {
- console.log(err);
- readData(obj);
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement