
Chiến lược này sử dụng chỉ số đèn treo để xác định hướng và cường độ của sự phá vỡ giá, do đó tạo ra tín hiệu mua và bán. Nó chỉ thực hiện các hoạt động mua.
Chiến lược này dựa trên chỉ số đèn treo, đèn treo là thiết lập đường dừng dựa trên giá cao nhất, giá thấp nhất và độ dao động thực tế trung bình của giá. Cụ thể, chiến lược tính toán độ dao động thực tế trung bình trong ngày 22 và nhân với một hệ số (bằng cách mặc định 3). Sau đó, dựa trên giá trị này, thiết lập đường dừng dài và đường dừng ngắn.
Chiến lược này chỉ thực hiện các hoạt động mua. Cụ thể, nó tạo ra tín hiệu mua khi giá vượt qua đường dừng dài trước đó. Sau đó, nó tạo ra tín hiệu bán và thanh toán khi giá vượt qua đường dừng ngắn.
Phương pháp giải quyết rủi ro:
Chiến lược này sử dụng các chỉ số đèn treo động để xác định các cơ hội đảo ngược giá. Nó chỉ mua khi giá vượt qua đường dừng dài và bán khi giá vượt qua đường dừng ngắn, thực hiện một chiến lược đơn giản đơn phương, tránh cả hai mặt của hành động. Chiến lược này kiểm soát rủi ro một cách hiệu quả, nhưng không có thiết lập dừng và dừng. Chúng ta có thể tối ưu hóa chiến lược này bằng cách thêm các chỉ số khác để lọc và thiết lập dừng lỗ.
/*backtest
start: 2023-12-28 00:00:00
end: 2024-01-04 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Chandelier Exit Strategy", overlay=true)
length = input(title='ATR Period', defval=22)
mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0)
showLabels = input(title='Show Buy/Sell Labels ?', defval=true)
useClose = input(title='Use Close Price for Extremums ?', defval=true)
highlightState = input(title='Highlight State ?', defval=true)
atr = mult * ta.atr(length)
longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
var color longColor = color.green
var color shortColor = color.red
longStopPlot = plot(dir == 1 ? longStop : na, title='Long Stop', style=plot.style_linebr, linewidth=2, color=color.new(longColor, 0))
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title='Long Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 0))
plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(longColor, 0), textcolor=color.new(color.white, 0))
shortStopPlot = plot(dir == 1 ? na : shortStop, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0))
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title='Short Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 0))
plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(shortColor, 0), textcolor=color.new(color.white, 0))
changeCond = dir != dir[1]
alertcondition(changeCond, title='Alert: CE Direction Change', message='Chandelier Exit has changed direction!')
alertcondition(buySignal, title='Alert: CE Buy', message='Chandelier Exit Buy!')
alertcondition(sellSignal, title='Alert: CE Sell', message='Chandelier Exit Sell!')
// Define initial capital
initial_capital =25
// Trigger buy order and close buy order on sell signal
if buySignal
strategy.entry("Buy", strategy.long, qty = initial_capital / close)
if sellSignal
strategy.close("Buy")