La stratégie de triple chevauchement de l'élan stochastique est une stratégie de trading à court terme typique. Elle calcule trois indicateurs de l'indice de l'élan stochastique (SMI) avec des paramètres différents et génère des signaux de trading lorsque les trois montrent simultanément des conditions de surachat ou de survente.
L'indicateur de base de cette stratégie est l'indice de dynamique stochastique (SMI).
SMI = 100 * EMA(EMA(Close - Midpoint of High-Low Range, N1), N2) / 0.5 * EMA(EMA(High - Low, N1), N2)
Les valeurs supérieures à 0 indiquent que la clôture se situe dans la moitié supérieure de la fourchette quotidienne, tandis que les valeurs inférieures à 0 indiquent que la clôture se situe dans la moitié inférieure.
Comme pour l'oscillateur stochastique traditionnel, les niveaux de surachat (par exemple 40) / survente (par exemple -40) indiquent des signaux d'inversion potentiels.
La stratégie utilise trois indicateurs SMI avec différents ensembles de paramètres, notamment:
Les signaux de négociation sont générés lorsque les trois PME affichent simultanément des conditions de surachat ou de survente.
Réduction des risques:
La stratégie du moment stochastique triple chevauchement combine une génération de signal robuste sur plusieurs délais en superposant trois indicateurs SMI avec des paramètres uniques.
/*backtest start: 2023-12-26 00:00:00 end: 2024-01-25 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy("Stochastic Momentum multi strategy", "Stochastic Momentum Index multi strategy", overlay=false) q = input(10, title="%K Length") r = input(3, title="%K Smoothing Length") s = input(3, title="%K Double Smoothing Length") nsig = input(10, title="Signal Length") matype = input("ema", title="Signal MA Type") // possible: ema, sma, wma, trima, hma, dema, tema, zlema overbought = input(40, title="Overbought Level", type=float) oversold = input(-40, title="Oversold Level", type=float) trima(src, length) => sma(sma(src,length),length) hma(src, length) => wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length))) dema(src, length) => 2*ema(src,length) - ema(ema(src,length),length) tema(src, length) => (3*ema(src,length) - 3*ema(ema(src,length),length)) + ema(ema(ema(src,length),length),length) zlema(src, length) => ema(src,length) + (ema(src,length) - ema(ema(src,length),length)) smi = 100 * ema(ema(close-0.5*(highest(q)+lowest(q)),r),s) / (0.5 * ema(ema(highest(q)-lowest(q),r),s)) sig = matype=="ema" ? ema(smi,nsig) : matype=="sma" ? sma(smi,nsig) : matype=="wma" ? wma(smi,nsig) : matype=="trima" ? trima(smi,nsig) : matype=="hma" ? hma(smi,nsig) : matype=="dema" ? dema(smi,nsig) : matype=="tema" ? tema(smi,nsig) : matype=="zlema" ? zlema(smi,nsig) : ema(smi,nsig) p_smi = plot(smi, title="SMI", color=aqua) p_sig = plot(sig, title="Signal", color=red) // plotchar(crossover(smi, sig), title= "low", location=location.bottom, color=green, char="▲", size= size.tiny) // plotchar(crossunder(smi, sig), title= "high", location=location.top, color=red, char="▼", size= size.tiny) /////////////////////////////2 q2 = input(20, title="%K Length 2") r2 = input(3, title="%K Smoothing Length 2") s2 = input(3, title="%K Double Smoothing Length 2") nsig2 = input(10, title="Signal Length 2") matype2 = input("ema", title="Signal MA Type 2") // possible: ema, sma, wma, trima, hma, dema, tema, zlema overbought2 = input(40, title="Overbought Level 2", type=float) oversold2 = input(-40, title="Oversold Level 2", type=float) trima2(src2, length2) => sma(sma(src2,length2),length2) hma2(src2, length2) => wma(2*wma(src2, length2/2)-wma(src2, length2), round(sqrt(length2))) dema2(src2, length2) => 2*ema(src2,length2) - ema(ema(src2,length2),length2) tema2(src2, length2) => (3*ema(src2,length2) - 3*ema(ema(src2,length2),length2)) + ema(ema(ema(src2,length2),length2),length2) zlema2(src2, length2) => ema(src2,length2) + (ema(src2,length2) - ema(ema(src2,length2),length2)) smi2 = 100 * ema(ema(close-0.5*(highest(q2)+lowest(q2)),r2),s2) / (0.5 * ema(ema(highest(q2)-lowest(q2),r2),s2)) sig2 = matype2=="ema" ? ema(smi2,nsig2) : matype2=="sma 2" ? sma(smi2,nsig2) : matype2=="wma 2" ? wma(smi2,nsig2) : matype2=="trima 2" ? trima2(smi2,nsig2) : matype2=="hma 2" ? hma2(smi2,nsig2) : matype=="dema 2" ? dema2(smi2,nsig2) : matype2=="tema 2" ? tema2(smi2,nsig2) : matype2=="zlema 2" ? zlema2(smi2,nsig2) : ema(smi2,nsig2) p_smi2 = plot(smi2, title="SMI 2", color=aqua) p_sig2 = plot(sig2, title="Signal2", color=red) // plotchar(crossover(smi2, sig2), title= "low2", location=location.bottom, color=green, char="▲", size= size.tiny) // plotchar(crossunder(smi2, sig2), title= "high2", location=location.top, color=red, char="▼", size= size.tiny) /////////////////////////////3 q3 = input(5, title="%K Length 3") r3 = input(3, title="%K Smoothing Length 3") s3 = input(3, title="%K Double Smoothing Length 3") nsig3 = input(10, title="Signal Length 3") matype3 = input("ema", title="Signal MA Type 3") // possible: ema, sma, wma, trima, hma, dema, tema, zlema overbought3 = input(40, title="Overbought Level 3", type=float) oversold3 = input(-40, title="Oversold Level 3", type=float) trima3(src3, length3) => sma(sma(src3,length3),length3) hma3(src3, length3) => wma(2*wma(src3, length3/2)-wma(src3, length3), round(sqrt(length3))) dema3(src3, length3) => 2*ema(src3,length3) - ema(ema(src3,length3),length3) tema3(src3, length3) => (3*ema(src3,length3) - 3*ema(ema(src3,length3),length3)) + ema(ema(ema(src3,length3),length3),length3) zlema3(src3, length3) => ema(src3,length3) + (ema(src3,length3) - ema(ema(src3,length3),length3)) smi3 = 100 * ema(ema(close-0.5*(highest(q3)+lowest(q3)),r3),s3) / (0.5 * ema(ema(highest(q3)-lowest(q3),r3),s3)) sig3 = matype3=="ema" ? ema(smi3,nsig3) : matype3=="sma 3" ? sma(smi3,nsig3) : matype3=="wma 3" ? wma(smi3,nsig3) : matype3=="trima 3" ? trima3(smi3,nsig3) : matype3=="hma 3" ? hma3(smi3,nsig3) : matype=="dema 3" ? dema3(smi3,nsig3) : matype3=="tema 3" ? tema3(smi3,nsig3) : matype3=="zlema 3" ? zlema3(smi3,nsig3) : ema(smi3,nsig3) p_smi3 = plot(smi3, title="SMI 3", color=aqua) p_sig3 = plot(sig3, title="Signal3", color=red) // plotchar(crossover(smi3, sig3) and crossover(smi2, sig2) and crossover(smi, sig), title= "low3", location=location.bottom, color=green, char="▲", size= size.tiny) // plotchar(crossunder(smi3, sig3) and crossunder(smi2, sig2) and crossunder(smi, sig), title= "high3", location=location.top, color=red, char="▼", size= size.tiny) plotchar (((smi3 < sig3) and (smi2 < sig2) and (smi < sig)), title= "low3", location=location.bottom, color=green, char="▲", size= size.tiny) plotchar (((smi3 > sig3) and (smi2 > sig2) and (smi > sig)), title= "high3", location=location.top, color=red, char="▼", size= size.tiny) // === BACKTEST RANGE === FromMonth = input(defval = 8, title = "From Month", minval = 1, maxval = 12) FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31) FromYear = input(defval = 2018, title = "From Year", minval = 2014) ToMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12) ToDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31) ToYear = input(defval = 2018, title = "To Year", minval = 2014) longCondition = ((smi3 < sig3) and (smi2 < sig2) and (smi < sig)) shortCondition = ((smi3 > sig3) and (smi2 > sig2) and (smi > sig)) // buy = longCondition == 1 and longCondition[1] == 1 ? longCondition : na buy = longCondition == 1 ? longCondition : na sell = shortCondition == 1? shortCondition : na // === ALERTS === strategy.entry("L", strategy.long, when=buy) strategy.entry("S", strategy.short, when=sell) alertcondition(((smi3 < sig3) and (smi2 < sig2) and (smi < sig)), title='Low Fib.', message='Low Fib. Buy') alertcondition(((smi3 > sig3) and (smi2 > sig2) and (smi > sig)), title='High Fib.', message='High Fib. Low')