OPEN-SOURCE SCRIPT

THE STRATEGIE

//version=5
strategy("XAU/USD Advanced Strategy with BOS & Patterns", overlay=true)

// === Paramètres utilisateur ===
rsi_length = input.int(14, title="RSI Length")
ema_length = input.int(50, title="EMA Length")
pivot_length = input.int(5, title="Pivot Length for BOS")
use_patterns = input.bool(true, title="Use Chart Patterns?")

// === Calculs de base ===
rsi = ta.rsi(close, rsi_length)
ema = ta.ema(close, ema_length)

// === Détection des tendances ===
trend_up = close > ema
trend_down = close < ema

// === Détection des divergences RSI ===
divergence_bullish = ta.lowest(low, 2) < ta.lowest(low[1], 2) and ta.rising(rsi, 2)
divergence_bearish = ta.highest(high, 2) > ta.highest(high[1], 2) and ta.falling(rsi, 2)

// === Détection des Break of Structure (BOS) ===
hh = ta.pivothigh(high, pivot_length, pivot_length)
ll = ta.pivotlow(low, pivot_length, pivot_length)
bos_bullish = close > hh[1] and trend_up
bos_bearish = close < ll[1] and trend_down

// === Détection des figures chartistes ===
triangle_pattern = use_patterns and (high[1] > high and low[1] < low)
double_top = use_patterns and (high[1] == high[2] and high > high[1])
double_bottom = use_patterns and (low[1] == low[2] and low < low[1])

// === Conditions pour signaux ===
long_condition = (divergence_bullish or bos_bullish or double_bottom) and trend_up
short_condition = (divergence_bearish or bos_bearish or double_top) and trend_down

// === Entrées et alertes ===
if long_condition
strategy.entry("Long", strategy.long)
alert("Signal d'achat détecté : Tendance haussière avec confirmation", alert.freq_once_per_bar_close)

if short_condition
strategy.entry("Short", strategy.short)
alert("Signal de vente détecté : Tendance baissière avec confirmation", alert.freq_once_per_bar_close)

// === Affichage des indicateurs ===
plot(ema, title="EMA", color=color.yellow, linewidth=2)
plot(rsi, title="RSI", color=color.blue, linewidth=2)

// === Affichage des zones RSI ===
hline(70, "RSI Overbought", color=color.red, linestyle=hline.style_dotted)
hline(30, "RSI Oversold", color=color.green, linestyle=hline.style_dotted)

// === Affichage des Break of Structure ===
plotshape(bos_bullish, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="BOS Bullish")
plotshape(bos_bearish, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="BOS Bearish")

// === Affichage des Figures Chartistes ===
bgcolor(triangle_pattern ? color.new(color.orange, 80) : na, title="Triangle Pattern")
bgcolor(double_top ? color.new(color.red, 80) : na, title="Double Top Pattern")
bgcolor(double_bottom ? color.new(color.green, 80) : na, title="Double Bottom Pattern")
Cycles

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità