← Back to Skills Marketplace
137
Downloads
0
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install factorlang-expression
Description
提供完整的FactorLang量化因子表达式语言参考手册和规范。当用户需要编写因子表达式、策略开发、查询语法或设计交易策略时调用此技能。包含完整的变量、函数和最佳实践。基于原始文档,包含完整的变量、函数和最佳实践。
README (SKILL.md)
\r \r
FactorLang表达式系统规范 v2.2(完整版)\r
\r
🎯 快速开始\r
# 示例1:日线收盘价突破10日最高价\r
_close_1d > HHV(10, _close_1d, 1d, 1ref)\r
\r
# 示例2:5日EMA斜率向上且金叉状态\r
_ema_1d_5_slope > 0 && _dkx_1d_cross_status == 1\r
\r
# 示例3:最近3天至少2天收阳\r
ANY(3, 2, _close_1d > _open_1d, 1d)\r
\r
# 示例4:价格在箱体内震荡\r
INRANGE(_close_1d, _box_1d_green_low, _box_1d_green_high)\r
\r
# 示例5:盈亏点数止损(使用正确的_palp变量)\r
_palp > 10 # 盈利10点止盈或亏损10点止损\r
```\r
\r
## 📋 核心变量速查表(基于原始文档)\r
\r
### 行情数据变量\r
| 变量 | 说明 | 示例 | 原始文档位置 |\r
|------|------|------|-------------|\r
| `_open_{period}` | 开盘价 | `_open_1d` | 第1-50行 |\r
| `_high_{period}` | 最高价 | `_high_1d` | 第1-50行 |\r
| `_low_{period}` | 最低价 | `_low_1d` | 第1-50行 |\r
| `_close_{period}` | 收盘价 | `_close_1d` | 第1-50行 |\r
| `_vol_{period}` | 成交量 | `_vol_1d` | 第1-50行 |\r
\r
### 技术指标变量\r
| 变量 | 说明 | 示例 | 原始文档位置 |\r
|------|------|------|-------------|\r
| `_ma_{period}_{N}` | 移动平均线 | `_ma_1d_30` | 第100-200行 |\r
| `_ma_{period}_{N}_trend` | MA趋势方向 | `_ma_1d_30_trend` | 第100-200行 |\r
| `_dkx_{period}` | 多空线 | `_dkx_1d` | 第200-300行 |\r
| `_dkx_{period}_cross_status` | 金叉状态 | `_dkx_1d_cross_status` | 第200-300行 |\r
| `_box_{period}_green_high` | 绿色箱体高点 | `_box_1d_green_high` | 第300-400行 |\r
| `_box_{period}_green_low` | 绿色箱体低点 | `_box_1d_green_low` | 第300-400行 |\r
| `_box_{period}_red_high` | 红色箱体高点 | `_box_1d_red_high` | 第300-400行 |\r
| `_box_{period}_red_low` | 红色箱体低点 | `_box_1d_red_low` | 第300-400行 |\r
\r
### **盈亏相关变量(重要)**\r
| 变量 | 说明 | 示例 | 原始文档位置 |\r
|------|------|------|-------------|\r
| **`_palp`** | **盈亏点数** | `_palp > 10` | 第604行 |\r
| `_palr` | 盈亏百分比 | `_palr > 40` | 第603行 |\r
\r
**重要区别**:\r
- **`_palp`**: 盈亏点数(当前价格 - 持仓成本)\r
- **`_palr`**: 盈亏百分比(相对于持仓成本的百分比)\r
\r
### 周期参数\r
| 周期 | 说明 | 应用场景 |\r
|------|------|----------|\r
| `1m` | 1分钟 | 高频交易 |\r
| `5m` | 5分钟 | 短线交易 |\r
| `15m` | 15分钟 | 中短线 |\r
| `30m` | 30分钟 | 中短线 |\r
| `60m` | 60分钟 | 短期趋势 |\r
| `1d` | 日线 | 中长线 |\r
| `1w` | 周线 | 长期投资 |\r
| `1mon` | 月线 | 长期投资 |\r
\r
## 🔧 常用函数速查\r
\r
### 统计函数\r
```python\r
# 最高值\r
HHV(10, _close_1d, 1d, 1ref) # 最近10日最高收盘价\r
\r
# 最低值\r
LLV(10, _close_1d, 1d, 1ref) # 最近10日最低收盘价\r
\r
# 移动平均\r
MA(_close_1d, 20, 1d, 1ref) # 20日移动平均\r
\r
# 指数移动平均\r
EMA(_close_1d, 12, 1d, 1ref) # 12日指数移动平均\r
\r
# 引用函数\r
REF(_close_1d, 1) # 前一日收盘价\r
REF(_close_1d, 2) # 前两日收盘价\r
```\r
\r
### 逻辑函数\r
```python\r
# 条件判断\r
IF(_close_1d > _ma_1d_20, 1, -1)\r
\r
# 范围判断\r
INRANGE(_close_1d, _box_1d_green_low, _box_1d_green_high)\r
\r
# 任意条件满足\r
ANY(3, 2, _close_1d > _open_1d, 1d)\r
\r
# 所有条件满足\r
ALL(3, 3, _close_1d > _open_1d, 1d)\r
```\r
\r
### 数学函数\r
```python\r
# 绝对值\r
ABS(_close_1d - _open_1d)\r
\r
# 最大值\r
MAX(_close_1d, _open_1d)\r
\r
# 最小值\r
MIN(_close_1d, _open_1d)\r
\r
# 求和\r
SUM(5, _close_1d, 1d, 1ref)\r
```\r
\r
## 🎯 策略模板\r
\r
### 趋势跟踪策略\r
```python\r
# 多头趋势:多空线金叉且斜率向上\r
_dkx_1d_cross_status == 1 && _dkx_1d_slope > 0\r
\r
# 空头趋势:多空线死叉且斜率向下\r
_dkx_1d_cross_status == -1 && _dkx_1d_slope \x3C 0\r
\r
# 均线多头排列\r
_ma_1d_5 > _ma_1d_10 && _ma_1d_10 > _ma_1d_20\r
\r
# 均线空头排列\r
_ma_1d_5 \x3C _ma_1d_10 && _ma_1d_10 \x3C _ma_1d_20\r
```\r
\r
### 突破策略\r
```python\r
# 突破箱体上轨\r
_close_1d > _box_1d_green_high\r
\r
# 突破前高\r
_close_1d > HHV(20, _high_1d, 1d, 1ref)\r
\r
# 突破均线\r
_close_1d > _ma_1d_30\r
\r
# 突破布林带上轨\r
_close_1d > _boll_1d_upper\r
```\r
\r
### 止损策略\r
```python\r
# 盈亏点数止损(使用正确的_palp变量)\r
_palp > 10 # 盈利10点止盈或亏损10点止损\r
\r
# 盈亏百分比止损\r
_palr > 0.1 # 盈利10%止盈\r
_palr \x3C -0.05 # 亏损5%止损\r
\r
# 移动止损\r
_close_1d \x3C HHV(10, _close_1d, 1d, 1ref) * 0.95 # 从最高点回撤5%\r
```\r
\r
### 震荡策略\r
```python\r
# RSI超买超卖\r
_rsi_1d > 70 # 超买\r
_rsi_1d \x3C 30 # 超卖\r
\r
# KD指标金叉死叉\r
_kd_1d_k > _kd_1d_d && REF(_kd_1d_k, 1) \x3C REF(_kd_1d_d, 1) # 金叉\r
_kd_1d_k \x3C _kd_1d_d && REF(_kd_1d_k, 1) > REF(_kd_1d_d, 1) # 死叉\r
```\r
\r
## 💡 最佳实践\r
\r
### 1. 变量使用规范\r
- 使用正确的盈亏变量:`_palp`(点数)和`_palr`(百分比)\r
- 周期参数必须正确:`1m`, `5m`, `1d`, `1w`等\r
- 技术指标参数必须完整:`_ma_1d_30`(周期_长度)\r
\r
### 2. 表达式编写技巧\r
- 使用括号明确运算优先级\r
- 避免过于复杂的嵌套表达式\r
- 使用注释说明策略逻辑\r
\r
### 3. 策略组合\r
- 结合多个时间周期进行验证\r
- 使用多种技术指标进行确认\r
- 设置合理的止损止盈条件\r
\r
## 🚨 常见错误\r
\r
### 错误1:使用错误的盈亏变量\r
```python\r
# 错误:使用_profit_loss_percent\r
_profit_loss_percent > 10\r
\r
# 正确:使用_palp或_palr\r
_palp > 10 # 盈亏点数\r
_palr > 0.1 # 盈亏百分比\r
```\r
\r
### 错误2:周期参数不完整\r
```python\r
# 错误:缺少周期参数\r
_ma_30\r
\r
# 正确:完整的周期参数\r
_ma_1d_30 # 日线30周期均线\r
_ma_5m_60 # 5分钟60周期均线\r
```\r
\r
### 错误3:函数参数错误\r
```python\r
# 错误:参数顺序错误\r
HHV(_close_1d, 10)\r
\r
# 正确:正确的参数顺序\r
HHV(10, _close_1d, 1d, 1ref)\r
```\r
\r
## 🔧 特殊规则(AI必须遵守)\r
\r
### 规则1:双箱体高点/低点计算\r
```python\r
# 双绿箱高点 = 当前和前一个绿色箱体高点中取最高值\r
MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
\r
# 双红箱低点 = 当前和前一个红色箱体低点中取最低值\r
MIN(_box_30m_red_low, REF(_box_30m_red_low, 1))\r
```\r
\r
### 规则2:突破逻辑的收盘价周期推断\r
```python\r
# 重要概念:"突破30分钟"指的是突破30分钟周期的箱体,不是使用30分钟收盘价\r
# 收盘价的周期应该根据上下文决定:\r
\r
# 情况1:用户明确指定收盘价周期\r
if "60分钟收盘价" in user_input:\r
close_period = "60m" # 使用60分钟收盘价\r
elif "30分钟收盘价" in user_input:\r
close_period = "30m" # 使用30分钟收盘价\r
else:\r
# 情况2:用户未指定收盘价周期,使用基础周期\r
close_period = base_period # 基础周期(如5m、15m等)\r
\r
# 示例:突破30分钟双绿箱高点\r
_close_{close_period} > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
```\r
\r
### 规则3:基础周期与收盘价周期的关系\r
```python\r
# 默认基础周期是5分钟,那么收盘价就是5分钟收盘价\r
_close_5m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
\r
# 如果基础周期是15分钟,收盘价就是15分钟收盘价\r
_close_15m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
\r
# 如果用户明确指定使用60分钟收盘价\r
_close_60m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
```\r
\r
### 规则4:止损条件处理\r
```python\r
# 用户明确提到止损条件时,使用用户指定的条件\r
if "止损" in user_input or "止盈" in user_input:\r
stopCondition = "用户指定的止损条件"\r
else:\r
# 用户未提到止损条件时,止损条件应该传空\r
stopCondition = "" # 空字符串\r
```\r
\r
### 规则5:MCP服务器调用\r
```python\r
# 用户未提到止损条件时,MCP调用应该传空字符串\r
mcp_engine_mcp_server_run_expression_selected(\r
startDateStr="2024-01-17",\r
endDateStr="2024-04-17", \r
period="5m", # 基础周期\r
poolId="10",\r
openCondition="用户指定的开仓条件",\r
closeCondition="用户指定的平仓条件",\r
stopCondition="", # 用户未提到止损条件时传空\r
initCash=10000000,\r
direction=1\r
)\r
```\r
\r
## 🎯 完整示例\r
\r
### 示例1:默认基础周期5分钟\r
```python\r
# 用户输入:突破30分钟双绿箱高点\r
# 推断:基础周期5分钟,收盘价使用5分钟收盘价\r
\r
_close_5m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
```\r
\r
### 示例2:用户指定基础周期15分钟\r
```python\r
# 用户输入:基础周期15分钟,突破30分钟双绿箱高点\r
# 推断:基础周期15分钟,收盘价使用15分钟收盘价\r
\r
_close_15m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
```\r
\r
### 示例3:用户明确指定收盘价周期\r
```python\r
# 用户输入:60分钟收盘价突破30分钟双绿箱高点\r
# 推断:收盘价使用60分钟收盘价\r
\r
_close_60m > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
```\r
\r
### 示例4:完整策略\r
```python\r
# 开仓条件:突破30分钟双绿箱高点(使用基础周期收盘价)\r
_close_{base_period} > MAX(_box_30m_green_high, REF(_box_30m_green_high, 1))\r
\r
# 平仓条件:突破30分钟双红箱低点(使用基础周期收盘价)\r
_close_{base_period} \x3C MIN(_box_30m_red_low, REF(_box_30m_red_low, 1))\r
\r
# 止损条件:用户未提到,传空\r
""\r
```\r
\r
---\r
\r
**数据来源**:基于[resources/FactorLang表达式系统规范.md](resources/FactorLang表达式系统规范.md)\r
**调用时机**:当用户需要编写因子表达式、策略开发、查询语法或设计交易策略时自动调用此技能。\r
\r
**版本**:v2.2(添加突破逻辑的收盘价周期推断规则)\r
\r
**AI执行要求**:必须严格遵守本SKILL中的变量使用规范和特殊规则!
Usage Guidance
This package is mainly a reference manual and examples for FactorLang and appears consistent with that purpose, but it also contains an instruction to call an 'MCP' engine (mcp_engine_mcp_server_run_expression_selected) that would send strategy/condition data to an external service. Before installing or enabling this skill, ask the publisher: (1) what is the MCP server (URL, owner, privacy policy)? (2) Will the agent actually send user strategy text or other sensitive data to that server? (3) What credentials or config are required, and why aren't they declared? If you plan to use the skill only as offline documentation, ensure the agent/platform won't automatically invoke external APIs or transmit your proprietary strategies; prefer disabling autonomous invocation or restricting network calls until you verify the endpoint and credentials. If the author cannot provide clear answers or the endpoint is untrusted, treat the skill as risky for handling confidential strategy code or account-sensitive parameters.
Capability Analysis
Type: OpenClaw Skill
Name: factorlang-expression
Version: 1.0.1
The skill bundle provides a comprehensive reference and instruction set for 'FactorLang', a domain-specific language for quantitative trading expressions. The files (SKILL.md and FactorLang表达式系统规范.md) contain documentation on variables, functions, and logic for financial analysis, along with specific instructions for the AI agent to correctly format calls to an MCP server (mcp_engine_mcp_server_run_expression_selected). There are no indicators of data exfiltration, malicious execution, or harmful prompt injection.
Capability Assessment
Purpose & Capability
The declared purpose (FactorLang expression reference and guidance) matches the included documentation and examples. However, the SKILL.md includes a specific MCP server call pattern for running expressions, which expands the skill's scope from 'documentation' to 'integration/execution' without declaring the service endpoint, required credentials, or why such a call is necessary for a documentation-only skill.
Instruction Scope
Instructions are mostly documentation and parsing rules for constructing expressions, which is expected. Concerningly, a special rule (Rule5) shows a concrete call to mcp_engine_mcp_server_run_expression_selected that sends start/end dates, poolId, open/close/stop conditions, cash, and direction. That directs the agent to transmit user-provided strategy details to an external execution/engine service; the SKILL.md does not identify the destination, authentication, or privacy handling.
Install Mechanism
No install spec and no code files that execute code are present beyond documentation; this is lowest-risk from installation perspective.
Credentials
The skill declares no required env vars or credentials, which aligns with being documentation-only. However, because it explicitly instructs the agent to call an MCP server, it is unusual that no endpoint or credential requirements are declared — if the agent/platform will perform that call, credentials or configuration will likely be needed but are not specified.
Persistence & Privilege
always is false and the skill is user-invocable; it does not request elevated persistence or system-wide configuration. Autonomous invocation is allowed by default (platform normal) but is not, by itself, a new concern here.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install factorlang-expression - After installation, invoke the skill by name or use
/factorlang-expression - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.1
- 文档路径从根目录移至 resources/ 下(FactorLang表达式系统规范.md → resources/FactorLang表达式系统规范.md)
- SKILL.md 内的数据来源说明同步为新路径,引用为 [resources/FactorLang表达式系统规范.md]
- 其余规范、内容、示例、规则均保持一致,没有其他功能或逻辑性调整
v1.0.0
- Initial release of factorlang-expression skill.
- Provides a comprehensive FactorLang quant factor expression language manual and specification.
- Includes complete variable and function reference, best practices, and rules for strategy development.
- Covers core variables (e.g.,行情、技术指标、盈亏), detailed function usage, and common strategy templates.
- Introduces special rules for handling close price period inference, stop-loss condition assignment, and MCP server calls.
- Designed for use when users need to write factor expressions, develop strategies, query syntax, or design trading logic.
Metadata
Frequently Asked Questions
What is factorlang-expression?
提供完整的FactorLang量化因子表达式语言参考手册和规范。当用户需要编写因子表达式、策略开发、查询语法或设计交易策略时调用此技能。包含完整的变量、函数和最佳实践。基于原始文档,包含完整的变量、函数和最佳实践。 It is an AI Agent Skill for Claude Code / OpenClaw, with 137 downloads so far.
How do I install factorlang-expression?
Run "/install factorlang-expression" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is factorlang-expression free?
Yes, factorlang-expression is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does factorlang-expression support?
factorlang-expression is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created factorlang-expression?
It is built and maintained by Frank (@rxjhfmf); the current version is v1.0.1.
More Skills