
Ini adalah strategi pengesahan tren Heikin-Ashi yang inovatif dan tidak digambar ulang, yang bertujuan untuk mengatasi masalah yang ada dengan strategi Heikin-Ashi dalam tampilan perdagangan tradisional. Dengan menghitung Heikin-Ashi dan mekanisme pengesahan tren ganda secara manual, strategi ini memberikan metode perdagangan yang lebih andal dan transparan.
Prinsip-prinsip utama dari strategi ini terdiri dari tiga langkah penting:
Perhitungan ini dilakukan secara manual tanpa menggambar ulang Haikang-Asi:
Beberapa tren yang dikonfirmasi:
Model perdagangan yang fleksibel:
Keterbatasan kinerja:
Pengendalian risiko potensial:
Pengaturan dinamis parameter:
Manajemen risiko yang lebih baik:
Kombinasi indikator:
Strategi pengesahan tren peta ulang Haikang-Sisi Afrika memberikan para pedagang alat perdagangan yang lebih andal dan transparan melalui perhitungan pivot inovatif dan metode pengesahan tren ganda. Strategi ini menunjukkan potensi inovasi teknologi dalam perdagangan kuantitatif dengan menghilangkan masalah peta ulang, memfilter sinyal palsu, dan menyediakan model perdagangan yang fleksibel.
/*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")