Chiến lược giao dịch Rainbow Oscillator


Ngày tạo: 2024-02-23 14:57:43 sửa đổi lần cuối: 2024-02-23 14:57:43
sao chép: 4 Số nhấp chuột: 706
1
tập trung vào
1617
Người theo dõi

Chiến lược giao dịch Rainbow Oscillator

Tổng quan

Chiến lược giao dịch Rainbow Vibrator chủ yếu sử dụng nhiều chỉ số để tạo ra các kênh rung động nhiều tầng, tạo ra các tín hiệu đa không gian rõ ràng về cấp độ, thuộc loại chiến lược theo dõi xu hướng. Chiến lược này sử dụng tổng hợp các chỉ số kết hợp RSI, CCI, Stochastic và MA để xác định xu hướng tổng thể của thị trường và khu vực mua bán quá mức, thuộc loại chiến lược đánh giá đa yếu tố.

Nguyên tắc chiến lược

  1. Tính trung bình trọng số của 3 chỉ số RSI, CCI và Stochastic để xây dựng chỉ số biến động tổng hợp Magic;
  2. Làm trơn chỉ số Magic nhiều lần để có được hai đường cong được lấy mẫu MagicFast và lấy mẫu MagicSlow;
  3. sampledMagicFast đại diện cho trung bình nhanh, sampledMagicSlow đại diện cho trung bình chậm;
  4. Sản xuất tín hiệu mua khi mặc sampledMagicSlow trên sampledMagicFast;
  5. Một dấu hiệu bán ra được tạo ra khi sử dụng MagicSlow dưới sampledMagicFast;
  6. Tính toán chiều thay đổi của sampledMagicFast của thanh cuối cùng so với thanh trước để đánh giá xu hướng hiện tại;
  7. Thời gian vào và ra sân được đánh giá dựa trên hướng xu hướng và sự giao thoa của MagicFast và MagicSlow.

Lợi thế chiến lược

  1. Các chỉ số tổng hợp được sử dụng để đánh giá xu hướng chung của thị trường và tăng cường độ chính xác của tín hiệu.
  2. Dựa trên chỉ số MA mịn, hiệu quả giảm tín hiệu tiếng ồn;
  3. Các tín hiệu rung chuyển rõ ràng và dễ dàng sử dụng.
  4. Kết hợp với bộ lọc xu hướng, có thể được cấu hình để theo dõi xu hướng hoặc đảo ngược;
  5. Có thể tùy chỉnh cường độ khu vực mua bán quá mức, có khả năng thích ứng.

Rủi ro chiến lược

  1. Các tham số đặt sai có thể dẫn đến đường cong quá mịn và bỏ lỡ thời gian đầu vào tốt nhất;
  2. Không đúng cách thiết lập khu vực mua quá mức có thể dẫn đến thời gian trống quá lâu;
  3. Một số chỉ số bị lỗi trong xếp hạng đa yếu tố sẽ làm suy yếu hiệu quả tín hiệu.

Giải pháp tương ứng:

  1. Tối ưu hóa các tham số, làm cho đường cong trơn ở mức trung bình;
  2. Điều chỉnh cường độ của khu vực quá mua quá bán để giảm tỷ lệ trống.
  3. Kiểm tra khả năng dự đoán của mỗi chỉ số, điều chỉnh theo trọng số.

Hướng tối ưu hóa chiến lược

  1. Điều chỉnh các tham số chỉ số dựa trên các đặc điểm của thị trường;
  2. Nhập các phương pháp học máy để tự động tối ưu hóa các trọng số của các chỉ số;
  3. Các yếu tố như tăng âm lượng và dao động sẽ được lọc ra từ tín hiệu nhập cảnh.

Tóm tắt

Chiến lược Rainbow Vibrator tích hợp nhiều tín hiệu chỉ số, tăng sự ổn định bằng cách xử lý chỉ số một cách mượt mà. Chiến lược có thể được cấu hình để thích ứng với xu hướng và thị trường chấn động, hoặc chỉ được sử dụng cho các biến động chấn động của một giống cụ thể. Bằng cách tối ưu hóa tham số và mở rộng chỉ số, có thể nâng cao chất lượng tín hiệu hơn nữa.

Mã nguồn chiến lược
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © businessduck

//@version=5
strategy("Rainbow Oscillator [Strategy]", overlay=false, margin_long=100, margin_short=100, initial_capital = 2000)

bool trendFilter = input.bool(true, 'Use trend filter')
float w1 = input.float(0.33, 'RSI Weight', 0, 1, 0.01)
float w2 = input.float(0.33, 'CCI Weight', 0, 1, 0.01)
float w3 = input.float(0.33, 'Stoch Weight', 0, 1, 0.01)
int fastPeriod = input.int(16, 'Ocillograph Fast Period', 4, 60, 1)
int slowPeriod = input.int(22, 'Ocillograph Slow Period', 4, 60, 1)
int oscillographSamplePeriod = input.int(8, 'Oscillograph Samples Period', 1, 30, 1)
int oscillographSamplesCount = input.int(2, 'Oscillograph Samples Count', 0, 4, 1)
string oscillographMAType = input.string("RMA", "Oscillograph Samples Type", options = ["EMA", "SMA", "RMA", "WMA"])
int levelPeriod = input.int(26, 'Level Period', 2, 100)
int levelOffset = input.int(0, 'Level Offset', 0, 200, 10)
float redunant = input.float(0.5, 'Level Redunant', 0, 1, 0.01)
int levelSampleCount = input.int(2, 'Level Smooth Samples', 0, 4, 1)
string levelType = input.string("RMA", "Level MA type", options = ["EMA", "SMA", "RMA", "WMA"])

perc(current, prev) => ((current - prev) / prev) * 100

smooth(value, type, period) =>
    float ma = switch type
        "EMA" => ta.ema(value, period)
        "SMA" => ta.sma(value, period)
        "RMA" => ta.rma(value, period)
        "WMA" => ta.wma(value, period)
        =>
            runtime.error("No matching MA type found.")
            float(na)

getSample(value, samples, type, period) =>
    float ma = switch samples
        0 => value
        1 => smooth(value, type, period)
        2 => smooth(smooth(value, type, period), type, period)
        3 => smooth(smooth(smooth(value, type, period), type, period), type, period)
        4 => smooth(smooth(smooth(smooth(value, type, period), type, period), type, period), type, period)

float takeProfit = input.float(5, "% Take profit", 0.8, 100, step = 0.1)  / 100
float stopLoss = input.float(2, "% Stop Loss", 0.8, 100, step = 0.1) / 100
float magicFast = w2 * ta.cci(close, fastPeriod) + w1 * (ta.rsi(close, fastPeriod) - 50) + w3 * (ta.stoch(close, high, low, fastPeriod) - 50)
float magicSlow = w2 * ta.cci(close, slowPeriod) + w1 * (ta.rsi(close, slowPeriod) - 50) + w3 * (ta.stoch(close, high, low, slowPeriod) - 50)
float sampledMagicFast = getSample(magicFast, oscillographSamplesCount, oscillographMAType, oscillographSamplePeriod)
float sampledMagicSlow = getSample(magicSlow, oscillographSamplesCount, oscillographMAType, oscillographSamplePeriod)
float lastUpperValue = 0
float lastLowerValue = 0

if (magicFast > 0)
    lastUpperValue := math.max(magicFast, magicFast[1])
else 
    lastUpperValue := math.max(0, lastUpperValue[1]) * redunant

    
if (magicFast <= 0)
    lastLowerValue := math.min(magicFast, magicFast[1])
else
    lastLowerValue := math.min(0, lastLowerValue[1]) * redunant

float level1up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) / 4, levelSampleCount, levelType, levelPeriod) + levelOffset
float level2up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) / 2, levelSampleCount, levelType, levelPeriod) + levelOffset
float level3up = getSample( magicFast >= 0 ? magicFast : lastUpperValue, levelSampleCount, levelType, levelPeriod) + levelOffset
float level4up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) * 2, levelSampleCount, levelType, levelPeriod) + levelOffset

float level1low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) / 4, levelSampleCount, levelType, levelPeriod) - levelOffset
float level2low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) / 2, levelSampleCount, levelType, levelPeriod) - levelOffset
float level3low = getSample( magicFast <= 0 ? magicFast : lastLowerValue, levelSampleCount, levelType, levelPeriod) - levelOffset
float level4low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) * 2, levelSampleCount, levelType, levelPeriod) - levelOffset

var transparent = color.new(color.white, 100)
var overbough4Color = color.new(color.red, 75)
var overbough3Color = color.new(color.orange, 75)
var overbough2Color = color.new(color.yellow, 75)

var oversold4Color = color.new(color.teal, 75)
var oversold3Color = color.new(color.blue, 75)
var oversold2Color = color.new(color.aqua, 85)

upperPlotId1 = plot(level1up, 'Upper1', transparent)
upperPlotId2 = plot(level2up, 'Upper2', transparent)
upperPlotId3 = plot(level3up, 'Upper3', transparent)
upperPlotId4 = plot(level4up, 'Upper4', transparent)

fastColor = color.new(color.teal, 60)
slowColor = color.new(color.red, 60)
fastPlotId = plot(sampledMagicFast, 'fast', color = fastColor)
slowPlotId = plot(sampledMagicSlow, 'slow', color = slowColor)

lowerPlotId1 = plot(level1low, 'Lower1', transparent)
lowerPlotId2 = plot(level2low, 'Lower2', transparent)
lowerPlotId3 = plot(level3low, 'Lower3', transparent)
lowerPlotId4 = plot(level4low, 'Lower4', transparent)

fill(upperPlotId4, upperPlotId3, overbough4Color)
fill(upperPlotId3, upperPlotId2, overbough3Color)
fill(upperPlotId2, upperPlotId1, overbough2Color)

fill(lowerPlotId4, lowerPlotId3, oversold4Color)
fill(lowerPlotId3, lowerPlotId2, oversold3Color)
fill(lowerPlotId2, lowerPlotId1, oversold2Color)

upTrend = sampledMagicFast > sampledMagicFast[1]
buySignal = ((upTrend or not trendFilter) and ta.crossunder(sampledMagicSlow, sampledMagicFast)) ? sampledMagicSlow : na
sellSignal = ((not upTrend or not trendFilter) and ta.crossover(sampledMagicSlow, sampledMagicFast)) ? sampledMagicSlow : na
diff = sampledMagicSlow - sampledMagicFast

fill(fastPlotId, slowPlotId, upTrend ? fastColor : slowColor)
plot(buySignal, color = color.aqua, style = plot.style_circles, linewidth = 4)
plot(sellSignal, color = color.red, style = plot.style_circles, linewidth = 4)


// longCondition = upTrend != upTrend[1] and upTrend
long_take_level = strategy.position_avg_price * (1 + takeProfit)
long_stop_level = strategy.position_avg_price * (1 - stopLoss)

short_take_level = strategy.position_avg_price * (1 - takeProfit)
short_stop_level = strategy.position_avg_price * (1 + stopLoss)

strategy.close(id="Long", when=sellSignal, comment = "Exit")
strategy.close(id="Short", when=buySignal, comment = "Exit")

strategy.entry("Long", strategy.long, when=buySignal)
strategy.entry("Short", strategy.short, when=sellSignal)

strategy.exit("Take Profit/ Stop Loss","Long", stop=long_stop_level, limit=long_take_level)
strategy.exit("Take Profit/ Stop Loss","Short", stop=short_stop_level, limit=short_take_level)


// plot(long_stop_level, color=color.red, overlay=true)
// plot(long_take_level, color=color.green)