STD Filtered indicator
Forums › ProRealTime forum Italiano › Supporto ProBuilder › STD Filtered indicator
- This topic has 1 reply, 2 voices, and was last updated 3 days ago by
Iván.
-
-
05/04/2025 at 5:54 PM #246772
Buon pomeriggio, è possibile tradurre questo indicatore che mi pare interessante:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx//@version=5
indicator(“STD-Filtered, N-Pole Gaussian Filter [Loxx]”,
shorttitle=”STDFNPGF [Loxx]”,
overlay = true)import loxx/loxxexpandedsourcetypes/4
greencolor = #2DD204
redcolor = #D2042D//factorial calc
fact(int n)=>
float a = 1
for i = 1 to n
a *= i
a//alpha calc
_alpha(int period, int poles)=>
w = 2.0 * math.pi / period
float b = (1.0 – math.cos(w)) / (math.pow(1.414, 2.0 / poles) – 1.0)
float a = – b + math.sqrt(b * b + 2.0 * b)
a//n-pole calc
_makeCoeffs(simple int period, simple int order)=>
coeffs = matrix.new<float>(order + 1, 3, 0.)
float a = _alpha(period, order)
for r = 0 to order
out = nz(fact(order) / (fact(order – r) * fact(r)), 1)
matrix.set(coeffs, r, 0, out)
matrix.set(coeffs, r, 1, math.pow(a, r))
matrix.set(coeffs, r, 2, math.pow(1.0 – a, r))
coeffs//n-pole calc
_npolegf(float src, simple int period, simple int order)=>
var coeffs = _makeCoeffs(period, order)
float filt = src * matrix.get(coeffs, order, 1)
int sign = 1
for r = 1 to order
filt += sign * matrix.get(coeffs, r, 0) * matrix.get(coeffs, r, 2) * nz(filt[r])
sign *= -1
filt//std filter
_filt(float src, int len, float filter)=>
float price = src
float filtdev = filter * ta.stdev(src, len)
price := math.abs(price – nz(price[1])) < filtdev ? nz(price[1]) : price
pricesmthtype = input.string(“Kaufman”, “Heiken-Ashi Better Smoothing”, options = [“AMA”, “T3”, “Kaufman”], group= “Source Settings”)
srcoption = input.string(“Close”, “Source”, group= “Source Settings”,
options =
[“Close”, “Open”, “High”, “Low”, “Median”, “Typical”, “Weighted”, “Average”, “Average Median Body”, “Trend Biased”, “Trend Biased (Extreme)”,
“HA Close”, “HA Open”, “HA High”, “HA Low”, “HA Median”, “HA Typical”, “HA Weighted”, “HA Average”, “HA Average Median Body”, “HA Trend Biased”, “HA Trend Biased (Extreme)”,
“HAB Close”, “HAB Open”, “HAB High”, “HAB Low”, “HAB Median”, “HAB Typical”, “HAB Weighted”, “HAB Average”, “HAB Average Median Body”, “HAB Trend Biased”, “HAB Trend Biased (Extreme)”])period = input.int(25,’Period’, group = “Basic Settings”)
order = input.int(5,’Order’, group = “Basic Settings”, minval = 1)filterop = input.string(“Gaussian Filter”, “Filter Options”, options = [“Price”, “Gaussian Filter”, “Both”, “None”], group= “Filter Settings”)
filter = input.float(1, “Filter Devaitions”, minval = 0, group= “Filter Settings”)
filterperiod = input.int(10, “Filter Period”, minval = 0, group= “Filter Settings”)colorbars = input.bool(true, “Color bars?”, group = “UI Options”)
showSigs = input.bool(true, “Show signals?”, group= “UI Options”)kfl=input.float(0.666, title=”* Kaufman’s Adaptive MA (KAMA) Only – Fast End”, group = “Moving Average Inputs”)
ksl=input.float(0.0645, title=”* Kaufman’s Adaptive MA (KAMA) Only – Slow End”, group = “Moving Average Inputs”)
amafl = input.int(2, title=”* Adaptive Moving Average (AMA) Only – Fast”, group = “Moving Average Inputs”)
amasl = input.int(30, title=”* Adaptive Moving Average (AMA) Only – Slow”, group = “Moving Average Inputs”)[haclose, haopen, hahigh, halow, hamedian, hatypical, haweighted, haaverage] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [close, open, high, low, hl2, hlc3, hlcc4, ohlc4])
float src = switch srcoption
“Close” => loxxexpandedsourcetypes.rclose()
“Open” => loxxexpandedsourcetypes.ropen()
“High” => loxxexpandedsourcetypes.rhigh()
“Low” => loxxexpandedsourcetypes.rlow()
“Median” => loxxexpandedsourcetypes.rmedian()
“Typical” => loxxexpandedsourcetypes.rtypical()
“Weighted” => loxxexpandedsourcetypes.rweighted()
“Average” => loxxexpandedsourcetypes.raverage()
“Average Median Body” => loxxexpandedsourcetypes.ravemedbody()
“Trend Biased” => loxxexpandedsourcetypes.rtrendb()
“Trend Biased (Extreme)” => loxxexpandedsourcetypes.rtrendbext()
“HA Close” => loxxexpandedsourcetypes.haclose(haclose)
“HA Open” => loxxexpandedsourcetypes.haopen(haopen)
“HA High” => loxxexpandedsourcetypes.hahigh(hahigh)
“HA Low” => loxxexpandedsourcetypes.halow(halow)
“HA Median” => loxxexpandedsourcetypes.hamedian(hamedian)
“HA Typical” => loxxexpandedsourcetypes.hatypical(hatypical)
“HA Weighted” => loxxexpandedsourcetypes.haweighted(haweighted)
“HA Average” => loxxexpandedsourcetypes.haaverage(haaverage)
“HA Average Median Body” => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)
“HA Trend Biased” => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)
“HA Trend Biased (Extreme)” => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)
“HAB Close” => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)
“HAB Open” => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)
“HAB High” => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)
“HAB Low” => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)
“HAB Median” => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)
“HAB Typical” => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)
“HAB Weighted” => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)
“HAB Average” => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)
“HAB Average Median Body” => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)
“HAB Trend Biased” => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)
“HAB Trend Biased (Extreme)” => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)
=> haclosesrc := filterop == “Both” or filterop == “Price” and filter > 0 ? _filt(src, filterperiod, filter) : src
out = _npolegf(src, period, order)
out := filterop == “Both” or filterop == “Gaussian Filter” and filter > 0 ? _filt(out, filterperiod, filter) : out
sig = nz(out[1])
state = 0
if (out > sig)
state := 1
if (out < sig)
state := -1pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]))
pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]))contsw = 0
contsw := nz(contsw[1])
contsw := pregoLong ? 1 : pregoShort ? -1 : nz(contsw[1])goLong = pregoLong and nz(contsw[1]) == -1
goShort = pregoShort and nz(contsw[1]) == 1var color colorout = na
colorout := state == -1 ? redcolor : state == 1 ? greencolor : nz(colorout[1])plot(out, “N-Pole GF”, color = colorout, linewidth = 3)
barcolor(colorbars ? colorout : na)plotshape(showSigs and goLong, title = “Long”, color = color.yellow, textcolor = color.yellow, text = “L”, style = shape.triangleup, location = location.belowbar, size = size.tiny)
plotshape(showSigs and goShort, title = “Short”, color = color.fuchsia, textcolor = color.fuchsia, text = “S”, style = shape.triangledown, location = location.abovebar, size = size.tiny)alertcondition(goLong, title = “Long”, message = “STD-Filtered, N-Pole Gaussian Filter [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}”)
alertcondition(goShort, title = “Short”, message = “STD-Filtered, N-Pole Gaussian Filter [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}”)05/28/2025 at 4:03 PM #247707Ciao! Ti darò la mia conversione fino a N=4. Devo ancora creare un pezzo di codice che emuli la funzione TW che consente N poli gaussiani.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158// ----------------------------------------////PRC_NPole Gaussian Filter// Indicador: Filtro Gaussiano N-Polo + STD//version = 0//28.05.2025//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge// ----------------------------------------//// ---------- PARÁMETROS DE USUARIO//----------------------------------------//NPole = 4//input(4, "Nº de Polos (2 a 4)", 2, 4)Period = 25//input(25, "Periodo del filtro gaussiano", 2)FilterMode = 3//input(3, "Modo de filtrado: 1=Precio, 2=Filtro, 3=Ambos", 0, 3)FilterStrength = 1// input(1, "Multiplicador de desviación", 0)FilterPeriod = 10//input(10, "Periodo de desviación", 1)ATRPeriod = 14//input(14, "Periodo ATR para señal", 1)//----------------------------------------//// ---------- VARIABLES BÁSICAS//----------------------------------------//src = closeatr = AverageTrueRange[ATRPeriod](close)//----------------------------------------//// ---------- FILTRO PREVIO SOBRE FUENTE//----------------------------------------//IF (FilterMode = 1 OR FilterMode = 3) AND FilterStrength > 0 AND BarIndex > FilterPeriod THENiprice = srcdevSrc = STD[FilterPeriod](src)filtdevSrc = FilterStrength * devSrcIF ABS(iprice - iprice[1]) < filtdevSrc THENiprice = iprice[1]ELSEiprice = ipriceENDIFELSEiprice = srcENDIF//----------------------------------------//// ---------- FILTRO GAUSSIANO N-POLO//----------------------------------------//Series = ipricePeriod = MAX(Period, 2)IF BarIndex = 0 THENw = 2 * 3.141592654 / Periodw = 180 * w / 3.141592654IF NPole = 2 THENb = (1 - COS(w)) / (1.41421 - 1)ELSIF NPole = 3 THENb = (1 - COS(w)) / (1.25992 - 1)ELSIF NPole = 4 THENb = (1 - COS(w)) / (1.18920 - 1)ENDIFaa = -b + SQRT(b * b + 2 * b)a1 = 1 - aaa12 = a1 * a1a13 = a12 * a1a14 = a12 * a12a2 = aa * aaa3 = a2 * aaa4 = a2 * a2y1 = Seriesy2 = y1y3 = y2y4 = y3ENDIFIF NPole = 2 THENy = a2 * Series + 2 * a1 * y1 - a12 * y2y2 = y1y1 = yELSIF NPole = 3 THENy = a3 * Series + 3 * a1 * y1 - 3 * a12 * y2 + a13 * y3y3 = y2y2 = y1y1 = yELSIF NPole = 4 THENy = a4 * Series + 4 * a1 * y1 - 6 * a12 * y2 + 4 * a13 * y3 - a14 * y4y4 = y3y3 = y2y2 = y1y1 = yENDIFAFR = y//----------------------------------------//// ---------- FILTRO POSTERIOR//----------------------------------------//IF (FilterMode = 2 OR FilterMode = 3) AND FilterStrength > 0 AND BarIndex > FilterPeriod THENiiprice = AFRdev = STD[FilterPeriod](AFR)filtdev = FilterStrength * devIF ABS(iiprice - iiprice[1]) < filtdev THENiiprice = iiprice[1]ELSEiiprice = iipriceENDIFELSEiiprice = AFRENDIF//----------------------------------------//// ---------- LÓGICA DE SEÑALES//----------------------------------------//sig = iiprice[1]state = 0IF iiprice > sig THENstate = 1ELSIF iiprice < sig THENstate = -1ENDIFpregoLong = iiprice > sig AND (iiprice[1] < sig[1] OR iiprice[1] = sig[1])pregoShort = iiprice < sig AND (iiprice[1] > sig[1] OR iiprice[1] = sig[1])IF BarIndex = 0 THENcontsw = 0ENDIFIF pregoLong THENcontsw = 1ELSIF pregoShort THENcontsw = -1ELSEcontsw = contsw[1]ENDIFgoLong = pregoLong AND contsw[1] = -1goShort = pregoShort AND contsw[1] = 1//----------------------------------------//// ---------- COLORES DINÁMICOS//----------------------------------------//IF state = 1 THENred = 50green = 200blue = 50ELSIF state = -1 THENred = 255green = 75blue = 100ENDIF//----------------------------------------//// ---------- REPRESENTACIÓN VISUAL//----------------------------------------//IF goLong THENdrawarrowup(barindex, low - 0.15 * atr) coloured("blue")ENDIFIF goShort THENdrawarrowdown(barindex, high + 0.15 * atr) coloured("fuchsia")ENDIF//----------------------------------------//return iiprice coloured(red, green, blue) style(line, 3) -
AuthorPosts
Find exclusive trading pro-tools on