-
Notifications
You must be signed in to change notification settings - Fork 3
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
4 changed files
with
70 additions
and
0 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
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,24 @@ | ||
import { useEMA, useSeriesMap } from "@libs"; | ||
|
||
export const useNVI = (volume: Series, close: Series, period: number = 72) => { | ||
const NVI = useSeriesMap( | ||
`NVI`, | ||
close, | ||
{ display: "line", chart: "new" }, | ||
(i, s) => | ||
i === 0 | ||
? 100 | ||
: s[i - 1] * | ||
(volume[i] < volume[i - 1] | ||
? Math.abs( | ||
// abs 是对负数价格的特殊处理 | ||
close[i] / close[i - 1] | ||
) | ||
: 1) | ||
); | ||
const MA_NVI = useEMA(NVI, period); | ||
useEffect(() => { | ||
MA_NVI.name = "MA_NVI"; | ||
}, []); | ||
return { NVI: NVI, MA_NVI: MA_NVI }; | ||
}; |
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,21 @@ | ||
// TD 序列指标 | ||
export const useTD = (source: Series) => { | ||
const TD = useSeries("Output", source, { | ||
display: "hist", | ||
chart: "new", | ||
}); | ||
|
||
useEffect(() => { | ||
const i = source.length - 1; | ||
if (i < 0) return; | ||
TD[i] = 0; | ||
if (source[i] > source[i - 4]) { | ||
TD[i] = Math.max(0, TD[i - 1] ?? 0) + 1; | ||
} | ||
if (source[i] < source[i - 4]) { | ||
TD[i] = Math.min(0, TD[i - 1] ?? 0) - 1; | ||
} | ||
}); | ||
|
||
return { TD }; | ||
}; |
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,22 @@ | ||
import { useSUM, useSeriesMap } from "@libs"; | ||
|
||
/** | ||
* 加权移动平均线 WMA | ||
*/ | ||
export const useWMA = (source: Series, weight: Series, period: number) => { | ||
const prod = useSeriesMap("Prod", source, {}, (i) => source[i] * weight[i]); | ||
|
||
const sumOfProd = useSUM(prod, period); | ||
const sumOfWeight = useSUM(weight, period); | ||
|
||
const WMA = useSeriesMap( | ||
`WMA(${period})`, | ||
source, | ||
{ | ||
display: "line", | ||
}, | ||
(i) => sumOfProd[i] / sumOfWeight[i] | ||
); | ||
|
||
return { WMA }; | ||
}; |