Momentum (SDK Trading)

Momentum and rate of change are simple technical analysis indicators showing the difference between a day(or a certain time period)'s closing price and the close N days(or some specific time periods) ago. It measures the latest closing bar to a previous closing bar N periods ago. By analyzing the rate of change, we can gauge the strength or so-called “Momentum” in a financial instrument or Forex currency pair.

Momentum (SDK Trading)

registerIndicator("momentum", "Momentum(v1.0)", function (context) {
    var dataInput = getDataInput(context, 0)
    var dataOutput = getDataOutput(context, "momentum")
    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
        }
    }

    while (ptr < dataInput.length) {
        dataOutput[ptr] = dataInput[ptr] * 100 / dataInput[ptr - period]
        ptr++
    }
},[{
    name: "period",
    value: 14,
    required: true,
    type: PARAMETER_TYPE.INTEGER,
    range: [1, 100]
}],
[{
    name: DATA_NAME.CLOSE,
    index: 0
}],
[{
    name: "momentum",
    visible: true,
    renderType: RENDER_TYPE.LINE,
    color: "steelblue"
}],
WHERE_TO_RENDER.SEPARATE_WINDOW)