[DMcL] SMI Momentum Index

stable
By dmaclennan in Momentum Published November 2023 👁 1,181 views 💬 0 comments

Description

from Trading View https://www.tradingview.com/support/solutions/43000707882-stochastic-momentum-index-smi/
HaasScript
-- [DMcL]
-- https://www.tradingview.com/support/solutions/43000707882-stochastic-momentum-index-smi/

DefineCommand('Stochastic_Momentum_Index', 'SMI out')

local c = ClosePrices()
local h = HighPrices()
local l = LowPrices()

local lengthK = DefineParameter(NumberType, 'LengthK', 'LengthK', true, 10)
local lengthD = DefineParameter(NumberType, 'LengthD', 'LengthD', true, 3)
local lengthEMA = DefineParameter(NumberType, 'LengthEMA', 'LengthEMA', true, 4)

local function emaEma(source, length)
    return EMA(EMA(source, length), length)
end

local highestHigh = GetHighs(h, lengthK)
local lowestLow = GetLows(l, lengthK)

local highestLowestRange = highestHigh - lowestLow
local relativeRange = c - (highestHigh + lowestLow) / 2
local smi = 200 * (emaEma(relativeRange, lengthD) / emaEma(highestLowestRange, lengthD))
local smiEma = EMA(smi, lengthEMA)




local smiplot = Plot(1, 'smi', smi)
local emaplot = Plot(1, 'smiEma', smiEma, Orange)


DefineOutput(ListDynamicType, {smi = smi, smiEma = smiEma}, "SMI values array", "Plot")
DefineOutputIndex(1, ListNumberType, "smi", "smi values")
DefineOutputIndex(2, ListNumberType, "smiEma", "smiEma values")

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!