indicator-hi-low-trailing
v0.0.12
Published
given an array of ohlcv candles, efficiently add trailing hi-low values for the previous [3,5,15,30,60,120,240,390,1440] candles
Downloads
1
Readme
indicator-hi-low-trailing
given an array of ohlcv candles, efficiently add trailing hi-low values for the previous [3,5,15,30,60,120,240,390,1440]
candles
experimental, use at your own risk
Installation
npm i indicator-hi-low-trailing
Usage
var candles = require('candles-sample-aapl').loadNMinuteCandles(60).slice(50);
//calculateHiLowsTrailing(candles, _periods=[3,5,15,30,60,120,240,390,1440])
require('indicator-hi-low-trailing').calculateHiLowsTrailing(candles);
//to push a new candle to candles with existing high/low data
//updateHiLowsTrailing(candles, newCandle, _periods=null)
console.log(candles.slice(-1)[0]);
// {
// date: '2022-12-02T20:00:00.000Z',
// open: 146.9572,
// high: 147.96,
// low: 146.91,
// close: 147.96,
// bid: 146.95,
// ask: 146.96,
// volume: 4031053,
// nSrcCandles: 17,
// hiLowsTrailing: {
// highs: {
// '3': 147.96,
// '5': 147.96,
// '15': 148.9805,
// '30': 148.9805,
// '60': 151.74,
// '120': 153.55,
// '240': 153.55,
// '390': 153.55,
// '1440': 153.55
// },
// lows: {
// '3': 146.07,
// '5': 145.9307,
// '15': 145.79,
// '30': 140.39,
// '60': 140.39,
// '120': 134.63,
// '240': 134.46,
// '390': 134.46,
// '1440': 134.46
// }
// relative: { //relative position of thsi candle's close within the span of lo...hi ==> 0...1
// '3': 0.38648648648647416, //your values will be different than this
// '5': 0.3994708994708939,
// '15': 0.3244005641748917,
// '30': 0.7490832896804595,
// '60': 0.5669603524229065,
// '120': 0.6445560253699779,
// '240': 0.647721320062859,
// '390': 0.647721320062859,
// '1440': 0.647721320062859
// }
// }
// }
//the rest of the code is just for charting...
var {drawChartForCandles,saveChartForCandles} = require('ohlc-chart-simple');
candles = candles.map(function(candle,index){
candle.indicators = {
"hi15": candle.hiLowsTrailing.highs['15'],
"hi15_color": [128,0,0],
"hi15_thickness": 0,
"hi60": candle.hiLowsTrailing.highs['60'],
"hi60_color": [128,0,0],
"hi60_thickness": 1,
"hi390": candle.hiLowsTrailing.highs['390'],
"hi390_color": [128,0,0],
"hi390_thickness": 2,
"lo15": candle.hiLowsTrailing.lows['15'],
"lo15_color": [0,128,0],
"lo15_thickness" : 0,
"lo60": candle.hiLowsTrailing.lows['60'],
"lo60_color": [0,128,0],
"lo60_thickness": 1,
"lo390": candle.hiLowsTrailing.lows['390'],
"lo390_color": [0,128,0],
"lo390_thickness": 2,
}
return candle;
});
var config = {
w: Math.floor(1024/2),
h: Math.floor(700/2),
profileBucketsTotal: 64,
profileBucketsWidth: 16,
volumeBarsHeight: 64,
bgColor: [255,255,255],
//alternative to volume profile: arbitrary kernel density histogram
kdePrices: candles.map(c=>[c.low, 1]), //[value, weight]
// kdeBandwidthDollars: 0.01,
kdeBandwidthPercent: 1.00,
kdeIsGaussian: true, //false == kernel is triangular
kdeColor: [0,0,255],
skipDrawOhlcBars: false,
skipDrawIndicators: false,
skipDrawLegend: false,
expandLegendText: false,
expandTitle: false,
expandPrice: false,
skipDrawDate: true,
skipDrawPrice: false,
skipDrawPriceBars: false,
title: "AAPL",
filename: "./candlestick-chart.png",
}
saveChartForCandles(candles, config);