Forums › ProRealTime forum Italiano › Supporto ProBuilder › STD Filtered indicator › Reply To: STD Filtered indicator
05/28/2025 at 4:03 PM
#247707
Ciao! 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
// ----------------------------------------// //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 = close atr = AverageTrueRange[ATRPeriod](close) //----------------------------------------// // ---------- FILTRO PREVIO SOBRE FUENTE //----------------------------------------// IF (FilterMode = 1 OR FilterMode = 3) AND FilterStrength > 0 AND BarIndex > FilterPeriod THEN iprice = src devSrc = STD[FilterPeriod](src) filtdevSrc = FilterStrength * devSrc IF ABS(iprice - iprice[1]) < filtdevSrc THEN iprice = iprice[1] ELSE iprice = iprice ENDIF ELSE iprice = src ENDIF //----------------------------------------// // ---------- FILTRO GAUSSIANO N-POLO //----------------------------------------// Series = iprice Period = MAX(Period, 2) IF BarIndex = 0 THEN w = 2 * 3.141592654 / Period w = 180 * w / 3.141592654 IF NPole = 2 THEN b = (1 - COS(w)) / (1.41421 - 1) ELSIF NPole = 3 THEN b = (1 - COS(w)) / (1.25992 - 1) ELSIF NPole = 4 THEN b = (1 - COS(w)) / (1.18920 - 1) ENDIF aa = -b + SQRT(b * b + 2 * b) a1 = 1 - aa a12 = a1 * a1 a13 = a12 * a1 a14 = a12 * a12 a2 = aa * aa a3 = a2 * aa a4 = a2 * a2 y1 = Series y2 = y1 y3 = y2 y4 = y3 ENDIF IF NPole = 2 THEN y = a2 * Series + 2 * a1 * y1 - a12 * y2 y2 = y1 y1 = y ELSIF NPole = 3 THEN y = a3 * Series + 3 * a1 * y1 - 3 * a12 * y2 + a13 * y3 y3 = y2 y2 = y1 y1 = y ELSIF NPole = 4 THEN y = a4 * Series + 4 * a1 * y1 - 6 * a12 * y2 + 4 * a13 * y3 - a14 * y4 y4 = y3 y3 = y2 y2 = y1 y1 = y ENDIF AFR = y //----------------------------------------// // ---------- FILTRO POSTERIOR //----------------------------------------// IF (FilterMode = 2 OR FilterMode = 3) AND FilterStrength > 0 AND BarIndex > FilterPeriod THEN iiprice = AFR dev = STD[FilterPeriod](AFR) filtdev = FilterStrength * dev IF ABS(iiprice - iiprice[1]) < filtdev THEN iiprice = iiprice[1] ELSE iiprice = iiprice ENDIF ELSE iiprice = AFR ENDIF //----------------------------------------// // ---------- LÓGICA DE SEÑALES //----------------------------------------// sig = iiprice[1] state = 0 IF iiprice > sig THEN state = 1 ELSIF iiprice < sig THEN state = -1 ENDIF pregoLong = 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 THEN contsw = 0 ENDIF IF pregoLong THEN contsw = 1 ELSIF pregoShort THEN contsw = -1 ELSE contsw = contsw[1] ENDIF goLong = pregoLong AND contsw[1] = -1 goShort = pregoShort AND contsw[1] = 1 //----------------------------------------// // ---------- COLORES DINÁMICOS //----------------------------------------// IF state = 1 THEN red = 50 green = 200 blue = 50 ELSIF state = -1 THEN red = 255 green = 75 blue = 100 ENDIF //----------------------------------------// // ---------- REPRESENTACIÓN VISUAL //----------------------------------------// IF goLong THEN drawarrowup(barindex, low - 0.15 * atr) coloured("blue") ENDIF IF goShort THEN drawarrowdown(barindex, high + 0.15 * atr) coloured("fuchsia") ENDIF //----------------------------------------// return iiprice coloured(red, green, blue) style(line, 3) |