Created
December 17, 2023 18:55
-
-
Save piboistudios/e2c26be8094b883503a93a5550d7a253 to your computer and use it in GitHub Desktop.
Live Indicator Wrapper for `trading-signals` (requires `deepclone`)
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
import clone from 'deepclone'; | |
import * as signals from 'trading-signals'; | |
export class Indicator { | |
constructor(indicator) { | |
this.values = []; | |
this.indicator = indicator; | |
} | |
update(v) { | |
this.last = clone(this.indicator); | |
const value = this.indicator.update(v); | |
this.values.push(value); | |
return value; | |
} | |
replace(v) { | |
const head = clone(this.last); | |
const value = head.update(v); | |
this.values.splice(this.values.length - 1, 1, value); | |
return value; | |
} | |
get value() { | |
return this.values[this.values.length - 1]; | |
} | |
static mk(indicator, args) { | |
const i = new signals[indicator](...args); | |
return new Indicator(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment