Moving Average Trend Sniper
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Moving Average Trend Sniper
- This topic has 2 replies, 2 voices, and was last updated 2 weeks ago by
Stenozar.
-
-
05/18/2025 at 5:21 PM #247279
Buon pomeriggio, chiedo gentilmente se possibile la traduzione di questo indicatore, grazie:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime//@version=5
indicator(“Moving Average Trend Sniper [ChartPrime]”, “MATS [ChartPrime]”, true)// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x – 1))// Custom sinh function
sinh(float x) =>
(math.exp(x) – math.exp(-x)) / 2// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))// Custom inverse tangent function
atan(float x) =>
math.pi / 2 – math.atan(1 / x)// Chebyshev Type I Moving Average
chebyshevI(float src, int len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.a := cosh(1 / len * acosh(1 / (1 – ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a – b) / (a + b)
chebyshev := (1 – g) * src + g * nz(chebyshev[1])
chebyshevbool_to_float(bool source) =>
source ? 1 : 0ema(source)=>
var float ema = 0.0
var int count = 0
count := nz(count[1]) + 1
ema := (1.0 – 2.0 / (count + 1.0)) * nz(ema[1]) + 2.0 / (count + 1.0) * source
emaatan2(y, x) =>
var float angle = 0.0
if x > 0
angle := math.atan(y / x)
else
if x < 0 and y >= 0
angle := math.atan(y / x) + math.pi
else
if x < 0 and y < 0
angle := math.atan(y / x) – math.pi
else
if x == 0 and y > 0
angle := math.pi / 2
else
if x == 0 and y < 0
angle := -math.pi / 2
angledegrees(float source) =>
source * 180 / math.pitra()=>
atr = ema(ta.tr)
slope = (close – close[10]) / (atr * 10)
angle_rad = atan2(slope, 1)
degrees = degrees(angle_rad)
source = ta.sma((degrees > 0 ? high : low), 2)mats(source, length) =>
smooth = 0.
higher_high = math.max(math.sign(ta.change(ta.highest(length))), 0)
lower_low = math.max(math.sign(ta.change(ta.lowest(length)) * -1), 0)
time_constant = math.pow(ta.sma(bool_to_float(higher_high or lower_low), length), 2)
smooth := nz(smooth[1] + time_constant * (source – smooth[1]), source)wilders_period = length * 4 – 1
atr = math.abs(nz(smooth[1]) – smooth)
ma_atr = ta.ema(atr, wilders_period)
delta_fast_atr = ta.ema(ma_atr, wilders_period) * length * 0.4result = 0.0
if smooth > nz(result[1])
if smooth – delta_fast_atr < result[1]
result := result[1]
else
result := smooth – delta_fast_atr
else
if smooth + delta_fast_atr > result[1]
result := result[1]
else
result := smooth + delta_fast_atr// Return
resultlength = input.int(30, “Length”, 2)
up_color = input.color(color.blue, “”, inline = “color”)
down_color = input.color(color.orange, “”, inline = “color”)
enable_glow = input.bool(true, “Enable Glow”, inline = “color”)mats = mats(tra(), length)
atr = ta.atr(length)
colour = ta.sma(close, 2) > mats ? up_color : down_color
atr_10 = ema(ta.tr) / 2
alpha = color.new(color.black, 100)
max = mats + atr_10
min = mats – atr_10center = plot(mats, “Moving Average Trend Sniper”, colour, editable = true)
plot(mats, “Moving Average Trend Sniper”, color.new(colour, 70), 2, editable = true)
plot(mats, “Moving Average Trend Sniper”, color.new(colour, 80), 3, editable = true)
plot(mats, “Moving Average Trend Sniper”, color.new(colour, 90), 4, editable = true)top = plot(enable_glow ? max : na, “Moving Average Trend Sniper”, alpha)
bottom = plot(enable_glow ? min : na, “Moving Average Trend Sniper”, alpha)fill(top, center, top_value = max, bottom_value = mats, bottom_color = color.new(colour, 75), top_color = alpha, editable = true)
fill(center, bottom, top_value = mats, bottom_value = min, bottom_color = alpha, top_color = color.new(colour, 75), editable = true)05/19/2025 at 3:32 PM #247328Ecco qui:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899//-----------------------------------------////PRC_Moving Avg Trend Sniper//version = 0//19.05.2025//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-----------------------------------------//// === PARAMETERS ===//-----------------------------------------//length = 30 // main smoothing lengthwildersPeriod = length * 4 - 1atrPeriod = lengthatrMult = 0.5 // multiplier for upper/lower ATR band//-----------------------------------------//// === CUSTOM EMA FUNCTION ===//-----------------------------------------//ONCE atrema = 0ONCE count = 0IF barindex <= 1 THENatrema = 0count = 0ELSEcount = count + 1atrema = (1 - 2 / (count + 1)) * atrema + 2 / (count + 1) * trENDIF//-----------------------------------------//// === TRA() FUNCTION ===//-----------------------------------------//atrLocal = atremaslope = (close - close[10]) / (atrLocal * 10)angle = ATAN(slope)IF angle > 0 THENsource = average[2](high)ELSEsource = average[2](low)ENDIF//-----------------------------------------//// === CHEBYSHEV-LIKE ADAPTIVE SMOOTHING ===//-----------------------------------------//// Applies smoothing only when barindex is sufficientIF barindex <= length THENsmooth = closeELSEhighChange = (HIGHEST[length](high) - HIGHEST[length+1](high)) <> 0lowChange = (LOWEST[length+1](low) - LOWEST[length](low)) <> 0boolImpulse = highChange OR lowChangetimeConstant = POW(AVERAGE[length](boolImpulse), 2)smooth = smooth + timeConstant * (source - smooth)ENDIF//-----------------------------------------//// === MODIFIED ATR CALCULATION ===//-----------------------------------------//atr = ABS(smooth[1] - smooth)maAtr = average[wildersPeriod,1](atr)deltaATR = average[wildersPeriod](maAtr) * length * 0.4//-----------------------------------------//// === MATS CALCULATION ===//-----------------------------------------//// Adaptive moving average trend filter with direction-sensitive filteringONCE mats = smoothIF smooth > mats[1] THENIF smooth - deltaATR < mats[1] THENmats = mats[1]ELSEmats = smooth - deltaATRENDIFELSEIF smooth + deltaATR > mats[1] THENmats = mats[1]ELSEmats = smooth + deltaATRENDIFENDIF//-----------------------------------------//// === ATR-BASED ENVELOPE BANDS ===//-----------------------------------------//atr10 = atrema / 2maxBand = mats + atr10 * atrMultminBand = mats - atr10 * atrMult//-----------------------------------------//// === DYNAMIC COLORING BASED ON TREND DIRECTION ===//-----------------------------------------//IF AVERAGE[2](close) > mats THENr = 0g = 0b = 255ELSEr = 255g = 175b = 100ENDIF// Shaded background between bandscolorbetween(maxBand, minBand, r, g, b, 30)//-----------------------------------------//RETURN mats COLOURED(r, g, b) STYLE(line, 3)05/19/2025 at 5:19 PM #247340 -
AuthorPosts
Find exclusive trading pro-tools on