Re: Already Converted TradingView Indicators to MT4 Indicators

434
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)
These users thanked the author RodrigoRT7 for the post (total 3):
mrtools, macd & rsi, moey_dw

Re: Already Converted TradingView Indicators to MT4 Indicators

435
RodrigoRT7 wrote: Tue Jun 11, 2024 7:42 am 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)
Posted a version here
These users thanked the author mrtools for the post:
RodrigoRT7


TMA Centered Bands for Tradingview

437
Hi, any kind people can help combine two of this same TMA centered bands together as one indicator pinescript? Your kind help much appreciated. The code is converted to pinescript by author Brylator and the original MT4 code is by mladen. Huge thanks to both for this wonderful indicator.

https://in.tradingview.com/script/dc1Mn ... th-alerts/

Code: Select all

//@version=5
//author: mladen
//rebound arrows and TMA angle caution: Ale
//rewritten from MQL5 to Pine: Brylator
indicator("TMA Centered Bands Indicator", "TMA v0.42", overlay = true, max_lines_count = 500, max_labels_count = 500)

//INPUTS
var GRP1 = "Parameters"
HalfLength = input.int(12, "Centered TMA half period", group = GRP1)
string PriceType = input.string("Weighted", "Price to use", options = ["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average"], group = GRP1)
AtrPeriod = input.int(100, "Average true range period", group = GRP1)
AtrMultiplier = input.float(2, "Average true range multiplier", group = GRP1)
TMAangle = input.int(4, "Centered TMA angle caution", group = GRP1)

//VARIABLES
float tmac = na
float tmau = na
float tmad = na

var float pastTmac = na //from the previous candle
var float pastTmau = na
var float pastTmad = na

float tmau_temp = na //before looping
float tmac_temp = na
float tmad_temp = na

float point = syminfo.pointvalue //NEEDS MORE TESTS

bool last = false //checks if a loop is needed

var string alertSignal = "EMPTY" //needed for alarms to avoid repetition

//COLORS
var GRP2 = "Colors"
var color colorBuffer = na
color colorDOWN = input.color(color.new(color.red, 0), "Bear", inline = "5", group = GRP2)
color colorUP = input.color(color.new(color.green, 0), "Bull", inline = "5", group = GRP2)
color colorBands = input.color(color.new(#b2b5be, 0), "Bands", inline = "5", group = GRP2)
bool cautionInput = input.bool(true, "Caution label", inline = "6", group = GRP2)

//ALERTS
var GRP3 = "Alerts (Needs to create alert manually after every change)"
bool crossUpInput = input.bool(false, "Crossing up", inline = "7", group = GRP3)
bool crossDownInput = input.bool(false, "Crossing down", inline = "7", group = GRP3)
bool comingBackInput = input.bool(false, "Coming back", inline = "7", group = GRP3)
bool onArrowDownInput = input.bool(false, "On arrow down", inline = "8", group = GRP3)
bool onArrowUpInput = input.bool(false, "On arrow up", inline = "8", group = GRP3)

//CLEAR LINES
a_allLines = line.all
if array.size(a_allLines) > 0
    for p = 0 to array.size(a_allLines) - 1
        line.delete(array.get(a_allLines, p))
        
//GET PRICE        
Price(x) =>
    float price = switch PriceType
        "Close" => close[x]
        "Open" => open[x]
        "High" => high[x]
        "Low" => low[x]
        "Median" => (high[x] + low[x]) / 2
        "Typical" => (high[x] + low[x] + close[x]) / 3
        "Weighted" => (high[x] + low[x] + close[x] + close[x]) / 4
        "Average" => (high[x] + low[x] + close[x] + open[x])/ 4
    price

//MAIN
for i = HalfLength to 0

    //ATR
    atr = 0.0
    for j = 0 to  AtrPeriod - 1
        atr += math.max(high[i + j + 10], close[i + j + 11]) - math.min(low[i + j + 10], close[i + j + 11])
    atr /= AtrPeriod
    
    //BANDS
    sum = (HalfLength + 1) * Price(i)
    sumw = (HalfLength + 1)
    k = HalfLength
    for j = 1 to HalfLength
        sum += k * Price(i + j)
        sumw += k
        if (j <= i)
            sum  += k * Price(i - j)
            sumw += k
        k -= 1
    tmac := sum/sumw
    tmau := tmac+AtrMultiplier*atr
    tmad := tmac-AtrMultiplier*atr
    
    //ALERTS
    if i == 0 //Only on a real candle 
        if (high > tmau and alertSignal != "UP") //crossing up band
            if crossUpInput == true //checks if activated
                alert("Crossing up Band") //calling alert
            alertSignal := "UP" //to avoid repeating 
        else if (low < tmad and alertSignal != "DOWN") //crossing down band
            if crossDownInput == true
                alert("Crossing down Band")
            alertSignal := "DOWN"
        else if (alertSignal == "DOWN" and high >= tmad and alertSignal != "EMPTY") //back from the down band
            if comingBackInput == true
                alert("Coming back")
            alertSignal := "EMPTY"
        else if (alertSignal == "UP" and low <= tmau and alertSignal != "EMPTY") //back from the up band
            if comingBackInput == true
                alert("Coming back")
            alertSignal := "EMPTY"
            
    //CHANGE TREND COLOR
    if pastTmac != 0.0
        if tmac > pastTmac
            colorBuffer := colorUP
        if tmac < pastTmac
            colorBuffer := colorDOWN
            
    //SIGNALS
    reboundD = 0.0
    reboundU = 0.0
    caution = 0.0
    if pastTmac != 0.0
        if (high[i + 1] > pastTmau and close[i + 1] > open[i + 1] and close[i] < open[i])
            reboundD := high[i] + AtrMultiplier * atr / 2
            if (tmac - pastTmac > TMAangle * point)
                caution := reboundD + 10 * point
        if (low[i + 1] < pastTmad and close[i + 1] < open[i + 1] and close[i] > open[i])
            reboundU := low[i] - AtrMultiplier * atr / 2
            if (pastTmac - tmac > TMAangle * point)
                caution := reboundU - 10 * point
    
    //LAST REAL
    if barstate.islast and i == HalfLength
        last := true
        tmau_temp := tmau
        tmac_temp := tmac
        tmad_temp := tmad
        
    //DRAW HANDICAPPED BANDS
    if barstate.islast and i < HalfLength
        line.new(bar_index - (i + 1), pastTmau, bar_index - (i), tmau, width = 2, style = line.style_dotted, color = colorBands)
        line.new(bar_index - (i + 1), pastTmac, bar_index - (i), tmac, width = 2, style = line.style_dotted, color = colorBuffer)
        line.new(bar_index - (i + 1), pastTmad, bar_index - (i), tmad, width = 2, style = line.style_dotted, color = colorBands)
        
    //DRAW SIGNALS
    if reboundD != 0
        //label.new(bar_index - (i), reboundD, color = colorDOWN, style = label.style_triangledown, size = size.tiny, textcolor = na)
        label.new(bar_index - (i), reboundD, '▼', color = na, textcolor = colorDOWN, textalign=  text.align_center)
        if i == 0 and onArrowDownInput == true //alert
            alert("Down arrow") 
        if caution != 0 and cautionInput == true
            label.new(bar_index - (i), reboundD, color = colorUP, style = label.style_xcross, size = size.tiny, textcolor = na)
    if reboundU != 0
        //label.new(bar_index - (i), reboundU, color = colorUP, style = label.style_triangleup, size = size.tiny, textcolor = na)
        label.new(bar_index - (i), reboundU, '▲', color = na, textcolor = colorUP, textalign = text.align_center)
        if i == 0 and onArrowUpInput == true //alert
            alert("UP arrow") 
        if caution != 0 and cautionInput == true
            label.new(bar_index - (i), reboundU, color = colorDOWN, style = label.style_xcross, size = size.tiny, textcolor = na)
            
    //SAVE HISTORY
    pastTmac := tmac
    pastTmau := tmau
    pastTmad := tmad
    
    //LOOP IS ONLY FOR HANDICAPPED
    if barstate.islast != true
        break
        
//DRAW REAL BANDS
plot(last ? tmau_temp : tmau, title = "TMA Up", color = colorBands, linewidth=1, style = plot.style_line, offset = -HalfLength)
plot(last ? tmac_temp : tmac, title = "TMA Mid", color = colorBuffer, linewidth=1, style = plot.style_line, offset = -HalfLength)
plot(last ? tmad_temp : tmad, title = "TMA Down", color = colorBands, linewidth=1, style = plot.style_line, offset = -HalfLength)

Re: Already Converted TradingView Indicators to MT4 Indicators

438
kenaz80 wrote: Wed Jun 19, 2024 5:22 pm Hi, any kind people can help combine two of this same TMA centered bands together as one indicator pinescript? Your kind help much appreciated. The code is converted to pinescript by author Brylator and the original MT4 code is by mladen. Huge thanks to both for this wonderful indicator.
Moved your post to the right thread and please make an effort to upload images directly to your posts in future.

You'll find that TMA in our topic over here: TMA indicators for MT4. If you scroll down on the first page you'll actually find that exact indicator in there. But I won't spoil the fun for you, take your pick.
Myfxbook live trading results 📊

List of our most powerful reversal indicators + Guide to the "All Averages" Filters (ADXvma, Laguerre etc.)
Fibonacci numbers for indicator settings + How to draw Fibonacci Extensions + How to draw Support & Resistance

Re: Already Converted TradingView Indicators to MT4 Indicators

440
mrtools wrote: Tue Dec 06, 2022 7:32 pm HIGH and LOW Optimized Trend Tracker HOTT LOTT

The HOTT LOTT is based off Anıl Özekşi's OTT - Optimized Trend Tracker.

This particular version has two lines of Optimized Trend Tracker which uses the HIGHEST price values (HOTT) and LOWEST price values (LOTT). The difference with this version is that the OTT uses a CLOSE price.

Guys I don't think this part is right for the upper channel

Code: Select all

if (MaType==ma_vidya)  valH[i]        = iVidya(MathMax(iHigh(NULL,0,iHighest(NULL,0,(int)PriceH,HLPeriod,i)),iHigh(NULL,0,iHighest(NULL,0,(int)PriceL,HLPeriod,i))),MaLength,VidyaSmoothPeriod,i,0);
      else  valH[i]        = iCustomMa(MaType,MathMax(iHigh(NULL,0,iHighest(NULL,0,(int)PriceH,HLPeriod,i)),iHigh(NULL,0,iHighest(NULL,0,(int)PriceL,HLPeriod,i))),MaLength,i,Bars,0);
and this for the lower channel

Code: Select all

if (MaType==ma_vidya)  valL[i] = iVidya(MathMin(iLow(NULL,0,iLowest(NULL,0,(int)PriceH,HLPeriod,i)),iLow(NULL,0,iLowest(NULL,0,(int)PriceL,HLPeriod,i))),MaLength,VidyaSmoothPeriod,i,1);
	  else valL[i] = iCustomMa(MaType,MathMin(iLow(NULL,0,iLowest(NULL,0,(int)PriceH,HLPeriod,i)),iLow(NULL,0,iLowest(NULL,0,(int)PriceL,HLPeriod,i))),MaLength,i,Bars,1);

I did something like this

Code: Select all

double hi   = high[ArrayMinimum(high,HLPeriod,i)];
      double lo   =  low[ArrayMinimum( low,HLPeriod,i)];
         wrk[r].valH = iCustomMa(MaType,hi,MaLength,i,rates_total,0);
         wrk[r].valL = iCustomMa(MaType,lo,MaLength,i,rates_total,1);
unless I am missing something please let me now, anyway, did a version too.
I think for

Code: Select all

MathMax(iHigh(NULL,0,iHighest(NULL,0,(int)PriceH,HLPeriod,i)),iHigh(NULL,0,iHighest(NULL,0,(int)PriceL,HLPeriod,i)))
There is no need to do a MathMax as the result of iHigh for PriceH should always be higher (or equal) to that for PriceL