
Il s’agit d’une stratégie innovante de confirmation de tendance sans repérage de Heikin-Ashi, qui vise à résoudre le problème de la repérage de la stratégie de Heikin-Ashi dans la vue de trading traditionnelle. La stratégie offre une méthode de négociation plus fiable et plus transparente en calculant manuellement Heikin-Ashi et le mécanisme de confirmation de tendance multiple.
Le principe de base de la stratégie comprend trois étapes clés:
Le calcul de l’équivalent de Haïkan Asif n’a pas été réalisé manuellement:
Les tendances multiples sont confirmées:
Le modèle de transaction flexible:
Limites de fonctionnalité:
Contrôle des risques potentiels:
Adaptation dynamique des paramètres:
Une meilleure gestion des risques:
Composé des indicateurs:
La stratégie de confirmation de tendance de repérage d’Afrique de l’Ouest offre aux traders un outil de négociation plus fiable et plus transparent grâce à des méthodes innovantes de calcul de la courbe et de confirmation de tendance multiple. La stratégie montre le potentiel d’innovation technologique dans le trading quantifié en éliminant les problèmes de repérage, en filtrant les faux signaux et en offrant un modèle de négociation flexible.
/*backtest
start: 2025-03-15 00:00:00
end: 2025-03-27 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
//© PineIndicators
strategy("Heikin-Ashi Non-Repainting Strategy [PineIndicators]", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, max_boxes_count=500, max_labels_count=500, max_lines_count=500, commission_value=0.01, process_orders_on_close=true, slippage= 2, behind_chart=false)
//====================================
// INPUTS
//====================================
// Number of consecutive candles required for entry and exit
openThreshold = input.int(title="Number of Candles for Entry", defval=2, minval=1)
exitThreshold = input.int(title="Number of Candles for Exit", defval=2, minval=1)
// Trade mode selection: "Long & Short", "Only Long", or "Only Short"
tradeMode = input.string(title="Trade Mode", defval="Only Long", options=["Long & Short", "Only Long", "Only Short"])
// Option to invert the trading logic (bullish signals become short signals, and vice versa)
invertTrades = input.bool(title="Invert Trading Logic (Long ↔ Short)", defval=false)
// Option to hide the standard candles (bodies only)
hideStandard = input.bool(title="Hide Standard Candles", defval=true)
// Heikin-Ashi transparency is fixed (0 = fully opaque)
heikinTransparency = 0
//====================================
// HIDE STANDARD CANDLES
//====================================
// Hide the body of the standard candles by setting them to 100% transparent.
// Note: The wicks of the standard candles cannot be hidden via code.
barcolor(hideStandard ? color.new(color.black, 100) : na)
//====================================
// HEIKIN-ASHI CALCULATION
//====================================
// Calculate Heikin-Ashi values manually
haClose = (open + high + low + close) / 4
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))
// Define colors for Heikin-Ashi candles (using fixed transparency)
bullColor = color.new(#0097a7, heikinTransparency)
bearColor = color.new(#ff195f, heikinTransparency)
//====================================
// PLOT HEIKIN-ASHI CANDLES
//====================================
// Plot the manually calculated Heikin-Ashi candles over the chart.
// The candle body, wicks, and borders will be colored based on whether the candle is bullish or bearish.
plotcandle(haOpen, haHigh, haLow, haClose, title="Heikin-Ashi",
color = haClose >= haOpen ? bullColor : bearColor,
wickcolor = haClose >= haOpen ? bullColor : bearColor,
bordercolor = haClose >= haOpen ? bullColor : bearColor,
force_overlay = true)
//====================================
// COUNT CONSECUTIVE TREND CANDLES
//====================================
// Count the number of consecutive bullish or bearish Heikin-Ashi candles.
var int bullishCount = 0
var int bearishCount = 0
if haClose > haOpen
bullishCount := bullishCount + 1
bearishCount := 0
else if haClose < haOpen
bearishCount := bearishCount + 1
bullishCount := 0
else
bullishCount := 0
bearishCount := 0
//====================================
// DEFINE ENTRY & EXIT SIGNALS
//====================================
// The signals are based on the number of consecutive trend candles.
// In normal logic: bullish candles trigger a long entry and bearish candles trigger a short entry.
// If invertTrades is enabled, the signals are swapped.
var bool longEntrySignal = false
var bool shortEntrySignal = false
var bool exitLongSignal = false
var bool exitShortSignal = false
if not invertTrades
longEntrySignal := bullishCount >= openThreshold
shortEntrySignal := bearishCount >= openThreshold
exitLongSignal := bearishCount >= exitThreshold
exitShortSignal := bullishCount >= exitThreshold
else
// Inverted logic: bullish candles trigger short entries and bearish candles trigger long entries.
longEntrySignal := bearishCount >= openThreshold
shortEntrySignal := bullishCount >= openThreshold
exitLongSignal := bullishCount >= exitThreshold
exitShortSignal := bearishCount >= exitThreshold
//====================================
// APPLY TRADE MODE RESTRICTIONS
//====================================
// If the user selects "Only Long", disable short signals (and vice versa).
if tradeMode == "Only Long"
shortEntrySignal := false
exitShortSignal := false
else if tradeMode == "Only Short"
longEntrySignal := false
exitLongSignal := false
//====================================
// TRADING STRATEGY LOGIC
//====================================
// Execute trades based on the calculated signals.
// If a long position is open:
if strategy.position_size > 0
if shortEntrySignal
strategy.close("Long", comment="Reverse Long")
strategy.entry("Short", strategy.short, comment="Enter Short")
else if exitLongSignal
strategy.close("Long", comment="Exit Long")
// If a short position is open:
if strategy.position_size < 0
if longEntrySignal
strategy.close("Short", comment="Reverse Short")
strategy.entry("Long", strategy.long, comment="Enter Long")
else if exitShortSignal
strategy.close("Short", comment="Exit Short")
// If no position is open:
if strategy.position_size == 0
if longEntrySignal
strategy.entry("Long", strategy.long, comment="Enter Long")
else if shortEntrySignal
strategy.entry("Short", strategy.short, comment="Enter Short")