Attachments forums

List of attachments posted on this forum.


All files on forums: 164161

Re: Already Converted TradingView Indicators to MT4 Indicators

RodrigoRT7, Tue Jun 11, 2024 7:41 am

mrtools wrote: Tue Jun 11, 2024 1:58 am Thanks, but unfortunately have no idea how to do it.
hello Mr Tools everything is fine?
For some time now, I've been wondering what it would be like to combine RSI + Z Score, as they are two indicators that I really like.

I discovered today that it already exists, could you convert this Tradingview code including your RSIs + averages + RMAs please? I imagine that other averages could greatly improve the smoothing.

Thank you very much, in advance :D

Code: Select all

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// Z-Score of RSI
// by SparkyFlary

study(title="Z-Score of RSI", overlay=false)

length = input(11, title="Length")
avgType = input("RMA", title="RSI and Standard deviation Average type", options=["RMA", "EMA", "SMA"])
src = input(close, title="Source for RSI")
n = input(2.0, title="Number of Standard deviations for OB/OS", minval=0)

movAvg_(avgType_, src_, length_) =>
    avg = 0.0
    if avgType_=="RMA"
        avg := rma(src_, length_)
    else if avgType_=="EMA"
        avg := ema(src_, length_)
    else
        avg := sma(src_, length_)
    avg

//standard deviation from Tradingview
isZero_(val_, eps_) => abs(val_) <= eps_

SUM_(fst_, snd_) =>
    EPS = 1e-10
    res = fst_ + snd_
    if isZero_(res, EPS)
        res := 0
    else
        if not isZero_(res, 1e-4)
            res := res
        else
            15

stdev_(avgType_, src_, length_) =>
    avg = movAvg_(avgType_, src_, length_)
    sumOfSquareDeviations = 0.0
    for i = 0 to length_ - 1
        sum = SUM_(src_[i], -avg)
        sumOfSquareDeviations := sumOfSquareDeviations + sum * sum
    stdev = sqrt(sumOfSquareDeviations / length_)

num = movAvg_(avgType, src - src[1], length)
denom = movAvg_(avgType, abs(src - src[1]), length)
rsi_ratio = num/denom // RS part of the RSI

avg = movAvg_(avgType, rsi_ratio, length)
dev = stdev_(avgType, rsi_ratio, length)
zscore = (rsi_ratio - avg) / dev

hline(n, "Upper band", color=#C0C0C0, linestyle=hline.style_solid, linewidth=2)
hline(-n, "Lower band", color=#C0C0C0, linestyle=hline.style_solid, linewidth=2)
hline(0, "Middle line", color=#C0C0C0, linestyle=hline.style_dashed, linewidth=1)
plot(zscore, title="Z-score", color=zscore>0?color.green:color.red)
bgcolor(zscore>n?color.red:zscore<-n?color.green:na)
All files in topic