silver 空仓

本文分享了一次成功的交易经历,通过合理操作空单,弥补了之前的多单亏损,虽然当前仍处于轻微亏损状态,但作者保持乐观心态,坚信未来将逐步实现盈利目标。

比较成功的空单,赢回了上次多单的亏损,目前整体还是亏 5000 多,保持好状态,慢慢回报变盈利~

平掉所有(3手)空单,落袋为安!


//@version=6 strategy("复合波段交易策略[优化版]", overlay=true, pyramiding=1, initial_capital=100000, currency=currency.USD, calc_on_every_tick=false) // 防止重复计算 // ======= 输入参数模块 ======= fastLength = input.int(10, "短期均线周期", minval=1, group="趋势参数") slowLength = input.int(20, "长期均线周期", minval=1, group="趋势参数") rsiLength = input.int(14, "RSI周期", minval=1, maxval=100, group="震荡指标") bbLength = input.int(20, "布林带周期", minval=1, group="波动通道") mult = input.float(2.0, "标准差倍数", step=0.1, minval=1.5, maxval=3.0, group="波动通道") stopLossPct = input.float(1.5, "止损比例 (%)", step=0.1, minval=0.5, maxval=5)/100 takeProfitPct = input.float(3.5, "止盈比例 (%)", step=0.1, minval=1.0, maxval=10)/100 tradeSizePct = input.float(15, "单笔风险比例 (%)", step=0.5, minval=5, maxval=30)/100 // ======= 核心指标计算 ======= // EMA双线系统 fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) // RSI动量指标 rsi = ta.rsi(math.min(close, high), rsiLength) // 防止极端值 // 布林带通道(使用标准函数) [bbUpper, bbMiddle, bbLower] = ta.bollinger(close, bbLength, mult) // ======= 信号生成系统 ======= bullishCross = ta.crossover(fastMA, slowMA) bearishCross = ta.crossunder(fastMA, slowMA) // 增强型过滤条件 oversoldCondition = rsi <= 35 and rsi > rsi[1] // RSI回升中 overboughtCondition = rsi >= 65 and rsi < rsi[1] // RSI回落中 priceBelowBB = low < bbLower and close > bbLower // 假突破过滤 priceAboveBB = high > bbUpper and close < bbUpper longCondition = bullishCross and (oversoldCondition or priceBelowBB) shortCondition = bearishCross and (overboughtCondition or priceAboveBB) // ======= 风险管理模块 ======= var float positionSize = na positionSize := strategy.equity * tradeSizePct / close // 止损止盈计算(入场时锁定) var float stopLossLevel = na var float takeProfitLevel = na if (longCondition or shortCondition) stopLossLevel := close * (1 - (strategy.position_size > 0 ? stopLossPct : -stopLossPct)) takeProfitLevel := close * (1 + (strategy.position_size > 0 ? takeProfitPct : -takeProfitPct)) // ======= 交易执行系统 ======= // 多单逻辑 if (longCondition and strategy.position_size <= 0) strategy.entry("Long", strategy.long, qty=math.floor(positionSize)) strategy.exit("Exit Long", "Long", stop=stopLossLevel, limit=takeProfitLevel, comment="多头平仓") // 空单逻辑 if (shortCondition and strategy.position_size >= 0) strategy.entry("Short", strategy.short, qty=math.floor(positionSize)) strategy.exit("Exit Short", "Short", stop=stopLossLevel, limit=takeProfitLevel, comment="空头平仓") // ======= 可视化增强系统 ======= // 均线系统 plot(fastMA, "快线", #00BCD4, 2, plot.style_linebr) plot(slowMA, "慢线", #FF9800, 2, plot.style_linebr) // 布林通道填充 bbFill = plot(bbUpper, "布林上轨", #2196F3, 1, transp=70, display=display.none) plot(bbLower, "布林下轨", #4CAF50, 1, transp=70, display=display.none) fill(bbFill, bbFill, color=color.new(#2196F3, 90), title="通道填充") // 信号标记 plotshape(longCondition, "买入信号", shape.triangleup, location.belowbar, #4CAF50, 0, "", text="B") plotshape(shortCondition, "卖出信号", shape.triangledown, location.abovebar, #F44336, 0, "", text="S") // ======= 动态监控面板 ======= var table infoTable = table.new(position.top_right, 3, 1, bgcolor=color.rgb(33, 33, 33)) if barstate.islast table.cell(infoTable, 0, 0, "策略状态:" + (strategy.position_size > 0 ? "▶ 持多单" : strategy.position_size < 0 ? "▶ 持空单" : "▷ 中立"), text_color=strategy.position_size != 0 ? color.yellow : color.white) table.cell(infoTable, 1, 0, "RSI:" + str.tostring(rsi, "#.##") + " | 通道偏离:" + str.tostring((close-bbMiddle)/bbMiddle*100, "+#.##") + "%", text_color=color.silver) table.cell(infoTable, 2, 0, "止损:" + str.tostring(stopLossLevel, "#.##") + " | 止盈:" + str.tostring(takeProfitLevel, "#.##"), text_color=color.gray) 2:Syntax error at input "end of line without line continuation"
03-12
//@version=6 strategy(“复合波段交易策略[优化版]”, overlay=true, pyramiding=1, initial_capital=100000, currency=currency.USD, calc_on_every_tick=false) // 防止重复计算 // ======= 输入参数模块 ======= fastLength = input.int(10, “短期均线周期”, minval=1, group=“趋势参数”) slowLength = input.int(20, “长期均线周期”, minval=1, group=“趋势参数”) rsiLength = input.int(14, “RSI周期”, minval=1, maxval=100, group=“震荡指标”) bbLength = input.int(20, “布林带周期”, minval=1, group=“波动通道”) mult = input.float(2.0, “标准差倍数”, step=0.1, minval=1.5, maxval=3.0, group=“波动通道”) stopLossPct = input.float(1.5, “止损比例 (%)”, step=0.1, minval=0.5, maxval=5)/100 takeProfitPct = input.float(3.5, “止盈比例 (%)”, step=0.1, minval=1.0, maxval=10)/100 tradeSizePct = input.float(15, “单笔风险比例 (%)”, step=0.5, minval=5, maxval=30)/100 // ======= 核心指标计算 ======= // EMA双线系统 fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) // RSI动量指标 rsi = ta.rsi(math.min(close, high), rsiLength) // 防止极端值 // 布林带通道(使用标准函数) [bbUpper, bbMiddle, bbLower] = ta.bollinger(close, bbLength, mult) // ======= 信号生成系统 ======= bullishCross = ta.crossover(fastMA, slowMA) bearishCross = ta.crossunder(fastMA, slowMA) // 增强型过滤条件 oversoldCondition = rsi <= 35 and rsi > rsi[1] // RSI回升中 overboughtCondition = rsi >= 65 and rsi < rsi[1] // RSI回落中 priceBelowBB = low < bbLower and close > bbLower // 假突破过滤 priceAboveBB = high > bbUpper and close < bbUpper longCondition = bullishCross and (oversoldCondition or priceBelowBB) shortCondition = bearishCross and (overboughtCondition or priceAboveBB) // ======= 风险管理模块 ======= var float positionSize = na positionSize := strategy.equity * tradeSizePct / close // 止损止盈计算(入场时锁定) var float stopLossLevel = na var float takeProfitLevel = na if (longCondition or shortCondition) stopLossLevel := close * (1 - (strategy.position_size > 0 ? stopLossPct : -stopLossPct)) takeProfitLevel := close * (1 + (strategy.position_size > 0 ? takeProfitPct : -takeProfitPct)) // ======= 交易执行系统 ======= // 多单逻辑 if (longCondition and strategy.position_size <= 0) strategy.entry(“Long”, strategy.long, qty=math.floor(positionSize)) strategy.exit(“Exit Long”, “Long”, stop=stopLossLevel, limit=takeProfitLevel, comment=“多头平仓”) // 空单逻辑 if (shortCondition and strategy.position_size >= 0) strategy.entry(“Short”, strategy.short, qty=math.floor(positionSize)) strategy.exit(“Exit Short”, “Short”, stop=stopLossLevel, limit=takeProfitLevel, comment=“空头平仓”) // ======= 可视化增强系统 ======= // 均线系统 plot(fastMA, “快线”, #00BCD4, 2, plot.style_linebr) plot(slowMA, “慢线”, #FF9800, 2, plot.style_linebr) // 布林通道填充 bbFill = plot(bbUpper, “布林上轨”, #2196F3, 1, transp=70, display=display.none) plot(bbLower, “布林下轨”, #4CAF50, 1, transp=70, display=display.none) fill(bbFill, bbFill, color=color.new(#2196F3, 90), title=“通道填充”) // 信号标记 plotshape(longCondition, “买入信号”, shape.triangleup, location.belowbar, #4CAF50, 0, “”, text=“B”) plotshape(shortCondition, “卖出信号”, shape.triangledown, location.abovebar, #F44336, 0, “”, text=“S”) // ======= 动态监控面板 ======= var table infoTable = table.new(position.top_right, 3, 1, bgcolor=color.rgb(33, 33, 33)) if barstate.islast table.cell(infoTable, 0, 0, “策略状态:” + (strategy.position_size > 0 ? “▶ 持多单” : strategy.position_size < 0 ? “▶ 持空单” : “▷ 中立”), text_color=strategy.position_size != 0 ? color.yellow : color.white) table.cell(infoTable, 1, 0, "RSI:" + str.tostring(rsi, "#.##") + " | 通道偏离:" + str.tostring((close-bbMiddle)/bbMiddle*100, "+#.##") + "%", text_color=color.silver) table.cell(infoTable, 2, 0, "止损:" + str.tostring(stopLossLevel, "#.##") + " | 止盈:" + str.tostring(takeProfitLevel, "#.##"), text_color=color.gray) 第2行有一个错误:Syntax error at input "end of line without line continuation"
03-12
//@version=6 strategy("复合波段交易策略", overlay=true, pyramiding=1, initial_capital=100000, currency=currency.USD) ; // 输入参数模块 fastLength = input.int(10, "短期均线周期", minval=1) slowLength = input.int(20, "长期均线周期", minval=1) rsiLength = input.int(14, "RSI周期", minval=1) bbLength = input.int(20, "布林带周期", minval=1) mult = input.float(2.0, "标准差倍数", step=0.1) stopLossPct = input.float(2, "止损比例 (%)", step=0.5)/100 takeProfitPct = input.float(5, "止盈比例 (%)", step=0.5)/100 // 核心指标计算 fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) rsi = ta.rsi(close, rsiLength) [bbUpper, bbMiddle, bbLower] = ta.bb(close, bbLength, mult) // 信号生成逻辑 bullishCross = ta.crossover(fastMA, slowMA) bearishCross = ta.crossunder(fastMA, slowMA) oversold = rsi <= 35 overbought = rsi >= 65 priceBelowBB = close < bbLower priceAboveBB = close > bbUpper // 复合交易条件 longCondition = bullishCross and (oversold or priceBelowBB) shortCondition = bearishCross and (overbought or priceAboveBB) // 风险管理模块 positionSize = strategy.equity * 0.1 stopLossLevel = strategy.position_avg_price * (1 - stopLossPct) takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPct) // 交易执行 if (longCondition) strategy.entry("Long", strategy.long, qty=positionSize/close) strategy.exit("Exit Long", "Long", stop=stopLossLevel, limit=takeProfitLevel) if (shortCondition) strategy.entry("Short", strategy.short, qty=positionSize/close) strategy.exit("Exit Short", "Short", stop=stopLossLevel, limit=takeProfitLevel) // 可视化组件 plot(fastMA, "快线", color.new(#00BCD4, 0), 2) plot(slowMA, "慢线", color.new(#FF9800, 0), 2) plot(bbUpper, "布林上轨", color.new(#2196F3, 70)) plot(bbLower, "布林下轨", color.new(#4CAF50, 70)) // 信号标记 plotshape(longCondition, "买入信号", shape.triangleup, location.belowbar, color.green, 0, "→ 多单入场") plotshape(shortCondition, "卖出信号", shape.triangledown, location.abovebar, color.red, 0, "→ 空单入场") // 动态信息面板 var table infoTable = table.new(position.top_right, 2, 1) if barstate.islast table.cell(infoTable, 0, 0, "当前策略状态:" + (strategy.position_size > 0 ? "持有多单" : strategy.position_size < 0 ? "持有空单" : "中立"), text_color=color.white) table.cell(infoTable, 1, 0, "RSI值:" + str.tostring(rsi, "#.##") + " | 偏离度:" + str.tostring((close-bbMiddle)/bbMiddle*100, "#.##") + "%", text_color=color.silver)
03-12
//@version=6 strategy("复合波段交易策略", overlay=true, pyramiding=1, initial_capital=100000, currency=currency.USD) // 输入参数模块 fastLength = input.int(10, "短期均线周期", minval=1) slowLength = input.int(20, "长期均线周期", minval=1) rsiLength = input.int(14, "RSI周期", minval=1) bbLength = input.int(20, "布林带周期", minval=1) mult = input.float(2.0, "标准差倍数", step=0.1) stopLossPct = input.float(2, "止损比例 (%)", step=0.5)/100 takeProfitPct = input.float(5, "止盈比例 (%)", step=0.5)/100 // 核心指标计算 fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) rsi = ta.rsi(close, rsiLength) [bbUpper, bbMiddle, bbLower] = ta.bb(close, bbLength, mult) // 信号生成逻辑 bullishCross = ta.crossover(fastMA, slowMA) bearishCross = ta.crossunder(fastMA, slowMA) oversold = rsi <= 35 overbought = rsi >= 65 priceBelowBB = close < bbLower priceAboveBB = close > bbUpper // 复合交易条件 longCondition = bullishCross and (oversold or priceBelowBB) shortCondition = bearishCross and (overbought or priceAboveBB) // 风险管理模块 positionSize = strategy.equity * 0.1 // 10%仓位管理 stopLossLevel = strategy.position_avg_price * (1 - stopLossPct) takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPct) // 交易执行 if (longCondition) strategy.entry("Long", strategy.long, qty=positionSize/close) strategy.exit("Exit Long", "Long", stop=stopLossLevel, limit=takeProfitLevel) if (shortCondition) strategy.entry("Short", strategy.short, qty=positionSize/close) strategy.exit("Exit Short", "Short", stop=stopLossLevel, limit=takeProfitLevel) // 可视化组件 plot(fastMA, "快线", color.new(#00BCD4, 0), 2) plot(slowMA, "慢线", color.new(#FF9800, 0), 2) plot(bbUpper, "布林上轨", color.new(#2196F3, 70)) plot(bbLower, "布林下轨", color.new(#4CAF50, 70)) // 信号标记 plotshape(longCondition, "买入信号", shape.triangleup, location.belowbar, color.green, 0, "→ 多单入场") plotshape(shortCondition, "卖出信号", shape.triangledown, location.abovebar, color.red, 0, "→ 空单入场") // 动态信息面板 var table infoTable = table.new(position.top_right, 2, 1) if barstate.islast table.cell(infoTable, 0, 0, "当前策略状态:" + (strategy.position_size > 0 ? "持有多单" : strategy.position_size < 0 ? "持有空单" : "中立"), text_color=color.white) table.cell(infoTable, 1, 0, "RSI值:" + str.tostring(rsi, "#.##") + " | 偏离度:" + str.tostring((close-bbMiddle)/bbMiddle*100, "#.##") + "%", text_color=color.silver) 给出完整使用说明
最新发布
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值