Skip to content

Instantly share code, notes, and snippets.

@wuuconix
Created July 10, 2025 06:59
Show Gist options
  • Save wuuconix/fafb95d77d417a6309b63a1e055f5121 to your computer and use it in GitHub Desktop.
Save wuuconix/fafb95d77d417a6309b63a1e055f5121 to your computer and use it in GitHub Desktop.
event
//@version=5
strategy("10分钟高胜率顺势突破策略", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === 参数 ===
length_bb = input.int(20, title="布林带周期")
mult = input.float(2.0, title="布林带倍数")
ma_length = input.int(50, title="均线周期")
use_trend_filter = input.bool(true, title="是否使用均线趋势过滤")
sl_pct = input.float(1.0, title="止损(%)", step=0.1)/100
tp_pct = input.float(2.0, title="止盈(%)", step=0.1)/100
// === 指标计算 ===
basis = ta.sma(close, length_bb)
dev = mult * ta.stdev(close, length_bb)
upper = basis + dev
lower = basis - dev
ma = ta.sma(close, ma_length)
// === 过滤条件 ===
trend_up = close > ma
trend_down = close < ma
// === 多单条件 ===
long_cond = close > upper and (not use_trend_filter or trend_up)
if (long_cond)
strategy.entry("Long", strategy.long)
strategy.exit("TP/SL Long", from_entry="Long", stop=close * (1 - sl_pct), limit=close * (1 + tp_pct))
// === 空单条件 ===
short_cond = close < lower and (not use_trend_filter or trend_down)
if (short_cond)
strategy.entry("Short", strategy.short)
strategy.exit("TP/SL Short", from_entry="Short", stop=close * (1 + sl_pct), limit=close * (1 - tp_pct))
// === 绘制 ===
plot(basis, color=color.orange)
plot(upper, color=color.green)
plot(lower, color=color.red)
plot(ma, color=color.blue)
@wuuconix
Copy link
Author

to calculate win rate:

//@version=5
strategy("10分钟高胜率顺势突破策略 (自动10分钟交割)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// === 参数 ===
length_bb = input.int(20, title="布林带周期")
mult = input.float(2.0, title="布林带倍数")
ma_length = input.int(50, title="均线周期")
use_trend_filter = input.bool(true, title="是否使用均线趋势过滤")
sl_pct = input.float(1.0, title="止损(%)", step=0.1)/100
tp_pct = input.float(2.0, title="止盈(%)", step=0.1)/100
bars_to_close = input.int(10, title="自动交割Bar数 (1分钟线填10 = 10分钟)")

// === 指标计算 ===
basis = ta.sma(close, length_bb)
dev = mult * ta.stdev(close, length_bb)
upper = basis + dev
lower = basis - dev
ma = ta.sma(close, ma_length)

// === 过滤条件 ===
trend_up = close > ma
trend_down = close < ma

// === 记录开仓 bar_index ===
var float long_entry_bar = na
var float short_entry_bar = na

// === 多单条件 ===
long_cond = close > upper and (not use_trend_filter or trend_up)
if (long_cond)
    strategy.entry("Long", strategy.long)
    long_entry_bar := bar_index

// === 空单条件 ===
short_cond = close < lower and (not use_trend_filter or trend_down)
if (short_cond)
    strategy.entry("Short", strategy.short)
    short_entry_bar := bar_index

// === 自动交割条件 ===
long_auto_close = not na(long_entry_bar) and (bar_index - long_entry_bar >= bars_to_close)
if (long_auto_close)
    strategy.close("Long")
    long_entry_bar := na

short_auto_close = not na(short_entry_bar) and (bar_index - short_entry_bar >= bars_to_close)
if (short_auto_close)
    strategy.close("Short")
    short_entry_bar := na

// === 止盈止损 ===
if (strategy.position_size > 0)
    strategy.exit("TP/SL Long", from_entry="Long", stop=close * (1 - sl_pct), limit=close * (1 + tp_pct))

if (strategy.position_size < 0)
    strategy.exit("TP/SL Short", from_entry="Short", stop=close * (1 + sl_pct), limit=close * (1 - tp_pct))

// === 绘制 ===
plot(basis, color=color.orange)
plot(upper, color=color.green)
plot(lower, color=color.red)
plot(ma, color=color.blue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment