-
-
Save wuuconix/8042807072605dd7a8563eebf85cdbc1 to your computer and use it in GitHub Desktop.
1分钟实体突破
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@version=5 | |
| strategy("1分钟实体突破-精确计时版", overlay=true, process_orders_on_close=true) | |
| // === 参数设置 === | |
| length_bb = input.int(20, "布林带周期") | |
| mult = input.float(2.0, "布林带倍数") | |
| ma_length = input.int(50, "均线周期") | |
| use_trend_filter = input.bool(true, "趋势过滤") | |
| trade_duration = input.int(10, "持仓时间(分钟)", minval=1) | |
| // === 指标计算 === | |
| 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) | |
| // === 信号条件 === | |
| // 实体突破定义:收盘价突破(忽略上下影线) | |
| body_break_upper = close > upper and open > upper[1] // 当前实体完全突破上轨 | |
| body_break_lower = close < lower and open < lower[1] // 当前实体完全突破下轨 | |
| trend_up = close > ma | |
| trend_down = close < ma | |
| // === 交易逻辑 === | |
| var int entry_bar_index = na // 记录入场K线索引 | |
| var int entry_time = na // 精确入场时间戳 | |
| // 多单条件(K线收盘后检查) | |
| if (body_break_upper and (not use_trend_filter or trend_up) and strategy.position_size <= 0) | |
| strategy.entry("Long", strategy.long) | |
| alert("Long " + str.tostring(close), alert.freq_once_per_bar_close) | |
| entry_bar_index := bar_index | |
| entry_time := time | |
| // 空单条件(K线收盘后检查) | |
| if (body_break_lower and (not use_trend_filter or trend_down) and strategy.position_size >= 0) | |
| strategy.entry("Short", strategy.short) | |
| alert("Short " + str.tostring(close), alert.freq_once_per_bar_close) | |
| entry_bar_index := bar_index | |
| entry_time := time | |
| // === 平仓逻辑 === | |
| // 方式1:精确时间控制(推荐) | |
| // if (not na(entry_time) and (time - entry_time) >= trade_duration*60*1000) | |
| // strategy.close_all() | |
| // entry_time := na | |
| // entry_bar_index := na | |
| // 方式2:K线数量控制(备选) | |
| // if (not na(entry_bar_index) and (bar_index - entry_bar_index) >= trade_duration | |
| // strategy.close_all() | |
| // entry_bar_index := na | |
| // === 可视化 === | |
| plot(basis, "中线", color=color.orange) | |
| plot(upper, "上轨", color=color.green) | |
| plot(lower, "下轨", color=color.red) | |
| plot(ma, "均线", color=color.blue) | |
| // 标记入场点 | |
| // plotshape(body_break_upper and strategy.position_size <= 0, "↑突破", shape.triangleup, location.belowbar, color.green, size=size.small) | |
| // plotshape(body_break_lower and strategy.position_size >= 0, "↓突破", shape.triangledown, location.abovebar, color.red, size=size.small) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
胜率统计优化