
Đây là một hệ thống giao dịch tự động dựa trên đường K trung bình không có bóng ((Heikin-Ashi) và giá trung bình cân bằng khối lượng giao dịch ((VWAP)). Chiến lược này thực hiện các hoạt động mua bán trong thời gian giao dịch được đặt bằng cách xác định hình thức đường K cụ thể, kết hợp với VWAP làm điểm hỗ trợ / kháng cự động. Hệ thống sử dụng rủi ro quản lý điểm dừng lỗ cố định và áp dụng các vị trí bằng phẳng vào một thời gian nhất định mỗi ngày để tránh rủi ro qua đêm.
Logic cốt lõi của chiến lược này dựa trên các yếu tố chính sau:
Chiến lược này xây dựng một hệ thống giao dịch trong ngày vững chắc bằng cách kết hợp các chỉ số Heikin-Ashi và VWAP. Mặc dù có một số không gian để tối ưu hóa, nhưng khuôn khổ cơ bản có tính thực tế tốt. Với hướng tối ưu hóa được đề xuất, chiến lược có khả năng hoạt động tốt hơn trong các điều kiện thị trường khác nhau.
/*backtest
start: 2024-07-16 00:00:00
end: 2025-02-19 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Buy and Sell Signal with VWAP and Timed Exit", overlay=true)
// VWAP Calculation
vwap = ta.vwap(close)
// Heikin-Ashi Formula
var float heikin_open = na
var float heikin_close = na
heikin_open := na(heikin_open[1]) ? (open + close) / 2 : (heikin_open[1] + heikin_close[1]) / 2
heikin_close := (open + high + low + close) / 4
heikin_high = math.max(high, math.max(heikin_open, heikin_close))
heikin_low = math.min(low, math.min(heikin_open, heikin_close))
// Conditions for Sell (Red Heikin-Ashi with no upper shadow) and Buy (Green Heikin-Ashi with no lower shadow)
no_upper_shadow = heikin_high == math.max(heikin_open, heikin_close)
no_lower_shadow = heikin_low == math.min(heikin_open, heikin_close)
// Condition for red (sell) and green (buy) Heikin-Ashi candles
is_red_candle = heikin_close < heikin_open
is_green_candle = heikin_close > heikin_open
// Buy and Sell Signal Conditions
sell_signal = is_red_candle and no_upper_shadow and close < vwap
buy_signal = is_green_candle and no_lower_shadow and close > vwap
// Check current time (for 15:01 IST)
is_after_1501 = (hour == 15 and minute > 1) or (hour > 15)
// Check for open positions
open_sell_position = strategy.position_size < 0
open_buy_position = strategy.position_size > 0
// Trigger Sell order only if no open sell position exists and time is before 15:01, and price is below VWAP
if sell_signal and not open_sell_position and not is_after_1501
strategy.entry("Sell", strategy.short)
// Trigger Buy order only if no open buy position exists and time is before 15:01, and price is above VWAP
if buy_signal and not open_buy_position and not is_after_1501
strategy.entry("Buy", strategy.long)
// Define exit condition for Sell (opposite of Buy conditions)
exit_sell_condition = false
if open_sell_position
entry_price = strategy.position_avg_price // Get the average entry price for Sell
current_price = close // Current market price for Sell
// Exit conditions for Sell
exit_sell_condition := current_price > entry_price or entry_price - current_price >= 50
// Exit if conditions are met
if exit_sell_condition
strategy.close("Sell")
// Define exit condition for Buy (opposite of Sell conditions)
exit_buy_condition = false
if open_buy_position
entry_price = strategy.position_avg_price // Get the average entry price for Buy
current_price = close // Current market price for Buy
// Exit conditions for Buy
exit_buy_condition := current_price < entry_price or current_price - entry_price >= 50
// Exit if conditions are met
if exit_buy_condition
strategy.close("Buy")
// Exit at 15:01 IST for both Buy and Sell if not already exited
if (open_sell_position or open_buy_position) and (hour == 15 and minute == 1)
strategy.close("Sell")
strategy.close("Buy")
// Plot VWAP
plot(vwap, color=color.blue, linewidth=2, title="VWAP")
// Plot Heikin-Ashi Candles
plotcandle(heikin_open, heikin_high, heikin_low, heikin_close, color = is_red_candle ? color.red : (is_green_candle ? color.green : color.gray))
// Plot Sell signal on the chart
plotshape(sell_signal and not open_sell_position and not is_after_1501, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)
// Plot Buy signal on the chart
plotshape(buy_signal and not open_buy_position and not is_after_1501, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
// Plot Exit signals on the chart
plotshape(exit_sell_condition and open_sell_position, style=shape.labelup, location=location.belowbar, color=color.blue, text="EXIT SELL", size=size.small)
plotshape(exit_buy_condition and open_buy_position, style=shape.labeldown, location=location.abovebar, color=color.blue, text="EXIT BUY", size=size.small)