
이 전략은 이동 평균선과 동적 포트 라인을 기반으로, 다중 공평 양방향 거래를 구현한다. 그것은 가격이 상하의 포트 라인을 깨는 것을 추적하여 포지션을 구축하고, 가격이 기준 평균선 아래로 다시 떨어지면 평소한다. 이 전략은 트렌드가 더 명백한 주식과 디지털 통화에 적용된다.
우선, 이 전략은 사용자가 선택한 평균선 유형과 길이를 기반으로 기준 평균선을 계산한다. 일반적인 평균선은 SMA, EMA 등이 있다.
다음으로, 사용자가 설정한 퍼센티지 파라미터에 따라 상하의 거래 라인을 계산한다. 예를 들어 5%는 가격 변동이 ALLOWED_BRACKET105%일 때 거래를 설정한다. 거래 라인의 수는 사용자 정의 할 수 있다.
입시 규칙에 따르면, 하계 라인업을 뚫면 더 많이 하고, 상계 라인업을 뚫면 공백하게 한다. 규칙은 매우 간단하고 명확하다.
마지막으로, 가격이 다시 기준 평균선 아래로 떨어지면 모든 포지션을 평행합니다. 이것은 추세를 추적하는 탈퇴 지점입니다.
주의할 점은 이 전략이 분장 포지션을 구현한다는 점입니다. 여러 개의 포트라인이 있다면, 비례적으로 자금을 분배합니다. 이것은 일방적인 게임의 위험을 피합니다.
이 전략의 가장 큰 장점은 다음과 같습니다.
트렌드를 자동으로 추적하는 기능이 구현되어 있습니다. 평균선을 사용하여 트렌드 방향을 판단하는 것은 매우 일반적이므로, 이것은 효과적인 방법입니다.
포괄 라인을 사용하여 일부 소음을 필터링하여 너무 민감한 문제를 방지하고 불필요한 거래를 유발합니다. 합리적인 매개 변수 설치는 전략의 수익성을 크게 최적화 할 수 있습니다.
분할 포지션 구축은 전략적 탄력성을 증가시킨다. 일방적인 돌파구가 실패하더라도, 다른 방향은 계속 잘 작동할 수 있다. 이것은 전반적인 위험/수익 비율을 최적화한다.
사용자 정의 평균선과 포괄선 수를 허용한다. 이것은 정책의 유연성을 증가시키고, 사용자는 다른 품종에 대해 파라미터를 조정할 수 있다.
이 전략의 주요 위험은 다음과 같습니다.
평행선 시스템은 골든 크로스 타입 신호에 민감하지 않다. 명확한 추세가 없다면 이 전략은 일부 기회를 놓칠 수 있다.
포괄망선이 너무 넓게 설정되어 거래 횟수와 슬라이드 포인트 위험을 증가시킬 수 있다. 라인이 너무 좁게 설계되어 큰 경우를 놓칠 수도 있다. 균형점을 찾는 데 충분한 테스트가 필요하다.
위기 상황에서는 이 전략이 더 많이 적용될 가능성이 있다. 따라서 품종 선택은 트렌드가 뚜렷한 품종이 좋다.
분할 포지션은 매출을 제한합니다. 단편적인 위험을 감수하기만 한다면, 추가적인 최적화가 필요합니다.
이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.
다른 지표들을 대체하여 창고 건설과 창고 을 결정한다. 예를 들어 KDJ 지표 등이다. 또는 여러 지표들을 결합하여 필터링 조건을 설정한다.
스톱 스톱 로직을 추가한다. 이것은 수익의 일부를 잠금하고, 적극적으로 위험의 일부를 회피한다.
최적화 파라미터는 최적의 평균선과 포괄선 조합을 찾는다. 이것은 충분한 회견과 최적화와 최적의 파라미터 쌍을 찾는다.
딥러닝과 같은 기술과 결합하여 지능적인 매개 변수 최적화를 구현한다. 시간이 지남에 따라 계속 학습하고 매개 변수 설정을 업데이트한다.
품종과 시장의 차이를 고려하여, 다양한 거래 환경에 적응하는 여러 개의 매개 변수를 설정하십시오. 이것은 전략의 안정성을 크게 향상시킬 것입니다.
이 동적 패키지 네트워크 일률 전략은 전반적으로 트렌드 거래에 매우 적합하다. 그것은 간단하고 효율적이며 이해하기 쉽고 최적화된다. 기본 전략으로서, 그것은 매우 강한 유연성과 확장성을 가지고 있다. 다른 더 복잡한 시스템과의 통합을 통해 전체적인 수익과 위험 조정 지표를 더욱 최적화 할 수 있다. 따라서 양적 거래의 매우 좋은 기초가 될 수 있다.
/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Envelope Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, pyramiding = 5, commission_type=strategy.commission.percent, commission_value=0.0)
// CopyRight Crypto Robot
src = input(ohlc4, title="Source", group = "Base MA")
ma_base_window = input.int(5, "Base Mooving Average Window", step = 1, group = "Base MA")
ma_type = input.string(defval='1. SMA', options=['1. SMA', '2. PCMA', '3. EMA', '4. WMA', '5. DEMA', '6. ZLEMA', '7. HMA'], title='MA Type', group = "Base MA")
envelope_1_pct = input.float(0.05, "Envelope 1", step = 0.01, group = "Envelopes")
envelope_2_pct = input.float(0.10, "Envelope 2", step = 0.01, group = "Envelopes")
envelope_3_pct = input.float(0.15, "Envelope 3", step = 0.01, group = "Envelopes")
envelope_4_pct = input.float(0.0, "Envelope 4", step = 0.01, group = "Envelopes")
envelope_5_pct = input.float(0.0, "Envelope 5", step = 0.01, group = "Envelopes")
use_longs = input.bool(true, 'Long Positions')
use_short = input.bool(true, 'Short Positions')
total_envelope = 0
if envelope_1_pct > 0
total_envelope := total_envelope + 1
if envelope_2_pct > 0
total_envelope := total_envelope + 1
if envelope_3_pct > 0
total_envelope := total_envelope + 1
if envelope_4_pct > 0
total_envelope := total_envelope + 1
if envelope_5_pct > 0
total_envelope := total_envelope + 1
// ---------------------------------------------
// -------------- INDICATORS -------------------
ma_function(MA_type, MA_length) =>
zlema_lag = (MA_length - 1) / 2
hma_src = MA_type == '7. HMA' ? 2 * ta.wma(src, math.floor(MA_length / 2)) - ta.wma(src, MA_length) : na
MA_type == '1. SMA' ? ta.sma(src, MA_length) : MA_type == '2. PCMA' ? (ta.highest(high, MA_length) + ta.lowest(low, MA_length)) / 2 : MA_type == '3. EMA' ? ta.ema(src, MA_length) : MA_type == '4. WMA' ? ta.wma(src, MA_length) : MA_type == '5. DEMA' ? 2 * ta.ema(src, MA_length) - ta.ema(ta.ema(src, MA_length), MA_length) : MA_type == '6. ZLEMA' ? ta.ema(src + src - src[zlema_lag], MA_length) : MA_type == '7. HMA' ? ta.wma(hma_src, math.floor(math.sqrt(MA_length))) : na
ma_base = ma_function(ma_type, ma_base_window)
ma_high_1 = envelope_1_pct > 0 ? ma_base * (1 + envelope_1_pct) : na
ma_high_2 = envelope_2_pct > 0 ? ma_base * (1 + envelope_2_pct) : na
ma_high_3 = envelope_3_pct > 0 ? ma_base * (1 + envelope_3_pct) : na
ma_high_4 = envelope_4_pct > 0 ? ma_base * (1 + envelope_4_pct) : na
ma_high_5 = envelope_5_pct > 0 ? ma_base * (1 + envelope_5_pct) : na
ma_low_1 = envelope_1_pct > 0 ? ma_base * (1 - envelope_1_pct) : na
ma_low_2 = envelope_2_pct > 0 ? ma_base * (1 - envelope_2_pct) : na
ma_low_3 = envelope_3_pct > 0 ? ma_base * (1 - envelope_3_pct) : na
ma_low_4 = envelope_4_pct > 0 ? ma_base * (1 - envelope_4_pct) : na
ma_low_5 = envelope_5_pct > 0 ? ma_base * (1 - envelope_5_pct) : na
// ---------------------------------------------
// --------------- STRATEGY --------------------
if use_longs
if envelope_1_pct > 0 and strategy.opentrades < 1
strategy.entry('long 1', strategy.long, limit=ma_low_1, qty=(strategy.equity / ma_low_1) * (1 / total_envelope))
if envelope_2_pct > 0 and strategy.opentrades < 2
strategy.entry('long 2', strategy.long, limit=ma_low_2, qty=(strategy.equity / ma_low_2) * (1 / total_envelope))
if envelope_3_pct > 0 and strategy.opentrades < 3
strategy.entry('long 3', strategy.long, limit=ma_low_3, qty=(strategy.equity / ma_low_3) * (1 / total_envelope))
if envelope_4_pct > 0 and strategy.opentrades < 4
strategy.entry('long 4', strategy.long, limit=ma_low_4, qty=(strategy.equity / ma_low_4) * (1 / total_envelope))
if envelope_5_pct > 0 and strategy.opentrades < 5
strategy.entry('long 5', strategy.long, limit=ma_low_5, qty=(strategy.equity / ma_low_5) * (1 / total_envelope))
if use_short
if envelope_1_pct > 0 and strategy.opentrades < 1
strategy.entry('short 1', strategy.short, limit=ma_high_1, qty=(strategy.equity / ma_high_1) * (1 / total_envelope))
if envelope_2_pct > 0 and strategy.opentrades < 2
strategy.entry('short 2', strategy.short, limit=ma_high_2, qty=(strategy.equity / ma_high_2) * (1 / total_envelope))
if envelope_3_pct > 0 and strategy.opentrades < 3
strategy.entry('short 3', strategy.short, limit=ma_high_3, qty=(strategy.equity / ma_high_3) * (1 / total_envelope))
if envelope_4_pct > 0 and strategy.opentrades < 4
strategy.entry('short 4', strategy.short, limit=ma_high_4, qty=(strategy.equity / ma_high_4) * (1 / total_envelope))
if envelope_5_pct > 0 and strategy.opentrades < 5
strategy.entry('short 5', strategy.short, limit=ma_high_5, qty=(strategy.equity / ma_high_5) * (1 / total_envelope))
strategy.exit('close', limit=ma_base)
// ---------------------------------------------
// ------------------ PLOT ---------------------
ma_base_plot = plot(ma_base, title = "Base MA", color = color.orange, linewidth = 3, offset = 1)
ma_high_1_plot = plot(ma_high_1, title = "MA high 1", color = color.red, offset = 1)
ma_high_2_plot = plot(ma_high_2, title = "MA high 2", color = color.red, offset = 1)
ma_high_3_plot = plot(ma_high_3, title = "MA high 3", color = color.red, offset = 1)
ma_high_4_plot = plot(ma_high_4, title = "MA high 4", color = color.red, offset = 1)
ma_high_5_plot = plot(ma_high_5, title = "MA high 5", color = color.red, offset = 1)
ma_low_1_plot = plot(ma_low_1, title = "MA low 1", color = color.green, offset = 1)
ma_low_2_plot = plot(ma_low_2, title = "MA low 2", color = color.green, offset = 1)
ma_low_3_plot = plot(ma_low_3, title = "MA low 3", color = color.green, offset = 1)
ma_low_4_plot = plot(ma_low_4, title = "MA low 4", color = color.green, offset = 1)
ma_low_5_plot = plot(ma_low_5, title = "MA low 5", color = color.green, offset = 1)
plot(ohlc4, color=color.purple)
// use_period = input.bool(false, "Période spécifique ?", group="periode")
// startDate = input.time(timestamp("01 Jan 2020"), "Date de début", group="periode")
// endDate = input.time(timestamp("01 Jan 2025"), "Date de fin", group="periode")
//------------------------------------------
//-------------Indicateurs------------------
// inDateRange = use_period ? ((time >= startDate) and (time < endDate)) : true
// //--------------Backtest-------------------
// strategy_pnl = strategy.netprofit + strategy.openprofit
// bnh_strategy_pnl_pcnt = (strategy_pnl / strategy.initial_capital) * 100
// float bnh_start_bar = na
// bnh_start_bar := na(bnh_start_bar[1]) or inDateRange != true? close : bnh_start_bar[1]
// float bnl_buy_hold_equity = na
// bnl_buy_hold_equity := inDateRange == true ? ((close - bnh_start_bar)/bnh_start_bar) * 100 : bnl_buy_hold_equity[1]
// bnh_vs_diff = bnh_strategy_pnl_pcnt - bnl_buy_hold_equity
// bnh_diff_color = bnh_vs_diff > 0 ? color.new(color.green, inDateRange ? 60 : 100) : color.new(color.red, inDateRange ? 60 : 100)
// var Table = table.new(position.top_right, columns = 2, rows = 4, border_width = 1, bgcolor = color.black, border_color = color.gray)
// table.cell(table_id = Table, column = 0, row = 0, text_color=(bnh_strategy_pnl_pcnt>bnl_buy_hold_equity)?color.gray:color.green, text_size = size.normal, text = "Buy & hold profit")
// table.cell(table_id = Table, column = 1, row = 0, text_color=(bnh_strategy_pnl_pcnt>bnl_buy_hold_equity)?color.gray:color.green, text_size = size.normal, text = str.tostring(bnl_buy_hold_equity, '#.##') + ' %')
// table.cell(table_id = Table, column = 0, row = 1, text_color=(bnh_strategy_pnl_pcnt<bnl_buy_hold_equity)?color.gray:color.green, text_size = size.normal, text = "Strategy profit")
// table.cell(table_id = Table, column = 1, row = 1, text_color=(bnh_strategy_pnl_pcnt<bnl_buy_hold_equity)?color.gray:color.green, text_size = size.normal, text = str.tostring(bnh_strategy_pnl_pcnt, '#.##') + ' %')
// table.cell(table_id = Table, column = 0, row = 2, text_color=color.yellow, text_size = size.normal, text = "Date de début")
// table.cell(table_id = Table, column = 1, row = 2, text_color=color.yellow, text_size = size.normal, text = str.format("{0,date,dd-MM-YYYY}",strategy.closedtrades.entry_time(1)))