
이 전략은 평평한 이동 평균과 평균 실제 가격 범위를 사용하여 두 개의 스톱 손실 가격을 계산하고, 스톱 손실 가격을 돌파 할 때 역으로 포지션을 열고, 트렌드 추적 스톱 손실을 실현합니다. 이 전략은 높은 변동성있는 디지털 통화 거래에 적합하며, 수익을 효과적으로 고정하여 손실을 확대하지 않습니다.
이 전략은 ATR을 계산하여 합리적인 중지 범위를 결정하고, RMA 방법과 결합하여 중지 라인을 평형화하여 작은 가격 흔들림에 의해 중지 손실이 유발되는 것을 피합니다. 트렌드가 전환되면 신호를 신속하게 인식하여 역행 가격으로 중지 라인을 뚫는 방식으로 위치를 구축합니다.
ATR 주기를 적절히 줄이거나 ATR 배수를 줄임으로써 손실을 줄일 수 있습니다. 또는 다른 필터 조건을 추가하여 불필요한 입장을 줄일 수 있습니다. 시장의 급격한 변화에 대응하기 위해 실제 레버리지 및 입장의 크기를 제어하십시오.
다른 오실레이터 지표와 통합하여 트렌드 방향을 판단하고, 불안정한 시점에 무효 입장을 피한다. 입구 논리를 최적화하여, 스톱 라인을 뚫고 가격이 일정 범위에서 계속 작동할 수 있도록 한다. 더 많은 수익을 잠금하기 위해 모바일 스톱 라인을 추가한다. 기계 학습 훈련을 사용하여 더 나은 스톱 함수를 사용합니다.
이 전략은 평평한 이동 평균 스톱 라인을 계산하여, 고 변동성 디지털 통화 시장에 대한 동적 추적 스톱을 구현하여, 위험을 효과적으로 제어할 수 있습니다. 전략의 매개 변수는 안정적이며, 자동화 거래에 적합합니다. 이를 기반으로 다차원 최적화를 수행하여 더 많은 지표와 알고리즘과 결합하여 효과를 높일 수 있습니다.
/*backtest
start: 2023-12-31 00:00:00
end: 2024-01-30 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//
// 作品: [LunaOwl] 超級趨勢2
//
////////////////////////////////
// ~~!!*(๑╹◡╹๑) ** //
// 製作: @LunaOwl 彭彭 //
// 第1版: 2019年05月29日 //
// 第2版: 2019年06月12日 //
// 微調: 2019年10月26日 //
// 第3版: 2020年02月12日 //
////////////////////////////////
//
//
//超級趨勢的缺點:
//--1.止損距離可能相當大, 請自己調整週期
//--2.市場沒有存在明顯趨勢的時候表現不佳
//
//超級趨勢的優點:
//--1.具有可以參考的移動止損線, 適合新手
//--2.市場存在明顯趨勢的時候表現會很不錯
//
//使用須知:
//--1.每筆交易都需要下移動止損單, 絕對要下
//--2.中途被針掃出場時不要急著再進去
//--3.當錯失機會不要追高追低, 等待下次機會
//--4.實質槓桿比率不要太高, 不要輕忽市場變化
//--5.訂單進出場都建議分成五份、十份區間掛單
//--6.不要妄圖賺到市場上的每一分錢
//
//稍做更新:
//--1.平均真實區間利用了遞迴均線減少雜訊
//--2.針對高波動率的小幣市場,中期順勢策略應該以減少雜訊為重點
//--3.研究國外交易策略後,它們常用平滑因子過濾隨機走勢
//--4.績效上和其它平均法比較並沒有突出,但優點是參數變動穩定性
//--5.我選擇四小時線回測小幣市場,並且選擇經歷過牛熊市的以太坊
//==設定研究==//
//study(title = "[LunaOwl] 超級趨勢2", shorttitle = "[LunaOwl] 超級趨勢2", overlay = true)
//==設定策略==//
strategy(
title = "[LunaOwl] 超級趨勢2",
shorttitle = "[LunaOwl] 超級趨勢2",
format = format.inherit,
overlay = true,
calc_on_order_fills = true,
calc_on_every_tick = false,
pyramiding = 0,
currency = currency.USD,
initial_capital = 10000,
slippage = 10,
default_qty_value = 100,
default_qty_type = strategy.percent_of_equity,
commission_value = 0.1
)
//==設定參數==//
src = input(close, "數據來源")
length = input(
title = "ATR 周期",
type = input.integer,
minval = 1,
maxval = 4,
defval = 1
)
//可以設定的精度為小數點後三位
mult = input(
title = "ATR 乘數",
type = input.float,
minval = 1.000,
maxval = 9.000,
defval = 2.618,
step = 0.001
)
atr = mult * atr(length)
atr_rma = rma(atr, 14) //平均真實區間添加遞回均線
//==算法邏輯==//
LongStop = hl2 - atr_rma
LongStopPrev = nz(LongStop[1], LongStop)
LongStop := close[1] > LongStopPrev ? max(LongStop, LongStopPrev) : LongStop
ShortStop = hl2 + atr_rma
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
LongStop_data = dir == 1 ? LongStop : na
ShortStop_data = dir == 1 ? na : ShortStop
LongMark = dir == 1 and dir[1] == -1 ? LongStop : na
ShortMark = dir == -1 and dir[1] == 1 ? ShortStop : na
LongColor = #0D47A1 //普魯士藍
ShortColor = #B71C1C //酒紅色
//==設置止損線==//
plot(LongStop_data,
title = "移動止損線",
style = plot.style_linebr,
color = LongColor,
linewidth = 1
)
plot(ShortStop_data,
title = "移動止損線",
style = plot.style_linebr,
color = ShortColor,
linewidth = 1
)
//==設定K線顏色==//
barcolor(dir == 1 ? LongColor : ShortColor, title = "K線顏色")
//==設定快訊通知==//
alertcondition(LongMark,
title = "多頭標記",
message = "多頭標記: 行情可能出現潛在變化,請注意個人的對沖或空頭部位,留意風險。")
alertcondition(ShortMark,
title = "空頭標記",
message = "空頭標記: 行情可能出現潛在變化,請注意個人的現貨或多單持倉狀況,留意風險。")
// - 設定日期範圍 - //
test_Year = input(2017, title = "設定範圍:年", minval = 1, maxval = 2140)
test_Month = input( 11, title = "_____月", minval = 1, maxval = 12)
test_Day = input( 01, title = "_____日", minval = 1, maxval = 31)
test_Period = timestamp( test_Year, test_Month, test_Day, 0, 0)
// - 買賣條件 - //
Long = src > LongStop_data
strategy.entry("多頭進場", strategy.long, when = Long)
strategy.close("多頭出場", when = Long)
Short = src < ShortStop_data
strategy.entry("空頭進場", strategy.short, when = Short)
strategy.close("空頭回補", when = Short)