이 전략은 전날의 최고 가격에 기초하여 작동하며, 트렌드 추적 유형 전략에 속한다. 전날의 최고 가격을 돌파했을 때 더 많은 포지션을 열고, 하루 동안 여러 번 돌파해도 반복적으로 포지션을 열는다.
LucF 함수를 사용하여 재검토를 피할 때 최신 K선을 스냅하십시오.
새로운 거래일 개시 여부를 판단한다. 그날의 최고 가격 max_today와 최저 가격 min_today를 기록한다.
현재 최고 가격 high와 max_today를 비교하고, max_today를 업데이트하십시오.
현재 최저가격 (low) 과 (min_today) 를 비교하고, (min_today) 를 업데이트하십시오.
지난 거래일 최고 가격과 최저 가격을 그려보세요.
전날의 최고 가격을 돌파한 시점의 개시점을 설정하면 최고 가격에 일정량의 GAP를 추가하여 진입을 늦추거나 앞당길 수 있다.
스톱 손실 비율 sl 및 스톱 스톱 비율 tp 을 설정합니다.
거래가 지난 거래일 최고치를 넘었을 때 포지션을 개설한다.
정지점과 정지점을 설정하세요.
트래킹 스톱을 켜거나, 트래킹 스톱을 시작하기 위한 최소 요구사항을 설정하고, 트래킹 스톱의 거리를 선택할 수 있다.
EMA 상태가 종료되었는지 판단할 수 있습니다.
이것은 비교적 간단한 트렌드 추적 전략으로 다음과 같은 장점이 있습니다.
전략적 신호는 간단하고 명확하며 실행하기 쉽습니다.
지난 거래일 최고 가격의 파격으로 형성된 트렌드 확인 신호를 활용하여, 흔들리는 시장의 소음을 효과적으로 필터링할 수 있다.
GAP 파라미터를 통해 진출의 민감도를 조정할 수 있다.
전체적인 위험은 통제할 수 있고, 손실은 명확하다.
더 많은 수익을 얻기 위해 추적 스톱을 사용하거나 사용하지 않거나 선택할 수 있습니다.
EMA의 판단에 따라, 사다리 접목을 피할 수 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
파격 실패는 손실을 초래할 수 있으며, 합리적인 스톱 손실 가격을 설정할 필요가 있다.
파격 효과는 시장이 트렌드 상태이고, 흔들리는 시장에서 쉽게 잡힐 수 있습니다.
추적 스톱 손실은 잘못 설정되면 너무 민감할 수 있으며, 가격 조그만 조정으로 스톱 손실을 줄일 수 있다.
EMA는 변수 선택이 잘못되면 너무 민감하거나 느리게 판단할 수 있다.
GAP, Stop Loss Amplitude, Tracking Stop Loss Settings 등과 같은 많은 변수들에 대한 관심과 최적화가 필요합니다.
이 전략은 다음의 몇 가지 측면에서 계속 개선될 수 있습니다.
정지 손실을 ATR 또는 동적 손실로 조정합니다.
표준 미비 필터링을 통해 돌파구 효과를 판단하는 것을 추가합니다.
변동성에 기반한 조건들을 추가하여, 진동상태의 무효적 돌파를 방지한다.
EMA 파라미터를 최적화하여 판단을 보다 안정적이고 정확하게 합니다.
시장의 변동에 더 잘 대응할 수 있도록 스톱 손실을 추적하는 파라미터를 최적화하십시오.
다양한 품종의 파라미터를 테스트한다.
포지션 크기를 동적으로 조정하는 메커니즘을 추가하십시오.
이 전략은 전반적으로 간단하고 실용적이며, 전형적인 트렌드 추적 전략에 속하며, 이전 거래일 최고 가격의 돌파구가 트렌드를 추적하기 위한 신호로, 위험 제어는 주로 스톱로스에 의존하여 실현된다. 합리적인 매개 변수 최적화를 통해 전략은 트렌드 상황에서 더 좋은 효과를 얻을 수 있다. 그러나 스톱 전략과 필터 조건을 제어하는 데 주의를 기울여야 하며, 충격적인 상황에서 포착되는 것을 피한다. 이 전략은 트렌드 추적 전략의 기본 틀로 확장 최적화를 할 수 있다.
/*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)