Stratégie Stochastique & Chandeliers

// Indicateur de chandeliers de retournement exclusivement en zone extrême de l'indicateur Stochastique
// Crée par touli de trader's journal
// //// Le code source de cet indicateur est destiné à un usage personnel uniquement.
// Il est strictement interdit de vendre, etc. Ce code est protégé par le droit d'auteur et propriété intellectuelle.
// Tous droits réservés - Copyright 2024
//
// Découvrez mes autres Indicateurs sur tradingview et trader-s-journal.org
//----------------------------------------------------------------------------------------------------------------------------------------------------


// 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
indicator("Stratégie Stochastique & Chandeliers", overlay=true)
//label_color = black/red:blue // Couleur des textes et des symboles black/red:blue

//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════ 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)
//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════ 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]

//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════ Conditions pour surachat et survente par rapport au stochastique ══════════"
//----------------------------------------------------------------------------------------------------------------------------------------------------

overbought_condition = sto_k > sto_borner_high
oversold_condition = sto_k < sto_borner_low

// Affichage des motifs sur le graphique en fonction du Stochastique
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)

//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════ Paramètres deuxieme stochastique ══════════"
//----------------------------------------------------------------------------------------------------------------------------------------------------

lenK = input(14, title='K Length')
lenD = input(3, title='D Length')
smoothK = input(5, 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 = 70 // You can adjust these thresholds according to your strategy
buyThreshold = 30
//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════// Conditions pour Acheter et Vendre par rapport au stochastic valeur 70 /30 ══════════"
//----------------------------------------------------------------------------------------------------------------------------------------------------


plotshape(series=ta.crossunder(k, d) and k > sellThreshold ? high : na, color=color.red, style=shape.labeldown, title="Sell", text="Sell", location=location.abovebar)
plotshape(series=ta.crossover(k, d) and k < buyThreshold ? low : na, color=color.blue, style=shape.labelup, title="Buy", text="Buy", location=location.belowbar, textcolor=color.yellow)

//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════ Paramètres Troisieme stochastique ══════════"
//----------------------------------------------------------------------------------------------------------------------------------------------------

 

lenK1 = input(14, title='K Length')
lenD1 = input(3, title='D Length')
smoothK1 = input(5, title='K Smoothing')
srcH1 = ta.highest(high, lenK)
srcL1 = ta.lowest(low, lenK)
k1 = ta.sma(ta.stoch(close, srcH, srcL, lenK), smoothK)
d1 = ta.sma(k, lenD)

sellThreshold1 = 80 // You can adjust these thresholds according to your strategy
buyThreshold1 = 20

//----------------------------------------------------------------------------------------------------------------------------------------------------
// "═════════// Conditions pour Acheter et Vendre par rapport au stochastic valeur 80 /20 ══════════"
//----------------------------------------------------------------------------------------------------------------------------------------------------


plotshape(series=ta.crossunder(k, d) and k > sellThreshold ? high : na, color=color.red, style=shape.labeldown, title="Sell", text="Sell", location=location.abovebar)
plotshape(series=ta.crossover(k, d) and k < buyThreshold ? low : na, color=color.blue, style=shape.labelup, title="Buy", text="Buy", location=location.belowbar, textcolor=color.yellow)


-----------------------------------------------------------------------"========== Mode emploi"==========-----------------------------------------------------

Mode d'emploi de l'indicateur "Stratégie Stochastique & Chandeliers"

Description :
Cet indicateur combine les signaux du Stochastique avec des motifs de chandeliers pour générer des signaux d'achat et de vente. Il utilise deux configurations distinctes du Stochastique, encadrant les signaux d'achat et de vente. Les motifs de chandeliers sont exclusivement recherchés en zone extrême du Stochastique.

Utilisation :

Stochastique principal :

Paramètres :

Stochastique K périodes : Périodes pour le calcul du %K.
Stochastique D périodes : Périodes pour le calcul du %D.
Stochastique Lent : Périodes de lissage pour le %K.
Niveau Haut du Stochastique : Seuil pour la surachat.
Niveau Bas du Stochastique : Seuil pour la survendre.
Signaux :

Des motifs de chandeliers sont affichés en fonction des conditions de surachat et de survendre.
Les motifs incluent l'Avalement baissier/haussier, l'Etoile du soir/matinal, le Harami baissier/haussier, le Pendu/Marteau, l'Etoile filante/Marteau inversé, le Doji, la Pénétrante haussière, et la Couverture nuage noir.
Stochastique pour les signaux d'achat/vente :

Paramètres :

K Length : Périodes pour le calcul du %K.
D Length : Périodes pour le calcul du %D.
K Smoothing : Périodes de lissage pour le %K.
Seuil de vente (70) : Seuil pour la surachat.
Seuil d'achat (30) : Seuil pour la survendre.
Signaux :

Des formes triangulaires sont affichées au-dessus des chandeliers pour indiquer les signaux d'achat (Buy) et de vente (Sell) en fonction des conditions du Stochastique.
Stochastique supplémentaire pour les signaux d'achat/vente :

Paramètres :

Mêmes paramètres que le Stochastique précédent.
Signaux :

Des formes triangulaires sont affichées au-dessus des chandeliers pour indiquer les signaux d'achat (Buy) et de vente (Sell) en fonction des conditions du Stochastique.
Remarques :

Vous pouvez ajuster les seuils de surachat et de survendre ainsi que d'autres paramètres en fonction de votre stratégie.
Les motifs de chandeliers sont affichés uniquement en zone extrême du Stochastique principal.
Les configurations des deux Stochastiques encadrent les signaux d'achat et de vente, fournissant une approche plus prudente pour les traders.