
Chiến lược dừng chân theo dõi động là một chiến lược giao dịch định lượng sử dụng cơ chế dừng chân theo dõi. Chiến lược này dựa trên lý thuyết theo dõi xu hướng, thiết lập đường dừng chân theo dõi, thực hiện xác nhận dừng chân và điều chỉnh dừng chân theo dõi.
Cốt lõi của chiến lược dừng theo dõi động là đặt ba tham số quan trọng: khoảng cách dừng ban đầu, khoảng cách dừng theo dõi và khoảng cách kích hoạt dừng theo dõi. Khi tín hiệu mua được kích hoạt, giá dừng ban đầu được tính toán dựa trên giá mua và khoảng cách dừng ban đầu được thiết lập.
Chiến lược này đồng thời có mức dừng thấp, cho dù có bắt đầu theo dõi dừng chân hay không, nếu giá giảm xuống mức dừng chân thấp, nó sẽ dừng ngay. Đường dừng thấp được sử dụng để phòng ngừa sự kiện đột ngột. Vì vậy, chiến lược dừng chân theo dõi động cho phép đường dừng tự động theo dõi xu hướng thuận lợi bằng cách sử dụng cơ chế dừng chân động theo dạng hai dòng lên xuống, đồng thời ngăn chặn tổn thất quá lớn.
Theo dõi lỗ hổng và khóa lợi nhuận, tránh cho phép trả lại quá nhiều cơ hội.
Sử dụng cấu trúc dừng lỗ hai dòng lên xuống, đảm bảo dây dừng lỗ có thể theo dõi kịp thời và ngăn chặn tổn thất quá lớn.
Sử dụng cơ chế phán đoán liên tục để điều chỉnh dừng lỗ, hoạt động đơn giản, dễ thực hiện.
Có thể điều chỉnh các tham số để tối ưu hóa hiệu quả dừng lỗ theo đặc điểm của thị trường và từng cổ phiếu.
Không cần phải dự đoán thị trường, bạn có thể làm theo xu hướng.
Cài đặt tham số không đúng có thể dẫn đến việc dừng lỗ quá thoải mái hoặc quá căng thẳng. Nếu quá thoải mái, nó sẽ không dừng lỗ hiệu quả, và nếu quá căng thẳng, nó sẽ dễ bị ảnh hưởng bởi biến động giá bình thường.
Các sự kiện bất ngờ gây ra giá tăng vọt, có thể dẫn đến việc dừng lỗ không có hiệu lực, nên được kết hợp với các biện pháp phòng ngừa khác.
Chi phí giao dịch và điểm trượt có thể ảnh hưởng đến giá bán thực tế sau khi triggered.
Khả năng thích ứng không tốt, hiệu quả không tốt trong các giai đoạn nhất định, chẳng hạn như trong khu vực động đất.
Phản ứng:
Việc điều chỉnh theo dõi đường dừng để theo dõi sự thay đổi phần trăm cho phép theo dõi tốt hơn sự thay đổi giá cổ phiếu ở các mức giá khác nhau.
Thêm chỉ số tỷ lệ dao động, tạm dừng theo dõi dừng khi có biến động lớn, tránh biến động bình thường gây ra dừng.
Sử dụng phương pháp học máy để tự động tối ưu hóa các tham số. Các mẫu đào tạo chọn tỷ lệ lợi nhuận của các tham số trong khoảng thời gian gần đây nhất.
Tăng khả năng đánh giá các điều kiện mở vị trí, kết hợp các chỉ số như xu hướng, hỗ trợ và kháng cự, tránh mở vị trí trong tình trạng biến động.
Chiến lược dừng theo dõi động thông qua cơ chế dừng hai dòng, thiết lập đường dừng theo dõi, thực hiện xác nhận dừng và điều chỉnh dừng theo dõi. Có thể tự động điều chỉnh khoảng cách dừng theo biến đổi giá, được sử dụng để khóa lợi nhuận, giảm sự quay trở lại và kiểm soát tổn thất. Chiến lược này hoạt động đơn giản, dễ thực hiện, có thể tối ưu hóa tham số theo tình hình thị trường, hiệu quả sử dụng tốt hơn với các chiến lược khác.
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-17 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Thumpyr
//@version=5
/////////////////////////////////////////////////////////////////////////////////////////////
// Comment out Strategy Line and remove // from Indicator line to turn into Indicator //////
// Do same for alertConidction at bottom //////
/////////////////////////////////////////////////////////////////////////////////////////////
strategy("PCT Trailing Stoploss-Strategy", shorttitle="PCT Trailing Stoploss- Strategy", overlay=true)
//indicator(title="PCT Trailing Stoploss- Indicator", shorttitle="PCT Trailing Stoploss - Indicator", timeframe="", timeframe_gaps=true, overlay=true)//
sellLow=input.float(.035, minval=0, title="Stop Loss Loss: 1% = .01", group="Sell Settings")
trailStopArm=input.float(.0065, minval=0, title="Trailing Stop Arm: 1%=.01", group="Sell Settings")
trailStopPct=input.float(.003, minval=0, title="Trailing Stop Trigger: 1%=.01 ", group="Sell Settings")
/////////////////////////////////////////////////
// Indicators //
/////////////////////////////////////////////////
ema1Len = input.int(14, minval=1, title=" ema 1 Length", group="Trend Line Settings")
ema1Src = input(close, title="ema 1 Source", group="Trend Line Settings")
ema1 = ta.ema(ema1Src, ema1Len)
plot(ema1, title="EMA", color=color.blue)
ema2Len = input.int(22, minval=1, title=" ema 2 Length", group="Trend Line Settings")
ema2Src = input(close, title="ema 2 Source", group="Trend Line Settings")
ema2 = ta.ema(ema2Src, ema2Len)
plot(ema2, title="EMA", color=color.orange)
ema3Len = input.int(200, minval=1, title=" ema 3 Length", group="Trend Line Settings")
ema3Src = input(close, title="ema 2 Source", group="Trend Line Settings")
ema3 = ta.ema(ema3Src, ema3Len)
plot(ema3, title="EMA", color=color.gray)
/////////////////////////////
//// Buy Conditions ////
/////////////////////////////
alertBuy = ta.crossover(ema1,ema2) and close>ema3
////////////////////////////////////////////////////////////////////
//// Filter redundant Buy Signals if Sell has not happened ////
////////////////////////////////////////////////////////////////////
var lastsignal = 0
showAlertBuy = 0
if(alertBuy and lastsignal !=1)
showAlertBuy := 1
lastsignal := 1
buyAlert= showAlertBuy > 0
//////////////////////////////////////////////////////////////////
//// Track Conditions at buy Signal ////
//////////////////////////////////////////////////////////////////
alertBuyValue = ta.valuewhen(buyAlert, close,0)
alertSellValueLow = alertBuyValue - (alertBuyValue*sellLow)
////////////////////////////////////////////////////////////
///// Trailing Stop /////
////////////////////////////////////////////////////////////
var TSLActive=0 //Check to see if TSL has been activated
var TSLTriggerValue=0.0 //Initial and climbing value of TSL
var TSLStop = 0.0 //Sell Trigger
var TSLRunning =0 //Continuously check each bar to raise TSL or not
// Check if a Buy has been triggered and set initial value for TSL //
if buyAlert
TSLTriggerValue := alertBuyValue+(alertBuyValue*trailStopArm)
TSLActive := 0
TSLRunning :=1
TSLStop := TSLTriggerValue - (TSLTriggerValue*trailStopPct)
// Check that Buy has triggered and if Close has reached initial TSL//
// Keeps from setting Sell Signal before TSL has been armed w/TSLActive//
beginTrail=TSLRunning==1 and TSLActive==0 and close>alertBuyValue+(alertBuyValue*trailStopArm) and ta.crossover(close,TSLTriggerValue)
if beginTrail
TSLTriggerValue :=close
TSLActive :=1
TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)
// Continuously check if TSL needs to increase and set new value //
runTrail= TSLActive==1 and (ta.crossover(close,TSLTriggerValue) or close>=TSLTriggerValue)
if runTrail
TSLTriggerValue :=close
TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)
// Verify that TSL is active and trigger when close cross below TSL Stop//
TSL=TSLActive==1 and (ta.crossunder(close,TSLStop) or (close[1]>TSLStop and close<TSLStop))
// Plot point of inital arming of TSL//
TSLTrigger=TSLActive==1 and TSLActive[1]==0
plotshape(TSLTrigger, title='TSL Armed', location=location.abovebar, color=color.new(color.blue, 0), size=size.small, style=shape.cross, text='TSL Armed')
////////////////////////////////////////////////////////////
// Plots used for troubleshooting and verification of TSL //
////////////////////////////////////////////////////////////
//plot(TSLActive,"Trailing Stop", color=#f48fb1)
//plot(TSLRunning,"Trailing Stop", color=#f48fb1)
//plot(TSLTriggerValue,"Trailing Stop Trigger", color.new(color=#ec407a, transp = TSLRunning==1 ? 0 : 100))
//plot(TSLStop,"Trailing Stop", color.new(color=#f48fb1, transp = TSLRunning==1 ? 0 : 100))//
////////////////////////////////////////////////////////////
///// Sell Conditions ///////
////////////////////////////////////////////////////////////
Sell1 = TSL
Sell2 = ta.crossunder(close,alertSellValueLow)
alertSell= Sell1 or Sell2
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//// Remove Redundant Signals ////
////////////////////////////////////////////////////////////
showAlertSell = 0
if(alertSell and lastsignal != -1)
showAlertSell := 1
lastsignal := -1
sellAlert= showAlertSell > 0
if sellAlert
TSLActive :=0
TSLRunning :=0
/////////////////////////////////////////
// Plot Buy and Sell Shapes on Chart //
/////////////////////////////////////////
plotshape(buyAlert, title='Buy', location=location.belowbar, color=color.new(color.green, 0), size=size.small, style=shape.triangleup, text='Buy')
plotshape(sellAlert, title='Sell', location=location.abovebar, color=color.new(color.red, 0), size=size.small, style=shape.triangledown, text='Sell')
/////////////////////////////////////////////////////////////////////////////////////////////
// Remove // to setup for Indicator //
/////////////////////////////////////////////////////////////////////////////////////////////
//Alerts
//alertcondition(title='Buy Alert', condition=buyAlert, message='Buy Conditions are Met')
//alertcondition(title='Sell Alert', condition=sellAlert, message='Sell Conditions are Met')
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//// Comment out this section if setup as Indicator ////
////////////////////////////////////////////////////////////
longCondition = buyAlert
if (longCondition)
strategy.entry("Buy", strategy.long)
alert(message='Buy', freq=alert.freq_once_per_bar_close)
shortCondition = sellAlert
if (shortCondition)
strategy.close_all(sellAlert,"Sell")
alert(message='Sell', freq=alert.freq_once_per_bar_close)
/////////////////////////////////////////////////////////////