itsadrianxv/tradeblazer_skills / skills/tb-bar-strategy
tb-bar-strategy
VerifiedUse when generating, modifying, explaining, or reviewing TBQ3 Bar-based trading strategies with OnBar, OnInit, OnReady, entries, exits, MarketPosition, stop profit/loss, sizing, slippage, commission, multi-symbol, or cross-period logic.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 2.8 KB |
| references/bar-patterns.md | markdown | 3.6 KB |
| references/bar-pitfalls.md | markdown | 2.1 KB |
references/bar-pitfalls.md
View on GitHub# Bar 策略常见坑
## 连续信号重复发单
突破、均线排列、通道条件可能连续多根 Bar 成立。如果没有 `MarketPosition` 或自定义状态限制,策略会不断加仓。默认用:
```cpp
If(MarketPosition <> 1 And longCond)
Buy(lots, price);
```
空头同理使用 `MarketPosition <> -1`。
## 开仓 Bar 止盈止损
Bar 数据无法知道开仓价、最高价、最低价在同一根 Bar 内的先后顺序。默认止盈止损使用:
```cpp
If(MarketPosition == 1 And BarsSinceEntry >= 1)
```
如果用户要求开仓 Bar 内处理,应提示需要更小周期或 Tick 级逻辑。
## 跳空成交价
止盈止损触发价可能被开盘跳空越过。多仓止盈时如果 `Open > exitPrice`,用 `Open` 替代;多仓止损时如果 `Open < exitPrice`,用 `Open` 替代。空仓方向相反。
## 多空方向和函数匹配
- 开多:`Buy`
- 平多:`Sell`
- 开空:`SellShort`
- 平空:`BuyToCover`
不要用 `Sell` 开空,也不要用 `Buy` 平空。
## 手数为 0
固定资金或固定保证金计算手数时,`IntPart` 可能返回 0。应根据策略要求处理,常见做法是限制最小为 1,或在资金不足时跳过发单并说明。
## 历史和实时运行差异
历史回测通常每根 Bar 执行一次;实时中当前 Bar 可能随 Tick 多次更新。依赖当前 Bar 的条件时,可能出现盘中信号和收盘信号不一致。需要时使用 `BarStatus`、收盘确认或更明确的触发时机。
## 换月复权真实价格
连续合约或复权数据用于指标计算时,真实下单价格可能需要映射或换算。涉及 `Rollover`、888/000 连续合约、真实合约发单时,必须查:
- `docs/TB语言编程技巧/2861-真实合约数据进行后复权处理.md`
- `docs/TB语言编程技巧/2862-系统直接提供后复权之后的数据.md`
- `docs/TB语言编程技巧/2863-利用系统函数的后复权处理.md`
## 跨周期和多品种对齐
多数据源、跨周期、套利、多品种策略不能只复制单品种模板。需要确认数据源索引、Bar 对齐、交易映射和每个品种的手续费/保证金设置。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |