Skip to content

Commit

Permalink
add rsi
Browse files Browse the repository at this point in the history
  • Loading branch information
nenjotsu committed Jan 16, 2022
1 parent 1b05b9a commit 8a65e4e
Show file tree
Hide file tree
Showing 95 changed files with 5,053 additions and 82 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# deno-talib
deno-talib port technical analysis of [https://github.com/anandanand84/technicalindicators](https://github.com/anandanand84/technicalindicators)
# deno-talib (WIP)
deno-talib port technical analysis of [https://github.com/anandanand84/technicalindicators](https://github.com/anandanand84/technicalindicators)
161 changes: 81 additions & 80 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
// export * from './lib/index.js';
export function getAvailableIndicators () {
let AvailableIndicators = []
AvailableIndicators.push('sma');
AvailableIndicators.push('ema');
AvailableIndicators.push('wma');
AvailableIndicators.push('wema');
AvailableIndicators.push('macd');
export * from './lib/index.ts';
export const getAvailableIndicators = () => {
const AvailableIndicators: string[] = []
// AvailableIndicators.push('sma');
// AvailableIndicators.push('ema');
// AvailableIndicators.push('wma');
// AvailableIndicators.push('wema');
// AvailableIndicators.push('macd');
AvailableIndicators.push('rsi');
AvailableIndicators.push('bollingerbands');
AvailableIndicators.push('adx');
AvailableIndicators.push('atr');
AvailableIndicators.push('truerange');
AvailableIndicators.push('roc');
AvailableIndicators.push('kst');
AvailableIndicators.push('psar');
AvailableIndicators.push('stochastic');
AvailableIndicators.push('williamsr');
AvailableIndicators.push('adl');
AvailableIndicators.push('obv');
AvailableIndicators.push('trix');
// AvailableIndicators.push('bollingerbands');
// AvailableIndicators.push('adx');
// AvailableIndicators.push('atr');
// AvailableIndicators.push('truerange');
// AvailableIndicators.push('roc');
// AvailableIndicators.push('kst');
// AvailableIndicators.push('psar');
// AvailableIndicators.push('stochastic');
// AvailableIndicators.push('williamsr');
// AvailableIndicators.push('adl');
// AvailableIndicators.push('obv');
// AvailableIndicators.push('trix');

AvailableIndicators.push('cci');
AvailableIndicators.push('awesomeoscillator');
AvailableIndicators.push('forceindex');
AvailableIndicators.push('vwap');
AvailableIndicators.push('volumeprofile');
AvailableIndicators.push('renko');
AvailableIndicators.push('heikinashi');
// AvailableIndicators.push('cci');
// AvailableIndicators.push('awesomeoscillator');
// AvailableIndicators.push('forceindex');
// AvailableIndicators.push('vwap');
// AvailableIndicators.push('volumeprofile');
// AvailableIndicators.push('renko');
// AvailableIndicators.push('heikinashi');

AvailableIndicators.push('stochasticrsi');
AvailableIndicators.push('mfi');
// AvailableIndicators.push('stochasticrsi');
// AvailableIndicators.push('mfi');

AvailableIndicators.push('averagegain');
AvailableIndicators.push('averageloss');
AvailableIndicators.push('highest');
AvailableIndicators.push('lowest');
AvailableIndicators.push('sum');
AvailableIndicators.push('FixedSizeLinkedList');
AvailableIndicators.push('sd');
AvailableIndicators.push('bullish');
AvailableIndicators.push('bearish');
AvailableIndicators.push('abandonedbaby');
AvailableIndicators.push('doji');
AvailableIndicators.push('bearishengulfingpattern');
AvailableIndicators.push('bullishengulfingpattern');
AvailableIndicators.push('darkcloudcover');
AvailableIndicators.push('downsidetasukigap');
AvailableIndicators.push('dragonflydoji');
AvailableIndicators.push('gravestonedoji');
AvailableIndicators.push('bullishharami');
AvailableIndicators.push('bearishharami');
AvailableIndicators.push('bullishharamicross');
AvailableIndicators.push('bearishharamicross');
AvailableIndicators.push('eveningdojistar');
AvailableIndicators.push('eveningstar');
AvailableIndicators.push('morningdojistar');
AvailableIndicators.push('morningstar');
AvailableIndicators.push('bullishmarubozu');
AvailableIndicators.push('bearishmarubozu');
AvailableIndicators.push('piercingline');
AvailableIndicators.push('bullishspinningtop');
AvailableIndicators.push('bearishspinningtop');
AvailableIndicators.push('threeblackcrows');
AvailableIndicators.push('threewhitesoldiers');
AvailableIndicators.push('bullishhammerstick');
AvailableIndicators.push('bearishhammerstick');
AvailableIndicators.push('bullishinvertedhammerstick');
AvailableIndicators.push('bearishinvertedhammerstick');
AvailableIndicators.push('hammerpattern');
AvailableIndicators.push('hammerpatternunconfirmed');
AvailableIndicators.push('hangingman');
AvailableIndicators.push('hangingmanunconfirmed');
AvailableIndicators.push('shootingstar');
AvailableIndicators.push('shootingstarunconfirmed');
AvailableIndicators.push('tweezertop');
AvailableIndicators.push('tweezerbottom');
// AvailableIndicators.push('averagegain');
// AvailableIndicators.push('averageloss');
// AvailableIndicators.push('highest');
// AvailableIndicators.push('lowest');
// AvailableIndicators.push('sum');
// AvailableIndicators.push('FixedSizeLinkedList');
// AvailableIndicators.push('sd');
// AvailableIndicators.push('bullish');
// AvailableIndicators.push('bearish');
// AvailableIndicators.push('abandonedbaby');
// AvailableIndicators.push('doji');
// AvailableIndicators.push('bearishengulfingpattern');
// AvailableIndicators.push('bullishengulfingpattern');
// AvailableIndicators.push('darkcloudcover');
// AvailableIndicators.push('downsidetasukigap');
// AvailableIndicators.push('dragonflydoji');
// AvailableIndicators.push('gravestonedoji');
// AvailableIndicators.push('bullishharami');
// AvailableIndicators.push('bearishharami');
// AvailableIndicators.push('bullishharamicross');
// AvailableIndicators.push('bearishharamicross');
// AvailableIndicators.push('eveningdojistar');
// AvailableIndicators.push('eveningstar');
// AvailableIndicators.push('morningdojistar');
// AvailableIndicators.push('morningstar');
// AvailableIndicators.push('bullishmarubozu');
// AvailableIndicators.push('bearishmarubozu');
// AvailableIndicators.push('piercingline');
// AvailableIndicators.push('bullishspinningtop');
// AvailableIndicators.push('bearishspinningtop');
// AvailableIndicators.push('threeblackcrows');
// AvailableIndicators.push('threewhitesoldiers');
// AvailableIndicators.push('bullishhammerstick');
// AvailableIndicators.push('bearishhammerstick');
// AvailableIndicators.push('bullishinvertedhammerstick');
// AvailableIndicators.push('bearishinvertedhammerstick');
// AvailableIndicators.push('hammerpattern');
// AvailableIndicators.push('hammerpatternunconfirmed');
// AvailableIndicators.push('hangingman');
// AvailableIndicators.push('hangingmanunconfirmed');
// AvailableIndicators.push('shootingstar');
// AvailableIndicators.push('shootingstarunconfirmed');
// AvailableIndicators.push('tweezertop');
// AvailableIndicators.push('tweezerbottom');

// AvailableIndicators.push('predictPattern');
// AvailableIndicators.push('hasDoubleBottom');
Expand All @@ -83,16 +83,17 @@ export function getAvailableIndicators () {
// AvailableIndicators.push('hasInverseHeadAndShoulder');
// AvailableIndicators.push('isTrendingUp');
// AvailableIndicators.push('isTrendingDown');
AvailableIndicators.push('ichimokucloud');

// AvailableIndicators.push('ichimokucloud');

AvailableIndicators.push('keltnerchannels');
AvailableIndicators.push('chandelierexit');
AvailableIndicators.push('crossup');
AvailableIndicators.push('crossdown');
AvailableIndicators.push('crossover');
// AvailableIndicators.push('keltnerchannels');
// AvailableIndicators.push('chandelierexit');
// AvailableIndicators.push('crossup');
// AvailableIndicators.push('crossdown');
// AvailableIndicators.push('crossover');
return AvailableIndicators;
};

let AvailableIndicators = getAvailableIndicators();
const AvailableIndicators = getAvailableIndicators();
console.log('AvailableIndicators', AvailableIndicators);
export { AvailableIndicators }
20 changes: 20 additions & 0 deletions lib/StockData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default class StockData {
constructor(open, high, low, close, reversedInput) {
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.reversedInput = reversedInput;
}
}
export class CandleData {}
export class CandleList {
constructor() {
this.open = [];
this.high = [];
this.low = [];
this.close = [];
this.volume = [];
this.timestamp = [];
}
}
68 changes: 68 additions & 0 deletions lib/Utils/AverageGain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// deno-lint-ignore-file
import { Indicator, IndicatorInput } from '../indicator/indicator.ts';
export class AvgGainInput extends IndicatorInput {
}
export class AverageGain extends Indicator {
generator: Generator<any,never,any>;
static calculate: (input: { reversedInput: any; values?: any[]|undefined; open?: any[]|undefined; high?: any[]|undefined; low?: any[]|undefined; close?: any[]|undefined; volume?: any[]|undefined; timestamp?: any[]|undefined; }) => any;
constructor(input: { period?: any; values?: any; format?: (v: any) => any; } | any) {
super(input);
let values = input.values;
let period = input.period;
let format = this.format;
this.generator = (function* (period) {
// @ts-ignore
var currentValue = yield;
var counter = 1;
var gainSum = 0;
var avgGain;
var gain;
var lastValue = currentValue;
// @ts-ignore
currentValue = yield;
while (true) {
gain = currentValue - lastValue;
gain = gain > 0 ? gain : 0;
if (gain > 0) {
gainSum = gainSum + gain;
}
if (counter < period) {
counter++;
}
else if (avgGain === undefined) {
avgGain = gainSum / period;
}
else {
avgGain = ((avgGain * (period - 1)) + gain) / period;
}
lastValue = currentValue;
avgGain = (avgGain !== undefined) ? format(avgGain) : undefined;
// @ts-ignore
currentValue = yield avgGain;
}
})(period);
this.generator.next();
this.result = [];
values.forEach((tick: any) => {
var result = this.generator.next(tick);
if (result.value !== undefined) {
this.result.push(result.value);
}
});
}
nextValue(price: any) {
return this.generator.next(price).value;
}
;
}
AverageGain.calculate = averagegain;
export function averagegain(input: { reversedInput: any; values?: any[]; open?: any[]; high?: any[]; low?: any[]; close?: any[]; volume?: any[]; timestamp?: any[]; } | any) {
Indicator.reverseInputs(input);
var result = new AverageGain(input).result;
if (input.reversedInput) {
result.reverse();
}
Indicator.reverseInputs(input);
return result;
}
;
68 changes: 68 additions & 0 deletions lib/Utils/AverageLoss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// deno-lint-ignore-file
import { Indicator, IndicatorInput } from '../indicator/indicator.ts';
export class AvgLossInput extends IndicatorInput {
}
export class AverageLoss extends Indicator {
generator: Generator<any,never,any>;
static calculate: (input: { reversedInput: any; values?: any[]|undefined; open?: any[]|undefined; high?: any[]|undefined; low?: any[]|undefined; close?: any[]|undefined; volume?: any[]|undefined; timestamp?: any[]|undefined; }) => any;
constructor(input: { period?: any; values?: any; format?: (v: any) => any; } | any) {
super(input);
let values = input.values;
let period = input.period;
let format = this.format;
this.generator = (function* (period) {
// @ts-ignore
var currentValue = yield;
var counter = 1;
var lossSum = 0;
var avgLoss;
var loss;
var lastValue = currentValue;
// @ts-ignore
currentValue = yield;
while (true) {
loss = lastValue - currentValue;
loss = loss > 0 ? loss : 0;
if (loss > 0) {
lossSum = lossSum + loss;
}
if (counter < period) {
counter++;
}
else if (avgLoss === undefined) {
avgLoss = lossSum / period;
}
else {
avgLoss = ((avgLoss * (period - 1)) + loss) / period;
}
lastValue = currentValue;
avgLoss = (avgLoss !== undefined) ? format(avgLoss) : undefined;
// @ts-ignore
currentValue = yield avgLoss;
}
})(period);
this.generator.next();
this.result = [];
values.forEach((tick: any) => {
var result = this.generator.next(tick);
if (result.value !== undefined) {
this.result.push(result.value);
}
});
}
nextValue(price: any) {
return this.generator.next(price).value;
}
;
}
AverageLoss.calculate = averageloss;
export function averageloss(input: { reversedInput: any; values?: any[]; open?: any[]; high?: any[]; low?: any[]; close?: any[]; volume?: any[]; timestamp?: any[]; } | any) {
Indicator.reverseInputs(input);
var result = new AverageLoss(input).result;
if (input.reversedInput) {
result.reverse();
}
Indicator.reverseInputs(input);
return result;
}
;
Loading

0 comments on commit 8a65e4e

Please sign in to comment.