Stratégie Stochastique & Chandeliers 67% de réussite

// Indicateur de chandeliers de retournement exclusivement en zone extrême de l'indicateur Stochastique
// Crée par Sese04
// //// Le code source de cet indicateur est destiné à un usage public.
// Il est strictement interdit de le vendre, etc.
// Tous droits réservés - Copyright 2024

 

//label_color = black,red,blue // Couleur des textes et des symboles

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SESE04

//@version=5
strategy("Stratégie Stochastique & Chandeliers", overlay=true)

// "═════════ STOCHASTIC ══════════")
// Paramètres du Stochastique
sto_k_periods = input(14, title="Stochastique K")
sto_d_periods = input(3, title="Stochastique D")
sto_smoothK = input(5, title="Stochastique Lent")
sto_borner_high = input(70, title="Niveau Haut du Stochastique")
sto_borner_low = input(30, title="Niveau Bas du Stochastique")

sto_k = ta.sma(ta.stoch(close, high, low, sto_k_periods), sto_smoothK)
sto_d = ta.sma(sto_k, sto_d_periods)

// "═════════ PATTERNS ══════════")

// Fonctions pour détecter les motifs des chandeliers
is_bullish_engulfing() =>
close[1] < open[1] and open < close and close > open[1] and open < close[1]

is_bearish_engulfing() =>
close[1] > open[1] and open > close and close < open[1] and open > close[1]

is_morning_star() =>
close[2] < open[2] and close[1] < close[2] and close > open

is_evening_star() =>
close[2] > open[2] and close[1] > close[2] and close < open

is_bullish_harami() =>
close[1] < open[1] and close > open and open > close[1] and close < open[1]

is_bearish_harami() =>
close[1] > open[1] and close < open and open < close[1] and close > open[1]

is_hammer_or_hanging_man() =>
(high - (open > close ? open : close)) <= 0.25 * (high - low) and open - low >= 0.66 * (high - low)

is_shooting_star_or_inverted_hammer() =>
open - high <= 0.25 * (high - low) and high - close >= 0.66 * (high - low)

is_doji() =>
math.abs(close - open) < 0.01 * (high - low)

is_bullish_piercing() =>
close[1] < open[1] and open < close[1] and close > (open[1] + close[1]) / 2 and close < open[1]

is_dark_cloud_cover() =>
close[1] > open[1] and open > close[1] and close < (open[1] + close[1]) / 2 and close > open[1]

// "═════════ BUY & SELL ══════════")

// Conditions pour surachat et survente par rapport au stochastique
overbought_condition = sto_k > sto_borner_high
oversold_condition = sto_k < sto_borner_low

// Parametres Buy & Sell Stochastic
lenK = input(14, title='K Length')
lenD = input(3, title='D Length')
smoothK = input(3, title='K Smoothing')
srcH = ta.highest(high, lenK)
srcL = ta.lowest(low, lenK)
k = ta.sma(ta.stoch(close, srcH, srcL, lenK), smoothK)
d = ta.sma(k, lenD)

sellThreshold = 75 // You can adjust these thresholds according to your strategy
buyThreshold = 25

// Conditions pour Acheter et Vendre par rapport au stochastic valeur 75 /25
strategy.entry("Sell", strategy.short, when=ta.crossunder(k, d) and k > sellThreshold)
strategy.entry("Buy", strategy.long, when=ta.crossover(k, d) and k < buyThreshold)

// Plot shapes for candlestick patterns
plotshape(series=overbought_condition and is_bearish_engulfing() ? high : na, color=color.red, style=shape.triangledown, title="Avalement baissier", text="Avalement baissier", location=location.abovebar, textcolor=color.red)
plotshape(series=oversold_condition and is_bullish_engulfing() ? low : na, color=color.blue, style=shape.triangleup, title="Avalement haussier", text="Avalement haussier", location=location.belowbar, textcolor=color.blue)
plotshape(series=overbought_condition and is_evening_star() ? high : na, color=color.red, style=shape.triangledown, title="Etoile du soir", text="Etoile du soir", location=location.abovebar, textcolor=color.red)
plotshape(series=oversold_condition and is_morning_star() ? low : na, color=color.blue,style=shape.triangleup, title="Etoile du matin", text="Etoile du matin", location=location.belowbar, textcolor=color.blue)
plotshape(series=overbought_condition and is_bearish_harami() ? high : na, color=color.red, style=shape.triangledown, title="Harami baissier", text="Harami baissier", location=location.abovebar, textcolor=color.red)
plotshape(series=oversold_condition and is_bullish_harami() ? low : na, color=color.blue, style=shape.triangleup, title="Harami haussier", text="Harami haussier", location=location.belowbar, textcolor=color.blue)
plotshape(series=overbought_condition and is_hammer_or_hanging_man() ? high : na, color=color.red, style=shape.triangledown, title="Pendu/Marteau", text="Pendu/Marteau", location=location.abovebar, textcolor=color.red)
plotshape(series=oversold_condition and is_shooting_star_or_inverted_hammer() ? low : na, color=color.blue, style=shape.triangleup, title="Etoile filante/Marteau inversé", text="Etoile filante/Marteau inversé", location=location.belowbar, textcolor=color.blue)
plotshape(series=overbought_condition and is_doji() ? high : na, color=color.red, style=shape.triangledown, title="Doji", text="Doji", location=location.abovebar, textcolor=color.red)
plotshape(series=oversold_condition and is_bullish_piercing() ? low : na, color=color.blue, style=shape.triangleup, title="Pénétrante haussière", text="Pénétrante haussière", location=location.belowbar, textcolor=color.blue)
plotshape(series=overbought_condition and is_dark_cloud_cover() ? high : na, color=color.red, style=shape.triangledown, title="Couverture nuage noir", text="Couverture nuage noir", location=location.abovebar, textcolor=color.red)

//------------------------------------------------------------------------------------mode emploi--------------------------------------------------------------
//Ce script Pine Script est une stratégie de trading basée sur des motifs de chandeliers de retournement exclusivement en zone extrême de l'indicateur stochastique. Voici une explication détaillée de chaque partie du script :
//Ces paramètres définissent la période de calcul du stochastique (K et D), la lissage de la ligne %K (sto_smoothK), et les niveaux extrêmes de surachat (sto_borner_high) et de survente (sto_borner_low).

//Fonctions pour détecter les motifs des chandeliers
//Le script utilise plusieurs fonctions pour détecter différents motifs de chandeliers, tels que l'avalement haussier/baissier, l'étoile du matin/du soir, le harami haussier/baissier, le pendu/marteau, l'étoile filante/marteau inversé, le doji, la pénétrante haussière, et la couverture nuage noir.

//Les seuils de surachat (sellThreshold) et de survente (buyThreshold) sont définis pour déclencher des signaux d'achat et de vente en fonction des valeurs du stochastique.

//Signaux d'Achat et de Vente

//La stratégie utilise les croisements de la ligne %K et %D du stochastique avec les seuils définis pour générer des signaux d'achat et de vente.

//Plots des Formes pour les Motifs de Chandeliers
//Le script utilise la fonction plotshape pour afficher des formes sur le graphique lorsque les conditions des motifs de chandeliers sont remplies, en fonction des niveaux de surachat et de survente.

//Remarques supplémentaires
//Le script est destiné à un usage public, et l'auteur demande de ne pas le vendre ni de l'utiliser à des fins commerciales.
//Vous pouvez ajuster les paramètres tels que les périodes du stochastique, les seuils de surachat/survente, et les motifs de chandeliers en fonction de votre style de trading et des résultats de backtesting.

//Indicateur de chandeliers de retournement exclusivement en zone extrême de l'indicateur Stochastique
//Réglages des motifs de chandeliers sur Stochastique 14/3/5 et niveaux 80/20
//Signaux Buy/Sell réglés sur Stochastique 14/3/5 avec seuils de 75/25
//Après backtesting sur le Gold et le US Oil, le taux de réussite est de 63,26%
//Vous pouvez ajuster les paramètres selon votre style de trading
//Tous droits réservés - Copyright 2024