Hi, I am looking for some help converting following Tradingview code for Thinkorswim. Here is the original link:
https://www.tradingview.com/script/rCfo5HHf-Reverse-Stochastic-Momentum-Index-On-Chart/
I have modified the code to only show the Reverse Stochastic Momentum Index midline. I can't figure out how to code "f_reverse_SMI" function. Thanks for any help!!
//
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// @version = 4
// @author = The_Caretaker
// © The_Caretaker
//
// Much respect to Alex Orekhov (everget) for sharing the Stochastic Momentum Index script which I based this indicator on.
// Greatly inspired by the original paper from William Blau, the inventor of the Stochastic Momentum Index
// and the prior works of Giorgos Siligardos, Dimitris Tsokakis and Johny Dough in reverse engineering momentum oscillators.
//
// Feel free to reuse or develop this script further, please drop me a note below if you find it useful.
//
study ( "Reverse Stochastic Momentum Index On Chart", "RSMI OC", true )
indicator('Reset Every (Price)', overlay=true, max_bars_back=1000)
// Inputs and global variable declarations
i_srcPrice = input(close, 'SMI Price Source')
i_SMI_len = input.int(10, 'SMI Length', minval=1)
i_smth1 = input.int(3, 'Smooth Length 1', minval=1)
i_smth2 = input.int(3, 'Smooth Length 2', minval=1)
i_sigLen = input.int(10, 'Signal Length', minval=1)
a(x) =>
2 / (x + 1)
f_reverse_SMI(P, U, W, X, Y, Z) =>
V = 0.5
H = ta.highest(W)
L = ta.lowest(W)
D = ta.ema(P - V * (H + L), X)[1]
E = ta.ema(a(X) * (P - V * (H + L)) + D - D * a(X), Y)[1]
F = ta.ema(H - L, X)[1]
G = ta.ema(a(X) * (H - L) + F * (1 - a(X)), Y)[1]
J = 100 * (a(Y) * (a(X) * (P - V * (H + L)) + D - D * a(X)) + E * (1 - a(Y))) / (V * (a(Y) * (a(X) * (H - L) + F * (1 - a(X))) + G * (1 - a(Y))))[1]
K = ta.ema(100 * (a(Y) * (a(X) * (P - V * (H + L)) + D - D * a(X)) + E * (1 - a(Y))) / (V * (a(Y) * (a(X) * (H - L) + F * (1 - a(X))) + G * (1 - a(Y)))), Z)[1]
rawReturn = (V * U * (a(Y) * a(X) * H - a(Y) * a(X) * L - a(Y) * F * a(X) + a(Y) * F - G * a(Y) + G) + 100 * (a(Y) * a(X) * V * H + a(Y) * a(X) * V * L - a(Y) * D + a(Y) * D * a(X) + E * a(Y) - E)) / (100 * a(Y) * a(X))
return_1 = rawReturn > 0 ? rawReturn : 0
return_1
SMINumerator = ta.ema(ta.ema(i_srcPrice - 0.5 * (ta.highest(i_SMI_len) + ta.lowest(i_SMI_len)), i_smth1), i_smth2)
SMIDenominator = 0.5 * ta.ema(ta.ema(ta.highest(i_SMI_len) - ta.lowest(i_SMI_len), i_smth1), i_smth2)
SMI = 100 * SMINumerator / SMIDenominator
SMI_eq = f_reverse_SMI(i_srcPrice, SMI[1], i_SMI_len, i_smth1, i_smth2, i_sigLen)
p_SMI_eqPlot = plot(SMI_eq, 'SMI EQ Price', color.rgb(3, 49, 87), 2, plot.style_linebr, transp=0)[/CODE]