Bears Power (SDK Trading)

The Bears Power oscillator was used to measure the difference between a 13-day(or 14-day, adjustable parameter) Exponential Moving Average (EMA) and the lowest price, plotted as a line or a histogram. If the Bears Power indicator is below zero, it means sellers tend to drive price below the EMA.

Bears Power (SDK Trading)

registerIndicator("bears", "Bears Power(v1.0)", function (context) {
    var dataInput = getDataInput(context, 0)
    var dataInputLow = getDataInput(context, 1)
    var dataOutput = getDataOutput(context, "bears")
    var dataOutputEma = getDataOutput(context, "ema")
    var period = getIndiParameter(context, "period")

    var calculatedLength = getCalculatedLength(context)

    var ptr = calculatedLength

    if (ptr > 0) {
        ptr--
    } else {
        ptr = period - 1

        for (var i = 0; i < period - 1; i++) {
            dataOutput[i] = 0
        }
    }

    ema(dataInput, dataOutputEma, calculatedLength, period)

    while (ptr < dataInput.length) {
        dataOutput[ptr] = dataInputLow[ptr] - dataOutputEma[ptr]
        ptr++
    }
},[{
    name: "period",
    value: 14,
    required: true,
    type: PARAMETER_TYPE.INTEGER,
    range: [1, 100]
}],
[{
    name: DATA_NAME.CLOSE,
    index: 0
},{
    name: DATA_NAME.LOW,
    index: 1
}],
[{
    name: "bears",
    visible: true,
    renderType: RENDER_TYPE.HISTOGRAM,
    color: "steelblue"
},{
    name: "ema",
    visible: false
}],
WHERE_TO_RENDER.SEPARATE_WINDOW)