hi mrtools
is it possible to convert this trading view indicator to mt4 Indicator
I am attaching the code here
//@version=6
indicator('ATR Based Zigzag w EMA', overlay = true)
// === Inputs ===
ATRLength = input(14, title = 'ATR Length')
ATRMult = input(5.0, title = 'ATR Multiplier')
lineSmoothLength = input(50, title = 'Line Smoothness (EMA Length)')
upTrendColor = input(color.rgb(0, 255, 132), title = 'Uptrend Line Color')
downTrendColor = input(color.rgb(255, 0, 0), title = 'Downtrend Line Color')
// === ATR Calculation ===
atr_val = ta.atr(ATRLength)
// === State Variables ===
var float LL = na
var float HH = na
var int trend = 1
// === Initialization ===
LL := na(LL[1]) ? low : LL[1]
HH := na(HH[1]) ? high : HH[1]
trend := na(trend[1]) ? 1 : trend[1]
// === Core Logic ===
if trend > 0 // Uptrend: looking for new swing low
if high >= HH
HH := high
HH
else
if low < HH - atr_val * ATRMult
trend := -1
LL := low
LL
else // Downtrend: looking for new swing high
if low <= LL
LL := low
LL
else
if high > LL + atr_val * ATRMult
trend := 1
HH := high
HH
// === Median Price (or pick a price base you prefer) ===
medianPrice = (high + low) / 2
// === Smoothed Line ===
smoothLine = ta.ema(medianPrice, lineSmoothLength)
// === Plotting the Clean Trend Line ===
plot(smoothLine, color = trend == 1 ? upTrendColor : downTrendColor, linewidth = 3, title = 'Trend Line')
// === (Optional) Bar Coloring Too ===
barcolor(trend == 1 ? upTrendColor : downTrendColor)
Re: Already Converted TradingView Indicators to MT4 Indicators
582Maybe I can help. Is this what you needed?ummadirajani wrote: Thu May 01, 2025 5:28 pm hi mrtools
is it possible to convert this trading view indicator to mt4 Indicator
Rgds
DC
Re: Already Converted TradingView Indicators to MT4 Indicators
583HI
Thanks for your response,but I am not seeing any color change when trend changes?
Re: Already Converted TradingView Indicators to MT4 Indicators
584https://www.mql5.com/en/charts/20940754 ... aveen-ranaummadirajani wrote: Thu May 01, 2025 6:05 pm HI
Thanks for your response,but I am not seeing any color change when trend changes?
Re: Already Converted TradingView Indicators to MT4 Indicators
585Ooops, I forgot to put the second buffer in... sorry!
Rgds
DC
Re: Already Converted TradingView Indicators to MT4 Indicators
586yes,It is working now ,thank you very muchdidichung wrote: Thu May 01, 2025 6:20 pm Ooops, I forgot to put the second buffer in... sorry!
Rgds
DC