All Downloads are FREE. Search and download functionalities are using the official Maven repository.

money.rave.common.backend.expression.indicator.BolingerBandPercent.kt Maven / Gradle / Ivy

package money.rave.common.backend.expression

import money.rave.common.backend.scaledBigDecimal
import java.math.BigDecimal

class BolingerBandPercent(
    private val candleCount: Int,
    private val multiplyFactor: BigDecimal = 2.scaledBigDecimal(),
    private val defaultCandleIndex: Int = 0,
) : Expression {

    private val name = "${javaClass.simpleName}:$candleCount:$multiplyFactor"

    override fun evaluate(context: EvaluationContext, candleIndex: Int): BigDecimal {
        val index = defaultCandleIndex + candleIndex
        if (!context.candleDatas[index].data.has(name)) {
            val close = Close().evaluate(context, index)
            val lowerBolingerBand = LowerBolingerBand(candleCount, multiplyFactor).evaluate(context, index)
            val upperBolingerBand = UpperBolingerBand(candleCount, multiplyFactor).evaluate(context, index)
            val b = (close - lowerBolingerBand) / (upperBolingerBand - lowerBolingerBand)

            context.candleDatas[index].data.addProperty(name, b.scaledBigDecimal())
        }
        return context.candleDatas[index].data.getAsJsonPrimitive(name).asBigDecimal
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy