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

money.rave.common.backend.expression.indicator.Ma.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 Ma(
    private val candleCount: Int,
    private val expression: Expression,
    private val defaultCandleIndex: Int = 0,
) : Expression {

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

    override fun evaluate(context: EvaluationContext, candleIndex: Int): BigDecimal {
        val index = defaultCandleIndex + candleIndex
        if (!context.candleDatas[index].data.has(name)) {
            val ma = (0 until candleCount).sumOf { expression.evaluate(context, index + it) } / candleCount.scaledBigDecimal()
            context.candleDatas[index].data.addProperty(name, ma)
        }
        return context.candleDatas[index].data.getAsJsonPrimitive(name).asBigDecimal.scaledBigDecimal()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy