indicator-supertrend
v0.0.1
Published
supertrend indicator
Downloads
11
Readme
indicator-supertrend
js version of Olivier Seban's "supertrend" indicator for OHLCV candles
Installation
npm i indicator-supertrend
Usage
var candles = require('candles-sample-aapl').loadNMinuteCandles(60).slice(50);
var superTrend = require('indicator-supertrend').appendSupertrend;
var period = 14;
superTrend(candles, period); //works in-place
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,
// superTrend: {
// '14': {
// fub: 150.5483357142857,
// flb: 144.3216642857143,
// tr: 1.1350000000000193,
// atr: 1.037778571428571,
// bub: 150.5483357142857,
// blb: 144.3216642857143,
// signal: 150.5483357142857,
// isSuperTrendBuySignal: false,
// isSuperTrendSellSignal: false
// }
// }
// }
//rest of code just for charting...
var {drawChartForCandles,saveChartForCandles} = require('ohlc-chart-simple');
candles = candles.map(function(candle,index){
if( candle.superTrend[period+'']){
var signalST = candle.superTrend[period+''].signal;
candle.indicators = {
...candle.indicators,
"ST_LINE": signalST,
"ST_LINE_color": candle.superTrend[period+''].isBullish ? [0,128,0] : [128,0,0],
"ST_LINE_thickness": 1
}
}
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);