Chiến lược giao dịch động lượng kết hợp STEM và MATCS


Ngày tạo: 2023-09-15 16:22:48 sửa đổi lần cuối: 2023-09-15 16:22:48
sao chép: 0 Số nhấp chuột: 655
1
tập trung vào
1617
Người theo dõi

Chiến lược này được gọi là chiến lược giao dịch động lực STEM và MATCS. Chiến lược này sử dụng chỉ số Supertrend kết hợp với chỉ số MACD để tạo ra tín hiệu giao dịch.

Chiến lược hoạt động như sau:

  1. Tính toán chỉ số Supertrend, tạo ra tín hiệu mua và bán khi giá biến đổi.
  2. Tính toán đường nhanh, đường trung và đường chậm của chỉ số MACD. Khi đường nhanh vượt qua đường trung tạo ra tín hiệu mua và khi đường nhanh vượt qua đường trung tạo ra tín hiệu bán.
  3. Kết hợp với chỉ số Supertrend và MACD, chỉ khi cả hai phát ra tín hiệu đồng thời mới được tham gia.
  4. Sử dụng chỉ số ATR để tính toán điểm dừng động.

Các quy tắc giao dịch cụ thể:

  1. Khi Supertrend chuyển hướng từ giảm xuống và MACD nhanh trên đường trung tâm, hãy nhập nhiều hơn.
  2. Khi Supertrend chuyển hướng từ tròn xuống và MACD đường nhanh đi qua đường trung tâm, hãy tham gia vào.
  3. Điều kiện: dừng lỗ hoặc dừng lỗ (có thể chọn) [2].

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

  1. Kết hợp nhiều chỉ số để tăng độ chính xác tín hiệu.
  2. Động thái dừng lỗ có thể hạn chế tổn thất lớn của cá nhân
  3. Có khả năng theo dõi xu hướng và đảo ngược giao dịch

Rủi ro của chiến lược này:

  1. Các tham số chỉ số Supertrend và MACD được thiết lập không chính xác, có thể tạo ra tín hiệu sai.
  2. Điểm dừng quá gần, có thể bị dừng thường xuyên.
  3. Chi phí giao dịch và điểm trượt ảnh hưởng đến lợi nhuận.

Tóm lại, chiến lược động lực STEM và MATCS được tích hợp bởi các chỉ số tích hợp để tăng hiệu quả, phù hợp với giao dịch ngắn và trung tuyến. Việc áp dụng chiến lược dừng lỗ rất quan trọng để kiểm soát rủi ro. Các nhà giao dịch cần giảm rủi ro trong giao dịch thực bằng cách tối ưu hóa tham số và quản lý tiền nghiêm ngặt.

Mã nguồn chiến lược
/*backtest
start: 2023-09-07 00:00:00
end: 2023-09-14 00:00:00
period: 1h
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/
// © IncomePipelineGenerator
//@version=4
// strategy("STRAT_STEM_MATCS_BTC", overlay=true, pyramiding = 0, default_qty_value = 20, slippage = 5)


ST_EMA_PERIOD = input(1, minval=1)
ST_EMA = ema(close, ST_EMA_PERIOD)

LENGTH = input(title="ATR_PERIOD", type=input.integer, defval=95)
ATR_TUNE = input(title="ATR_TUNE", type=input.float, step=0.1, defval=2.1)
showLabels = input(title="Show_Buy/Sell_Labels ?", type=input.bool, defval=true)
highlightState = input(title="Highlight_State ?", type=input.bool, defval=true)

ATR = ATR_TUNE * atr(LENGTH)

longStop = ST_EMA - ATR
longStopPrev = nz(longStop[1], longStop)
longStop := (close[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = ST_EMA + ATR
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := (close[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and (close) > shortStopPrev ? 1 : dir == 1 and (close) < longStopPrev ? -1 : dir


fastLength = input(3, minval=1), medLength=input(9, minval=1), slowLength=input(12, minval=1), signalLength=input(16,minval=1)
fastMA = ema(close, fastLength), medMA = ema(close, medLength), slowMA = ema(close, slowLength)

macd = fastMA - slowMA
fmacd = fastMA - medMA
smacd = slowMA - medMA

signal = ema(macd, signalLength)
fsignal = ema(fmacd, signalLength)
ssignal = ema(smacd, signalLength)


SetStopLossShort = 0.0
SetStopLossShort := if(strategy.position_size < 0)
    StopLossShort = shortStop
    min(StopLossShort,SetStopLossShort[1])

SetStopLossLong = 0.0
SetStopLossLong := if(strategy.position_size > 0)
    StopLossLong = longStop
    max(StopLossLong,SetStopLossLong[1])


ATR_CrossOver_Period = input(5, type=input.integer, minval=1, maxval=2000)
ATR_SIGNAL_FINE_TUNE = input(0.962, type=input.float)  
ATR_CS = atr(ATR_CrossOver_Period)*ATR_SIGNAL_FINE_TUNE

StopLoss_Initial_Short = input(0.0, type=input.float) 
StopLoss_Initial_Long = input(0.0, type=input.float) 

StopLoss_Long_Adjust = input(0.0, type=input.float) 
StopLoss_Short_Adjust = input(0.0, type=input.float) 

VOLUME_CHECK = input(200)

//Custom Time Interval
fromMinute = input(defval = 0, title = "From Minute", minval = 0, maxval = 60)
fromHour = input(defval = 0, title = "From Hour", minval = 0, maxval = 24)
fromDay = input(defval = 1, title = "From Day", minval = 1)
fromMonth = input(defval = 1, title = "From Month", minval = 1)
fromYear = input(defval = 2019, title = "From Year", minval = 1900)
tillMinute = input(defval = 0, title = "Till Minute", minval = 0, maxval = 60)
tillHour = input(defval = 0, title = "Till Hour", minval = 0, maxval = 24)
tillDay = input(defval = 1, title = "Till Day", minval = 1)
tillMonth = input(defval = 1, title = "Till Month", minval = 1)
tillYear = input(defval = 2020, title = "Till Year", minval = 1900)
timestampStart = timestamp(fromYear,fromMonth,fromDay,fromHour,fromMinute)
timestampEnd = timestamp(tillYear,tillMonth,tillDay,tillHour,tillMinute)


//Custom Buy Signal Code --  This is where you design your own buy and sell signals. You now have millions of possibilites with the use of simple if/and/or statements.
if (  dir==1 and dir[1]==-1  and volume > VOLUME_CHECK and ((fsignal[1] -fsignal) <= 0) and  cross(fmacd, smacd) )
    strategy.exit("SELL")
    strategy.entry("BUY", strategy.long)
    strategy.exit("BUY_STOP","BUY", stop = close - StopLoss_Initial_Long)

//Custom Sell Signal Code
if  ( dir == -1 and dir[1] == 1 and dir[2] == 1 and dir[3] == 1 and dir[4] == 1 and  cross(fmacd, smacd) )
    strategy.exit( "BUY")
    strategy.entry("SELL", strategy.short)
    strategy.exit("SELL_STOP","SELL", stop = close + StopLoss_Initial_Short)

//Slight adjustments to ST for fine tuning
if (strategy.opentrades > 0 )
    strategy.exit("BUY_TRAIL_STOP","BUY", stop = longStop - StopLoss_Long_Adjust)
    strategy.exit("SELL_TRAIL_STOP","SELL", stop = shortStop + StopLoss_Short_Adjust)