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

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

package money.rave.common.backend.expression

import money.rave.common.backend.expression.EvaluationContext
import money.rave.common.backend.expression.Expression
import money.rave.common.backend.scaledBigDecimal
import java.math.BigDecimal

class LowerEnvelope(
    private val candleCount: Int,
    private val ratio: BigDecimal,
    private val maExpression: Expression,
    private val defaultCandleIndex: Int = 0,
) : Expression {

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

    override fun evaluate(context: EvaluationContext, candleIndex: Int): BigDecimal {
        val index = defaultCandleIndex + candleIndex
        if (!context.candleDatas[index].data.has(name)) {
            val ma = Ma(candleCount, maExpression).evaluate(context, index)

            context.candleDatas[index].data.addProperty(name, ma - ma * ratio)
        }
        return context.candleDatas[index].data.getAsJsonPrimitive(name).asBigDecimal.scaledBigDecimal()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy