Skip to content

Commit

Permalink
feat: add OBV and fix RSI (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 authored Dec 6, 2023
1 parent 04cd644 commit 7d9f15a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions @libs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from "./indicators/MACD";
export * from "./indicators/MAX";
export * from "./indicators/MIN";
export * from "./indicators/NVI";
export * from "./indicators/OBV";
export * from "./indicators/PROD";
export * from "./indicators/RANGE";
export * from "./indicators/RANK";
Expand Down
24 changes: 24 additions & 0 deletions @libs/indicators/OBV.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEMA, useSeriesMap } from "@libs";

/**
* On Balance Volume
* @param source - Source Price
* @param volume - Volume
*/
export const useOBV = (source: Series, volume: Series) => {
return useSeriesMap(
`OBV(${source.name})`,
source,
{ display: "line", chart: "new" },
(i, obv) => {
if (i === 0) return 0;
if (source[i] > source[i - 1]) {
return obv[i - 1] + volume[i];
}
if (source[i] < source[i - 1]) {
return obv[i - 1] - volume[i];
}
return obv[i - 1];
}
);
};
4 changes: 4 additions & 0 deletions @libs/indicators/RSI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const useRSI = (source: Series, period = 14) => {
);
const EMA_U = useEMA(U, period);
const EMA_D = useEMA(D, period);
useEffect(() => {
EMA_U.tags.display = "none";
EMA_D.tags.display = "none";
}, []);
const RSI = useSeriesMap(
`RSI(${source.name},${period})`,
source,
Expand Down

0 comments on commit 7d9f15a

Please sign in to comment.