//@version=5
indicator(title="Stan Weinstein Trend Indicator",overlay=true, timeframe="W")
// Get the ticker symbol of BTCUSD index
i_sym = input.symbol("INDEX:BTCUSD", "Symbol for Relative Strength")
// Retrieve the historical close prices of BTCUSD using request.security
btcusd_close = request.security(i_sym, 'W', close)
// Calculate the ratio between the current chart and BTCUSD
ratio = close / btcusd_close
// Calculate the difference between today's ratio and yesterday's ratio
diff = ratio - ratio[1]
// Calculate the percentage variation
force_relative = (diff / ratio[1]) * 100
//Initialisation des variables
average_volume_8_period = input.float(8, "Period for SMA Volume", 1, 100, 1)
average_volume_8 = ta.ema(volume, int(average_volume_8_period))
volume_condition1 = volume <= average_volume_8
m30_period = input.float(21,"Period for EMA", 1, 100, 1)
m30 = ta.ema(close, int(m30_period))
//Calcul du RSI
rsi_period = input.float(14, "Period for RSI", 1, 100, 1)
rsi = ta.rsi(close, int(rsi_period))
rsi_condition1 = rsi < 50
//Phase 1: Consolidation
tunnel_condition = (high - low) / high <= 0.1
consolidation = volume_condition1 and rsi_condition1 and tunnel_condition
// Initialisation des variables pour phase 2
m30_condition2 = close > m30
volume_condition2 = volume > average_volume_8
resistance_period = input.float(8, "Period for Resistance", 1, 100, 1)
resistance = ta.highest(close, int(resistance_period))
resistance_condition = close >= resistance
m30_trend_condition_phase2 = m30 > m30[1]
// Phase 2: Avancée
avancee = m30_condition2 and m30_trend_condition_phase2 and volume_condition2 and force_relative > 0 and resistance_condition
//Définition des conditions pour l'EMA21
rsi_condition3 = rsi > 50
// Initialisation des variables pour phase 3
proximity_condition = math.abs(close - m30) / close <= 0.05
// Phase 3: Plafonnement
ema_trend = input.float(10, "Period for EMA trend", 1, 100, 1)
plafonnement = rsi_condition3 and proximity_condition and close <= ta.ema(close, int(ema_trend))
// Initialisation des variables pour phase 4
support_period = input.float(8,"Period for Support", 1, 100, 1)
support = ta.lowest(close, int(support_period))
support_condition = close <= support
m30_trend_condition_phase4 = m30 < m30[1]
volume_condition4 = volume > average_volume_8
// Phase 4: Declin
declin = close < m30 and m30_trend_condition_phase4 and volume_condition4 and force_relative < 0 and support_condition
plotshape(consolidation, style = shape.circle, location = location.belowbar, color = color.white, size = size.small)
plotshape(avancee, style = shape.circle, location = location.belowbar, color = color.green, size = size.small)
plotshape(plafonnement, style = shape.circle, location = location.abovebar, color = color.blue, size = size.small)
plotshape(declin, style = shape.circle, location = location.abovebar, color = color.red, size = size.small)