exit 和 filter 没有起到作用,帮我改以下代码//@version=5 strategy("Supertrend RTX001", overlay=true) //…
- User
exit 和 filter 没有起到作用,帮我改以下代码//@version=5 strategy("Supertrend RTX001", overlay=true)
// Input variables atrPeriod = input(10, "ATR Length") factor = input.float(3.0, "Factor", step=0.01) trailingStopPercentage = input.float(1.0, "Trailing Stop Percentage", step=0.1) hullPeriod = input(14, "Hull Moving Average Period")
// Calculate Supertrend [supertrend, direction] = ta.supertrend(factor, atrPeriod)
// Calculate Hull Moving Average hull = ta.hma(close, hullPeriod)
// Plot Supertrend and Hull Moving Average bodyMiddle = plot((open + close) / 2, display=display.none) upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color=color.green, style=plot.style_linebr) downTrend = plot(direction < 0 ? na : supertrend, "Down Trend", color=color.red, style=plot.style_linebr) hullPlot = plot(hull, "Hull Moving Average", color=color.blue)
// Fill body middle fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false) fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
// Entry Rules longCondition = ta.crossover(close, supertrend) and close > hull shortCondition = ta.crossunder(close, supertrend) and close < hull
// Exit Rules longExitCondition = ta.crossunder(close, hull) shortExitCondition = ta.crossover(close, hull)
// Trailing Stop var float longTrailingStopPrice = na var float shortTrailingStopPrice = na
if longCondition strategy.entry("Long", strategy.long) longTrailingStopPrice := close * (1 - trailingStopPercentage / 100)
if shortCondition strategy.entry("Short", strategy.short) shortTrailingStopPrice := close * (1 + trailingStopPercentage / 100)
if longExitCondition strategy.exit("Long Exit", "Long", stop=longTrailingStopPrice)
if shortExitCondition strategy.exit("Short Exit", "Short", stop=shortTrailingStopPrice)
- Assistant
以下是修改过的代码:
pinescript