//@version=6
// strategy.risk.*:allow_entry_in(long) 把反向 entry 变成平仓、max_position_size 截断数量、max_intraday_filled_orders 每日限单
strategy("S_risk", overlay = false,
initial_capital = 100000, currency = currency.NONE,
default_qty_type = strategy.fixed, default_qty_value = 40, pyramiding = 1,
commission_type = strategy.commission.percent, commission_value = 0, slippage = 0,
margin_long = 0, margin_short = 0, close_entries_rule = "FIFO",
process_orders_on_close = false, calc_on_order_fills = false, calc_on_every_tick = false,
backtest_fill_limits_assumption = 0, use_bar_magnifier = false, fill_orders_on_standard_ohlc = false)
strategy.risk.allow_entry_in(strategy.direction.long)
strategy.risk.max_position_size(25)
strategy.risk.max_intraday_filled_orders(3)
int cycleLen = 12
int phase = bar_index % cycleLen
int cycle = math.floor(bar_index / cycleLen)
if phase == 0
strategy.entry("L", strategy.long) // 40 股 → 应被截到 25
if phase == 4
strategy.entry("S", strategy.short) // 只允许做多:应变成平仓,不开空
if phase == 8
strategy.close_all(comment = "c1")
if phase == 11
strategy.cancel_all()
// ---- 对齐列 ----
plot(bar_index, "bar_index")
plot(cycle, "cycle")
plot(phase, "phase")
plot(strategy.position_size, "pos")
plot(strategy.position_avg_price, "avg_price")
plot(strategy.equity, "equity")
plot(strategy.openprofit, "openprofit")
plot(strategy.netprofit, "netprofit")
plot(strategy.closedtrades, "closedtrades")
plot(strategy.opentrades, "opentrades")