Stratégie de trading avancée avec cassure de plusieurs modèles

DOJI PIN BAR HAMMER BREAKOUT CANDLESTICK RSI
Date de création: 2025-02-20 13:33:36 Dernière modification: 2025-02-20 13:33:36
Copier: 0 Nombre de clics: 349
2
Suivre
319
Abonnés

Stratégie de trading avancée avec cassure de plusieurs modèles Stratégie de trading avancée avec cassure de plusieurs modèles

Aperçu

La stratégie est un système de trading avancé basé sur la reconnaissance de formes multi-techniques, intégrant l’analyse de formes de pions et les principes de négociation de rupture. La stratégie est capable d’identifier et de négocier plusieurs formes de pions classiques, y compris les formes de croix (Doji), de marteau (Hammer) et d’aiguille (Pin Bar), tout en combinant le système de confirmation de deux pions pour améliorer la fiabilité du signal de négociation.

Principe de stratégie

La logique centrale de la stratégie repose sur les éléments clés suivants:

  1. Système de reconnaissance des formes - Identifie, par un calcul mathématique précis, les trois formes clés du dessin: l’étoile de la croix, la ligne du pendule et la forme de l’aiguille. Chaque forme possède ses propres critères d’identification, tels que le rapport entre l’objet et la ligne de l’ombre.
  2. Mécanisme de confirmation de rupture - Un système de confirmation de double fil est utilisé pour exiger que le second fil traverse le haut du fil précédent pour réduire les faux signaux.
  3. Détermination de la cible - utilisation d’une période de rétroaction réglable (de 20 cycles par défaut) pour déterminer le plus récent sommet ou le plus bas sommet comme cible, afin de rendre la stratégie dynamiquement adaptable.

Avantages stratégiques

  1. Identification de multiples formes - augmentation significative des opportunités de transactions potentielles en surveillant simultanément plusieurs formes techniques.
  2. Mécanisme de confirmation du signal - Le système de confirmation à deux niveaux réduit le risque de faux signaux.
  3. Visualiser les zones de négociation - utilisez des boîtes de couleurs pour indiquer les zones de négociation afin de rendre les objectifs de négociation plus intuitifs.
  4. Adaptation flexible des paramètres - les périodes de rétrocession peuvent être ajustées en fonction des conditions du marché.

Risque stratégique

  1. Risque de fluctuation du marché - Faux signaux de rupture peuvent apparaître pendant les périodes de forte volatilité.
  2. Risque de glissement - dans les marchés moins liquides, le prix de transaction réel peut être très éloigné du prix du signal.
  3. Risque de renversement de tendance - dans les marchés à forte tendance, les signaux de renversement peuvent entraîner des pertes plus importantes.

Direction d’optimisation

  1. Introduction de la confirmation de transaction - Il est recommandé d’inclure l’analyse de transaction dans le système de reconnaissance de forme pour améliorer la fiabilité du signal.
  2. Mécanisme d’arrêt dynamique - le point d’arrêt dynamique peut être réglé en fonction de l’ATR ou de la volatilité.
  3. Filtrage de l’environnement du marché - Ajout d’un indicateur de force de tendance pour filtrer les signaux de revers pendant une forte tendance.
  4. Optimisation des délais - envisagez la confirmation du signal sur plusieurs délais.

Résumer

La stratégie crée un système de négociation complet en combinant l’analyse de la morphologie multi-technique et les principes de négociation de rupture. Son avantage réside dans la confirmation multidimensionnelle du signal et l’ajustement flexible des paramètres, mais il faut également faire attention aux risques de volatilité et de liquidité du marché. La stabilité et la fiabilité de la stratégie peuvent être encore améliorées par l’orientation optimisée proposée.

Code source de la stratégie
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("Target(Made by Karan)", overlay=true)

// Input for lookback period
lookbackPeriod = input.int(20, title="Lookback Period for Recent High/Low", minval=1)

// --- Pattern Identification Functions ---

// Identify Doji pattern
isDoji(open, high, low, close) =>
    bodySize = math.abs(close - open)
    rangeSize = high - low
    bodySize <= rangeSize * 0.1  // Small body compared to total range

// Identify Hammer pattern
isHammer(open, high, low, close) =>
    bodySize = math.abs(close - open)
    lowerShadow = open - low
    upperShadow = high - close
    bodySize <= (high - low) * 0.3 and lowerShadow > 2 * bodySize and upperShadow <= bodySize * 0.3  // Long lower shadow, small upper shadow

// Identify Pin Bar pattern
isPinBar(open, high, low, close) =>
    bodySize = math.abs(close - open)
    rangeSize = high - low
    upperShadow = high - math.max(open, close)
    lowerShadow = math.min(open, close) - low
    (upperShadow > bodySize * 2 and lowerShadow < bodySize) or (lowerShadow > bodySize * 2 and upperShadow < bodySize)  // Long shadow on one side

// --- Candle Breakout Logic ---

// Identify the first green candle (Bullish)
is_first_green_candle = close > open

// Identify the breakout above the high of the first green candle
breakout_green_candle = ta.crossover(close, high[1]) and is_first_green_candle[1]

// Identify the second green candle confirming the breakout
second_green_candle = close > open and breakout_green_candle[1]

// Find the recent high (for the target)
recent_high = ta.highest(high, lookbackPeriod)  // Use adjustable lookback period

// Plot the green rectangle box if the conditions are met and generate buy signal
var float start_price_green = na
var float end_price_green = na

if second_green_candle
    start_price_green := low[1]  // Low of the breakout green candle
    end_price_green := recent_high  // The most recent high in the lookback period
    strategy.entry("Buy", strategy.long)  // Buy signal

// --- Red Candle Logic ---

// Identify the first red candle (Bearish)
is_first_red_candle = close < open

// Identify the breakdown below the low of the first red candle
breakdown_red_candle = ta.crossunder(close, low[1]) and is_first_red_candle[1]

// Identify the second red candle confirming the breakdown
second_red_candle = close < open and breakdown_red_candle[1]

// Find the recent low (for the target)
recent_low = ta.lowest(low, lookbackPeriod)  // Use adjustable lookback period

// Plot the red rectangle box if the conditions are met and generate sell signal
var float start_price_red = na
var float end_price_red = na

if second_red_candle
    start_price_red := high[1]  // High of the breakout red candle
    end_price_red := recent_low  // The most recent low in the lookback period
    strategy.entry("Sell", strategy.short)  // Sell signal

// --- Pattern Breakout Logic for Doji, Hammer, Pin Bar ---

// Detect breakout of Doji, Hammer, or Pin Bar patterns
var float start_price_pattern = na
var float end_price_pattern = na

// Check for Doji breakout
if isDoji(open, high, low, close) and ta.crossover(close, high[1])
    start_price_pattern := low[1]  // Low of the breakout Doji
    end_price_pattern := recent_high  // The most recent high in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = end_price_pattern, bottom = start_price_pattern, border_color = color.new(color.blue, 0), bgcolor = color.new(color.blue, 80))
    strategy.entry("Buy Doji", strategy.long)  // Buy signal for Doji breakout

// Check for Hammer breakout
if isHammer(open, high, low, close) and ta.crossover(close, high[1])
    start_price_pattern := low[1]  // Low of the breakout Hammer
    end_price_pattern := recent_high  // The most recent high in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = end_price_pattern, bottom = start_price_pattern, border_color = color.new(color.blue, 0), bgcolor = color.new(color.blue, 80))
    strategy.entry("Buy Hammer", strategy.long)  // Buy signal for Hammer breakout

// Check for Pin Bar breakout
if isPinBar(open, high, low, close) and ta.crossover(close, high[1])
    start_price_pattern := low[1]  // Low of the breakout Pin Bar
    end_price_pattern := recent_high  // The most recent high in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = end_price_pattern, bottom = start_price_pattern, border_color = color.new(color.blue, 0), bgcolor = color.new(color.blue, 80))
    strategy.entry("Buy Pin Bar", strategy.long)  // Buy signal for Pin Bar breakout

// Check for bearish Doji breakout
if isDoji(open, high, low, close) and ta.crossunder(close, low[1])
    start_price_pattern := high[1]  // High of the breakdown Doji
    end_price_pattern := recent_low  // The most recent low in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = start_price_pattern, bottom = end_price_pattern, border_color = color.new(color.orange, 0), bgcolor = color.new(color.orange, 80))
    strategy.entry("Sell Doji", strategy.short)  // Sell signal for Doji breakdown

// Check for bearish Hammer breakout
if isHammer(open, high, low, close) and ta.crossunder(close, low[1])
    start_price_pattern := high[1]  // High of the breakdown Hammer
    end_price_pattern := recent_low  // The most recent low in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = start_price_pattern, bottom = end_price_pattern, border_color = color.new(color.orange, 0), bgcolor = color.new(color.orange, 80))
    strategy.entry("Sell Hammer", strategy.short)  // Sell signal for Hammer breakdown

// Check for bearish Pin Bar breakout
if isPinBar(open, high, low, close) and ta.crossunder(close, low[1])
    start_price_pattern := high[1]  // High of the breakdown Pin Bar
    end_price_pattern := recent_low  // The most recent low in the lookback period
    box.new(left = bar_index[1], right = bar_index, top = start_price_pattern, bottom = end_price_pattern, border_color = color.new(color.orange, 0), bgcolor = color.new(color.orange, 80))
    strategy.entry("Sell Pin Bar", strategy.short)  // Sell signal for Pin Bar breakdown

// Optional: Plot shapes for the green sequence of candles
plotshape(series=is_first_green_candle, location=location.belowbar, color=color.green, style=shape.labelup, text="1st Green")
plotshape(series=breakout_green_candle, location=location.belowbar, color=color.blue, style=shape.labelup, text="Breakout")
plotshape(series=second_green_candle, location=location.belowbar, color=color.orange, style=shape.labelup, text="2nd Green")

// Optional: Plot shapes for the red sequence of candles
plotshape(series=is_first_red_candle, location=location.abovebar, color=color.red, style=shape.labeldown, text="1st Red")
plotshape(series=breakdown_red_candle, location=location.abovebar, color=color.blue, style=shape.labeldown, text="Breakdown")
plotshape(series=second_red_candle, location=location.abovebar, color=color.orange, style=shape.labeldown, text="2nd Red")