Chiến lược cơ bản SuperTrend

Tác giả:ChaoZhang, Ngày: 2023-10-11 15:14:54
Tags:

Tổng quan

Chiến lược cơ bản SuperTrend là một chiến lược giao dịch thuật toán đáng tin cậy và có lợi nhuận dựa trên ba chỉ số mạnh mẽ: SuperTrend (ATR), RSI và EMA. Nó nhằm mục đích xác định hướng và sức mạnh của xu hướng thị trường, vào thị trường tại các điểm tối ưu và thoát ra khi dừng lỗ hoặc lấy lợi nhuận.

Chiến lược logic

Chiến lược sử dụng chỉ số SuperTrend để xác định giá có đang trong xu hướng tăng hay giảm.

RSI được sử dụng để phát hiện các điều kiện mua quá mức / bán quá mức. Trên 50 là tăng và dưới 50 giảm. RSI lọc ra các tín hiệu sai.

EMA đánh giá hướng xu hướng dài hạn. Trên EMA là xu hướng tăng, dưới đây là xu hướng giảm. Nó xác nhận hướng giao dịch.

Các tín hiệu giao dịch là:

Đăng nhập dài: Giá trên SuperTrend và RSI trên 50 và Giá trên EMA Ra ngoài dài: Giá đóng dưới SuperTrend hoặc Stop loss hoặc Take profit

Nhập ngắn: Giá dưới SuperTrend và RSI dưới 50 và Giá dưới EMA Khóa ngắn: Giá đóng trên SuperTrend hoặc Stop loss hoặc Take profit

Stop loss và take profit có thể được thiết lập theo tỷ lệ phần trăm của giá nhập cảnh.

Phân tích lợi thế

Những lợi thế của chiến lược này:

  1. Kết hợp 3 chỉ số, phát hiện xu hướng đáng tin cậy

  2. SuperTrend xác định rõ xu hướng tăng và giảm

  3. Chỉ số RSI lọc ra các sự phá vỡ sai, tránh mua quá mức / bán quá mức

  4. EMA xác nhận xu hướng chung

  5. Các tín hiệu giao dịch đơn giản và rõ ràng, dễ làm theo

  6. Thời gian ATR có thể tùy chỉnh, các tham số RSI và thời gian EMA để tối ưu hóa

  7. Dừng lỗ và lấy lợi nhuận để kiểm soát rủi ro

  8. Chế độ chỉ dài hoặc chỉ ngắn cho các thị trường khác nhau

  9. Áp dụng cho bất kỳ khung thời gian nào

Phân tích rủi ro

Những rủi ro chính:

  1. Sự chậm trễ của SuperTrend trong sự đảo ngược xu hướng, có thể gây ra tổn thất

  2. Stop loss nhỏ / lấy lợi nhuận không bắt được những động thái lớn

  3. EMA không thể phát hiện các điểm đảo ngược xu hướng

  4. Không phát hiện sự khác biệt

  5. Vẫn có rủi ro biến động và rủi ro thời gian

Giải pháp:

  1. Thêm các chỉ số khác để phát hiện đảo ngược

  2. Tối ưu hóa stop loss/take profit

  3. Thêm các chỉ số khác vào sự đảo ngược tại chỗ

  4. Bao gồm các chỉ số phân kỳ

  5. Điều chỉnh kích thước vị trí

Hướng dẫn tối ưu hóa

Cách tối ưu hóa chiến lược:

  1. Tối ưu hóa thời gian ATR cho độ nhạy và ổn định

  2. Tối ưu hóa các thông số RSI để chính xác cao hơn

  3. Tối ưu hóa thời gian EMA cho các thị trường khác nhau

  4. Thêm các chỉ số như MACD, KD để phát hiện đảo ngược

  5. Thêm các chỉ số khác biệt

  6. Sử dụng sóng Elliott để phát hiện sự đảo ngược

  7. Sử dụng máy học để tối ưu hóa các tham số một cách năng động

  8. Các thuật toán dừng lỗ tiên tiến như dừng lỗ sau

  9. Tối ưu hóa kích thước vị trí cho sự biến động khác nhau

  10. Kiểm tra các điều kiện nhập và xuất phức tạp hơn

Kết luận

Chiến lược cơ bản SuperTrend tích hợp SuperTrend, RSI và EMA vào một hệ thống theo xu hướng đơn giản và thực tế. Nó xác định rõ hướng xu hướng, lọc ra các tín hiệu sai và xác nhận xu hướng tổng thể. Quy tắc nhập cảnh, thoát rõ ràng và cấu hình dừng lỗ / lấy lợi nhuận. Dễ sử dụng, lợi nhuận đáng tin cậy. Áp dụng cho bất kỳ khung thời gian nào. Nó có thể được tối ưu hóa thêm bằng cách điều chỉnh các tham số, thêm các công cụ đảo ngược, nâng cao dừng để trở thành một hệ thống giao dịch mạnh mẽ hơn.


/*backtest
start: 2023-09-10 00:00:00
end: 2023-10-10 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JS_TechTrading

//@version=5
// strategy("Supertrend", overlay=true,default_qty_type =strategy.percent_of_equity,default_qty_value = 1,process_orders_on_close = false)

// group string////
var string group_text000="Choose Strategy"
var string group_text0="Supertrend Settings"
var string group_text0000="Ema Settings"
var string group_text00="Rsi Settings"
var string group_text1="Backtest Period"
var string group_text2="Trade Direction"
// var string group_text3="Quantity Settings"
var string group_text4="Sl/Tp Settings"
////////////////////
option_ch=input.string('Pullback',title = "Type Of Strategy",options =['Pullback','Simple'])

//atr period input supertrend 
atrPeriod = input(10, "ATR Length",group = group_text0)
factor = input.float(3.0, "Factor", step = 0.01,group=group_text0)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

long=direction < 0 ? supertrend : na
short=direction < 0? na : supertrend

longpos=false
shortpos=false

longpos :=long?true :short?false:longpos[1]
shortpos:=short?true:long?false:shortpos[1]

fin_pullbuy= (ta.crossunder(low[1],long) and long and high>high[1])
fin_pullsell=(ta.crossover(high[1],short) and short and low<low[1]) 

//Ema 1
on_ma=input.bool(true,"Ema Condition On/Off",group=group_text0000)
ma_len= input.int(200, minval=1, title="Ema Length",group = group_text0000)
ma_src = input.source(close, title="Ema Source",group = group_text0000)
ma_out = ta.ema(ma_src, ma_len)

ma_buy=on_ma?close>ma_out?true:false:true
ma_sell=on_ma?close<ma_out?true:false:true

// rsi indicator and condition
// Get user input
en_rsi    = input.bool(true,"Rsi Condition On/Off",group = group_text00)
rsiSource = input(title='RSI Source', defval=close,group = group_text00)
rsiLength = input(title='RSI Length', defval=14,group = group_text00)
rsiOverbought = input(title='RSI BUY Level', defval=50,group = group_text00)
rsiOversold   = input(title='RSI SELL Level', defval=50,group = group_text00)

// Get RSI value
rsiValue = ta.rsi(rsiSource, rsiLength)

rsi_buy=en_rsi?rsiValue>=rsiOverbought ?true:false:true
rsi_sell=en_rsi?rsiValue<=rsiOversold?true:false:true

// final condition
buy_cond=option_ch=='Simple'?long and not(longpos[1]) and rsi_buy and ma_buy:option_ch=='Pullback'?fin_pullbuy and rsi_buy and ma_buy:na
sell_cond=option_ch=='Simple'?short and not(shortpos[1]) and rsi_sell and ma_sell:option_ch=='Pullback'?fin_pullsell and rsi_sell and ma_sell:na

//backtest engine
start = input(timestamp('2005-01-01'), title='Start calculations from',group=group_text1)
end=input(timestamp('2045-03-01'), title='End calculations',group=group_text1)
time_cond =true

// Make input option to configure trade direction

tradeDirection = input.string(title='Trade Direction', options=['Long', 'Short', 'Both'], defval='Both',group = group_text2)

// Translate input into trading conditions
longOK  = (tradeDirection == "Long") or (tradeDirection == "Both")
shortOK = (tradeDirection == "Short") or (tradeDirection == "Both")



// strategy start
if buy_cond and longOK and time_cond and strategy.position_size==0
    strategy.entry('long',direction = strategy.long)
if sell_cond and shortOK and time_cond and strategy.position_size==0
    strategy.entry('short',direction =strategy.short)

// fixed percentage based stop loss and take profit 

// User Options to Change Inputs (%)
stopPer = input.float(1.0,step=0.10, title='Stop Loss %',group =group_text4) / 100
takePer = input.float(1.0,step =0.10, title='Take Profit %',group =group_text4) / 100

// Determine where you've entered and in what direction
longStop  = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake  = strategy.position_avg_price * (1 + takePer)


if strategy.position_size > 0
    strategy.exit(id='Close Long',stop=longStop, limit=longTake)
if strategy.position_size < 0
    strategy.exit(id='Close Short',stop=shortStop, limit=shortTake)

//PLOT FIXED SLTP LINE
plot(strategy.position_size > 0 ? longStop : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Long Fixed SL')
plot(strategy.position_size < 0 ? shortStop :na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Short Fixed SL')
plot(strategy.position_size > 0 ? longTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Long Take Profit')
plot(strategy.position_size < 0 ? shortTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Short Take Profit')

//

Thêm nữa