-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
95 changed files
with
5,053 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
; |
Oops, something went wrong.