Chiến lược này thực hiện một cơ chế theo dõi lỗ hổng phần trăm có thể cấu hình được để kiểm soát rủi ro giao dịch. Nó cho phép thiết lập tỷ lệ phần trăm của lỗ hổng cho các vị trí dài và ngắn, liên tục theo dõi giá cao nhất hoặc thấp nhất theo hướng thuận lợi từ giá nhập, để thực hiện dừng động.
Lập luận chính của chiến lược này là:
Chiến lược cho phép tùy chỉnh tỷ lệ phần trăm dừng lỗ, chẳng hạn như đặt nó là 10%. Trong trường hợp dài, nó sẽ tính toán trực tiếp 10% trên mức giá thấp nhất là đường dừng lỗ; trong trường hợp ngắn, tính toán 10% dưới mức giá cao nhất là đường dừng lỗ.
Bằng cách này, đường dừng sẽ liên tục di chuyển theo hướng thuận lợi, theo dõi động các lệnh dừng, tối đa hóa lợi nhuận và kiểm soát rủi ro.
Phản ứng:
Chiến lược này có thể được tối ưu hóa:
Chiến lược này cung cấp một phương pháp theo dõi tỷ lệ dừng hiệu quả, có thể điều chỉnh động đường dừng. Nó có thể bảo vệ tối đa lợi nhuận và kiểm soát rủi ro hiệu quả.
/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// © theCrypster
//@version=4
strategy("Percent Trailing Stop %", overlay=true)
//ENTER SOME SETUP TRADES FOR TSL EXAMPLE
longCondition = crossover(sma(close, 10), sma(close, 20))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 10), sma(close, 20))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
//TRAILING STOP CODE
trailStop = input(title="Long Trailing Stop (%)", type=input.float, minval=0.0, step=0.1, defval=10) * 0.01
longStopPrice = 0.0
shortStopPrice = 0.0
longStopPrice := if strategy.position_size > 0
stopValue = close * (1 - trailStop)
max(stopValue, longStopPrice[1])
else
0
shortStopPrice := if strategy.position_size < 0
stopValue = close * (1 + trailStop)
min(stopValue, shortStopPrice[1])
else
999999
//PLOT TSL LINES
plot(series=strategy.position_size > 0 ? longStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Long Trail Stop", offset=1, title="Long Trail Stop")
plot(series=strategy.position_size < 0 ? shortStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Short Trail Stop", offset=1, title="Short Trail Stop")
//EXIT TRADE @ TSL
if strategy.position_size > 0
strategy.exit(id="Close Long", stop=longStopPrice)
if strategy.position_size < 0
strategy.exit(id="Close Short", stop=shortStopPrice)