어제의 높은 유출 추세 전략에 따라

저자:차오장, 날짜: 2023-10-08 14:06:55
태그:

전반적인 설명

이 전략은 전날의 거래의 최고치를 기반으로 트렌드를 따르는 방식으로 작동합니다. 하루 동안 여러 번 브레이크가 발생하더라도 어제의 최고가 깨지면 길어집니다.

전략 논리

  1. LucF 함수를 사용하여 백테스팅에서 룩헤드 편향을 피합니다.

  2. 새로운 거래일이 열렸는지 확인합니다. 하루의 최고가 오늘이고 최저가 오늘입니다.

  3. 현재 최고치를 max_today와 비교하고, 초과되면 max_today를 업데이트합니다.

  4. 현재 최저값을 min_today와 비교하고, 위반될 경우 min_today를 업데이트합니다.

  5. 전날 거래의 높은 수준과 낮은 수준을 나타냅니다.

  6. 전날의 최고점의 돌파점에 입점점을 설정하면 GAP를 추가하여 진입을 앞당기고 지연할 수 있습니다.

  7. 스톱 로스 비율 sl를 설정하고 이익 비율 tp를 취합니다.

  8. 가격이 전날의 최고점을 넘을 때 롱으로 이동합니다.

  9. 스톱 로스 가격을 설정하고 이윤을 취합니다.

  10. 선택적으로 트레일링 스톱 손실을 활성화하고, 활성화 레벨과 오프셋 거리를 설정합니다.

  11. 선택적으로 EMA 크로스오버를 기반으로 거래를 닫습니다.

이점 분석

이 간단한 트렌드를 따르는 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 명확하고 간편한 신호 생성

  2. 전날의 최고점의 돌파는 트렌드 확인을 제공하며, 위프사우를 줄입니다.

  3. GAP 매개 변수는 입력 감도를 조정할 수 있습니다.

  4. 전체 위험은 명확한 스톱 로스로 제어됩니다.

  5. 더 많은 수익을 올리기 위해 트레일링 스톱을 사용할 수 있습니다.

  6. EMA 크로스오버는 하락 추세에 갇히지 않도록 합니다.

위험 분석

주의해야 할 몇 가지 위험 요소가 있습니다.

  1. 실패한 탈출은 손실을 초래할 수 있습니다. 합리적인 스톱 손실이 필요합니다.

  2. 시장의 트렌드를 요구하고, 다양한 조건에서 윙사브가 가능해

  3. 부적절한 후속 정지는 조기에 중단 될 수 있습니다.

  4. 잘못된 EMA 매개 변수 선택은 너무 민감하거나 지연을 일으킬 수 있습니다.

  5. GAP, Stop Loss, Trailing Stop 등과 같은 여러 변수가 조정되어야 합니다.

개선 할 기회

전략을 더 최적화 할 수있는 몇 가지 방법:

  1. ATR 또는 트렌드를 기반으로 동적 스톱 손실을 사용하십시오.

  2. 표준편차를 이용한 유효한 브레이크아웃을 위한 필터를 추가합니다.

  3. 변동성 조건이 추가되어 불안한 시장에서 잘못된 파장을 피합니다.

  4. 더 강력한 신호를 위해 EMA 매개 변수를 최적화하세요.

  5. 시장의 변동성에 맞추기 위해 세밀하게 조정된 후속 스톱 매개 변수

  6. 다른 기기에 대한 매개 변수 견고성 테스트

  7. 동적 위치 크기 메커니즘을 추가합니다.

결론

이 전략은 이전 날의 높은 브레이크오웃을 기반으로 한 전형적인 트렌드 다음 시스템으로 간단하고 실용적입니다. 리스크 관리는 주로 스톱 로스에 의존합니다. 적절한 매개 변수 조정으로 트렌드 조건에서 잘 수행 할 수 있습니다. 그러나 적절한 스톱 로스와 필터가 윙사브를 피하기 위해 필요합니다. 프레임워크는 트렌드 다음 전략의 기초로 더욱 향상 될 수 있습니다.


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

// This source code is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
// © TheSocialCryptoClub

//@version=5

strategy("Yesterday's High", overlay=true, pyramiding = 1,
         initial_capital=10000, 
         default_qty_type=strategy.percent_of_equity, default_qty_value=10,
         slippage=1, backtest_fill_limits_assumption=1, use_bar_magnifier=true,
         commission_type=strategy.commission.percent, commission_value=0.075
         )

// -----------------------------------------------------------------------------
// ROC Filter
// -----------------------------------------------------------------------------

// f_security function by LucF for PineCoders available here: https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/
f_security(_sym, _res, _src, _rep) => request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
high_daily = f_security(syminfo.tickerid, "D", high, false)

roc_enable = input.bool(false, "", group="ROC Filter from CloseD", inline="roc")
roc_threshold = input.float(1, "Treshold", step=0.5, group="ROC Filter from CloseD", inline="roc")

closed = f_security(syminfo.tickerid,"1D",close, false)
roc_filter= roc_enable ? (close-closed)/closed*100  > roc_threshold  : true


// -----------------------------------------------------------------------------
// Trigger Point 
// -----------------------------------------------------------------------------

open_session = ta.change(time('D'))
price_session = ta.valuewhen(open_session, open, 0)
tf_session = timeframe.multiplier <= 60

bgcolor(open_session and tf_session ?color.new(color.blue,80):na, title = "Session")

first_bar = 0
if open_session
    first_bar := bar_index

var max_today = 0.0
var min_today = 0.0
var high_daily1 = 0.0
var low_daily1 = 0.0
var today_open = 0.0

if first_bar
    high_daily1 := max_today
    low_daily1 := min_today
    today_open := open
    max_today := high
    min_today := low


if high >= max_today
    max_today := high

if low < min_today
    min_today := low


same_day  = today_open == today_open[1]

plot( timeframe.multiplier <= 240 and same_day ? high_daily1 : na, color= color.yellow , style=plot.style_linebr, linewidth=1, title='High line')
plot( timeframe.multiplier <= 240 and same_day ? low_daily1 : na, color= #E8000D , style=plot.style_linebr, linewidth=1, title='Low line')

// -----------------------------------------------------------------------------
// Strategy settings 
// -----------------------------------------------------------------------------

Gap = input.float(1,"Gap%", step=0.5, tooltip="Gap di entrata su entry_price -n anticipa entrata, con +n posticipa entrata", group = "Entry")
Gap2 = (high_daily1 * Gap)/100

sl  = input.float(3, "Stop-loss", step= 0.5,  group = "Entry")
tp  = input.float(9, "Take-profit", step= 0.5, group = "Entry")
stop_loss_price = strategy.position_avg_price * (1-sl/100)
take_price = strategy.position_avg_price * (1+tp/100)

sl_trl = input.float(2, "Trailing-stop", step = 0.5, tooltip = "Attiva trailing stop dopo che ha raggiunto...",group = "Trailing Stop Settings")//group = "Trailing Stop Settings")
Atrl= input.float(1, "Offset Trailing", step=0.5,tooltip = "Distanza dal prezzo", group = "Trailing Stop Settings")
stop_trl_price_cond = sl_trl * high/syminfo.mintick/100
stop_trl_price_offset_cond = Atrl * high/syminfo.mintick/100

stop_tick = sl * high/syminfo.mintick/100
profit_tick = tp * high/syminfo.mintick/100

mess_buy = "buy"
mess_sell = "sell"

// -----------------------------------------------------------------------------
// Entry - Exit - Close
// -----------------------------------------------------------------------------

if close < high_daily1 and roc_filter
    strategy.entry("Entry", strategy.long, stop = high_daily1 + (Gap2), alert_message = mess_buy)

ts_n  = input.bool(true, "Trailing-stop", tooltip = "Attiva o disattiva trailing-stop", group = "Trailing Stop Settings")
close_ema = input.bool(false, "Close EMA", tooltip = "Attiva o disattiva chiusura su EMA", group = "Trailing Stop Settings")
len1 = input.int(10, "EMA length", step=1, group = "Trailing Stop Settings")
ma1 = ta.ema(close, len1)

plot(ma1, title='EMA', color=color.new(color.yellow, 0))

if ts_n == true
    strategy.exit("Trailing-Stop","Entry",loss= stop_tick, stop= stop_loss_price, limit= take_price, trail_points = stop_trl_price_cond, trail_offset = stop_trl_price_offset_cond, comment_loss="Stop-Loss!!",comment_profit ="CASH!!", comment_trailing = "TRL-Stop!!", alert_message = mess_sell)
else
    strategy.exit("TP-SL", "Entry",loss= stop_tick, stop=stop_loss_price, limit= take_price, comment_loss= "Stop-loss!!!", comment_profit = "CASH!!", alert_message = mess_sell)

if close_ema == true and ta.crossunder(close,ma1)
    strategy.close("Entry",comment = "Close" , alert_message = mess_sell)



더 많은