Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/extension/indicator/currentRatio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const currentRatio: IndicatorTemplate<Cr, number> = {
const ma3List: number[] = []
let ma4Sum = 0
const ma4List: number[] = []
let highSubSum = 0
let preMidSubSum = 0
const result: Cr[] = []
dataList.forEach((kLineData, i) => {
const cr: Cr = {}
Expand All @@ -73,9 +75,19 @@ const currentRatio: IndicatorTemplate<Cr, number> = {

const preMidSubLow = Math.max(0, prevMid - kLineData.low)

highSubSum += highSubPreMid
preMidSubSum += preMidSubLow
if (i >= params[0]) {
const outData = dataList[i - params[0]]
const outPrevData = dataList[i - params[0] - 1] ?? outData
const outPrevMid = (outPrevData.high + outPrevData.low) / 2
highSubSum -= Math.max(0, outData.high - outPrevMid)
preMidSubSum -= Math.max(0, outPrevMid - outData.low)
}

if (i >= params[0] - 1) {
if (preMidSubLow !== 0) {
cr.cr = (highSubPreMid / preMidSubLow) * 100
if (preMidSubSum !== 0) {
cr.cr = (highSubSum / preMidSubSum) * 100
} else {
cr.cr = 0
}
Expand Down