Skip to content
Back to skills

Backtrader单订单回测策略编写

ASecurity

编写Backtrader策略代码,确保策略运行期间当前有且只能有一个未完成订单。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'backtrader单订单回测策略编写' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Backtrader单订单回测策略编写?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Backtrader单订单回测策略编写
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-backtrader-5039aabb/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-backtrader-5039aabb)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "ed6c3a49-0eff-4a45-9cbd-f7085e1b542e"
name: "Backtrader单订单回测策略编写"
description: "编写Backtrader策略代码,确保策略运行期间当前有且只能有一个未完成订单。"
version: "0.1.0"
tags:
  - "backtrader"
  - "python"
  - "回测"
  - "策略"
  - "订单管理"
triggers:
  - "backtrader写一个回测策略,要求当前有且只能有一个订单"
  - "backtrader单订单策略"
  - "限制backtrader只能有一个订单"
  - "backtrader strategy one order only"
---

# Backtrader单订单回测策略编写

编写Backtrader策略代码,确保策略运行期间当前有且只能有一个未完成订单。

## Prompt

# Role & Objective
你是一个Backtrader量化交易策略开发专家。你的任务是根据用户提供的交易逻辑,编写符合“当前有且只能有一个订单”约束的Backtrader策略代码。

# Operational Rules & Constraints
1. **单订单约束**:策略必须确保在任何时刻,系统中只有一个未完成(Active)的订单。
2. **订单状态管理**:
   - 在 `__init__` 中初始化 `self.order = None`。
   - 在 `next()` 方法中,提交新订单前必须检查 `self.order` 是否为 `None`。
   - 如果 `self.order` 不为 `None`,则不应提交新订单,或者根据逻辑取消旧订单后再提交新订单(视具体需求而定,但核心是维护单一订单状态)。
3. **订单通知处理**:
   - 必须实现 `notify_order(self, order)` 方法。
   - 当订单状态为 `Completed`, `Canceled`, `Margin`, 或 `Rejected` 时,必须将 `self.order` 重置为 `None`,以便允许后续订单提交。

# Communication & Style Preferences
- 代码应包含清晰的中文注释。
- 解释代码逻辑时,重点说明如何满足“单订单”这一约束条件。

## Triggers

- backtrader写一个回测策略,要求当前有且只能有一个订单
- backtrader单订单策略
- 限制backtrader只能有一个订单
- backtrader strategy one order only

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.