
La stratégie est un système de trading auto-adaptatif combinant un retour en ZigZag et des indicateurs aléatoires. Il identifie les points de retournement critiques en calculant dynamiquement les fluctuations du marché et en combinant des signaux aléatoires de surachat et de survente pour déterminer le moment de la transaction. La stratégie intègre un mécanisme automatique de stop-loss pour gérer efficacement les risques.
Le cœur de la stratégie est de suivre dynamiquement les tendances du marché via la méthode du pourcentage inverse. Il permet aux utilisateurs de choisir de définir manuellement le pourcentage inverse ou le calcul dynamique de l’ATR sur la base de différentes périodes (de 5 à 250 jours). Un signal de multiplication est généré lorsque le prix franchit la ligne inverse et que la valeur K de l’indicateur aléatoire est inférieure à 30; un signal de pause est généré lorsque le prix franchit la ligne inverse et que la valeur K est supérieure à 70.
Il s’agit d’une stratégie de trading moderne combinant les outils classiques de l’analyse technique. Elle offre aux traders un système de trading complet en intégrant le retour ZigZag, les indicateurs aléatoires et la gestion des risques. La stratégie est hautement personnalisable et adaptée aux traders ayant des préférences de risque différentes.
/*backtest
start: 2024-06-04 00:00:00
end: 2025-02-19 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("[RS]ZigZag Percent Reversal with Stochastic Strategy", overlay=true)
// ZigZag Settings
string percent_method = input.string(
defval="MANUAL",
title="Method to use for the zigzag reversal range:",
options=[
"MANUAL",
"ATR005 * X", "ATR010 * X", "ATR020 * X", "ATR050 * X", "ATR100 * X", "ATR250 * X"
]
)
var float percent = input.float(
defval=0.25,
title="Percent of last pivot price for zigzag reversal:",
minval=0.0, maxval=99.0
) / 100
float percent_multiplier = input.float(
defval=1.0,
title="Multiplier to apply to ATR if applicable:"
)
if percent_method == "ATR005 * X"
percent := ta.atr(5) / open * percent_multiplier
if percent_method == "ATR010 * X"
percent := ta.atr(10) / open * percent_multiplier
if percent_method == "ATR020 * X"
percent := ta.atr(20) / open * percent_multiplier
if percent_method == "ATR050 * X"
percent := ta.atr(50) / open * percent_multiplier
if percent_method == "ATR100 * X"
percent := ta.atr(100) / open * percent_multiplier
if percent_method == "ATR250 * X"
percent := ta.atr(250) / open * percent_multiplier
// Zigzag function
f_zz(_percent)=>
// Direction
var bool _is_direction_up = na
var float _htrack = na
var float _ltrack = na
var float _pivot = na
float _reverse_range = 0.0
var int _real_pivot_time = na
var int _htime = na
var int _ltime = na
var float _reverse_line = na
if bar_index >= 1
if na(_is_direction_up)
_is_direction_up := true
_reverse_range := nz(_pivot[1]) * _percent
if _is_direction_up
_ltrack := na
_ltime := time
if na(_htrack)
if high > high[1]
_htrack := high
_htime := time
else
_htrack := high[1]
_htime := time[1]
else
if high > _htrack
_htrack := high
_htime := time
_reverse_line := _htrack - _reverse_range
if close <= _reverse_line
_pivot := _htrack
_real_pivot_time := _htime
_is_direction_up := false
if not _is_direction_up
_htrack := na
_htime := na
if na(_ltrack)
if low < low[1]
_ltrack := low
_ltime := time
else
_ltrack := low[1]
_ltime := time[1]
else
if low < _ltrack
_ltrack := low
_ltime := time
_reverse_line := _ltrack + _reverse_range
if close >= _reverse_line
_pivot := _ltrack
_real_pivot_time := _ltime
_is_direction_up := true
[_pivot, _is_direction_up, _reverse_line, _real_pivot_time]
[pivot, direction_up, reverse_line, pivot_time] = f_zz(percent)
// Reversal line
var float static_reverse_line = na
if (not na(reverse_line))
static_reverse_line := reverse_line
plot(series=static_reverse_line, color=color.gray, style=plot.style_line, title="Reversal Line", trackprice=false)
// Stochastic Settings
K_length = input.int(9, title="Stochastic K Length", minval=1) // User input
K_smoothing = input.int(3, title="Stochastic K Smoothing", minval=1) // User input
stochK = ta.sma(ta.stoch(close, high, low, K_length), K_smoothing)
// User Input: Take Profit and Stop Loss Levels
stop_loss_pips = input.int(100, title="Stop Loss (pips)", minval=1) // Stop Loss
take_profit_pips = input.int(300, title="Take Profit (pips)", minval=1) // Take Profit
// Calculating levels
long_stop_loss = close - stop_loss_pips * syminfo.mintick
long_take_profit = close + take_profit_pips * syminfo.mintick
short_stop_loss = close + stop_loss_pips * syminfo.mintick
short_take_profit = close - take_profit_pips * syminfo.mintick
// Buy and Sell Conditions
buy_signal = close > static_reverse_line and stochK < 30 // K < 30 condition
sell_signal = close < static_reverse_line and stochK > 70 // K > 70 condition
if buy_signal
strategy.entry("Buy", strategy.long)
strategy.exit("TP/SL", "Buy", stop=long_stop_loss, limit=long_take_profit)
if sell_signal
strategy.entry("Sell", strategy.short)
strategy.exit("TP/SL", "Sell", stop=short_stop_loss, limit=short_take_profit)
// Signal Visualization
plotshape(series=buy_signal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY", textcolor=color.white)
plotshape(series=sell_signal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL", textcolor=color.white)