PROTECTED SOURCE SCRIPT

CoinGpt NQ策略

34
# CoinGpt NQ 策略(MACD·多因子·可金字塔)

## 概述

**CoinGpt NQ策略**是一套面向 **纳指期货 NQ(建议:`CME_MINI:NQ1!`)30 分钟** 的可运行交易策略。
核心以 **MACD 趋势动量** 为骨架,叠加 **EMA 趋势过滤**、**可选金字塔加仓**、**三种出场模式(固定 TP/SL、追踪、追踪+TP)** 与 **风控上限**,提供三套一键预设(Balanced / Trend / Scalper),满足不同市场状态与风险偏好。

> 适配:期货/连续合约;仅做多(本脚本版本)。
> 时间框架:**30m**(可在“仅在 30m 生效”开关控制)。

---

## 进场逻辑

* **信号触发**:`MACD 上穿 Signal`(并要求直方图连续上升 2 根)。
* **趋势过滤**:价格位于 `EMA(p_emaLen)` 上方,且 `MACD>0 & Signal>0`(可关闭)。
* **时间框架限制**:默认仅在 30m 有效(可关闭)。

## 出场逻辑

* **固定 TP/SL**:按百分比计算限价止盈与止损。
* **追踪止盈**:默认以 **ATR 偏移** 跟踪;
* **追踪 + TP**:在拖尾的同时设置上沿 TP。
* **反向保护**:`MACD 下穿 Signal` 时市价平仓。

> 出场模式在输入项 **「出场模式」** 选择:
> `Auto(by preset) / Fixed TP/SL / Trailing / Trailing + TP`

---

## 金字塔加仓(可选)

* 仅在已有多单且不利回撤达到阈值时触发;
* 最多 `p_maxAdds` 层;每层在 **上次加仓价** 基础上按 `p_addStep%` 回撤触发;
* 目的:**拉低均价、提高持仓性价比**;采用小步长、有限层数控制回撤风险。

---

## 风险管理

* **当日最大亏损**:`strategy.risk.max_intraday_loss(p_maxDailyDD, %权益)`
* **单笔头寸上限**:`strategy.risk.max_position_size(p_posCapPct)`
* **订单量**(策略属性):默认 **90% 权益**。

* 实盘更建议:Balanced≈**40%**、Trend≈**35%**、Scalper≈**30%**(在“策略属性 → 订单大小”中调整)。

---

## 三套预设(参数一键生效)

| 预设 | MACD(fast/slow/signal) | 趋势EMA | 金字塔 | 加仓步长 | 固定TP/SL(%) | 追踪(ATR倍数) | 单笔上限 | 当日亏损 |
| ---------------- | ---------------------- | ----- | --- | ----- | ----------------- | --------- | ---- | ---- |
| **Balanced(默认)** | 8 / 21 / 5 | 233 | 2 层 | 0.12% | TP 0.22 / SL 0.15 | 1.2× | 50% | 1.5% |
| **Trend** | 10 / 24 / 7 | 200 | 3 层 | 0.10% | TP 0.25 / SL 0.18 | 1.6× | 45% | 1.2% |
| **Scalper** | 6 / 19 / 4 | 100 | 关闭 | —— | TP 0.18 / SL 0.12 | 1.3× | 35% | 1.0% |

> 说明:
>
> * Balanced:均衡型,适合多数时期;
> * Trend:顺势拉伸,持仓更久、盈亏比更高;
> * Scalper:快进快出、高胜率、不过度叠仓。

---

## 使用建议

1. **品种/周期**:`CME_MINI:NQ1!`(或当季主力合约),**30m**。
2. **手续费**:本策略默认 **1 USD/合约**(在“策略属性”可按实盘成本调整)。
3. **成交精度**:建议在“策略属性 → 高级设置”勾选 **Bar Magnifier**,提升限价/拖尾成交模拟精度。
4. **仓位**:策略默认 90% 仅为展示;回测与实盘更建议 **30%\~40% 权益**。
5. **风险**:金字塔仅做轻量、有限层数;若市场极端震荡,适当降低单笔上限与当日亏损阈值。

---

## 输入项(TradingView 右侧面板)

* **参数预设**:`Balanced / Trend / Scalper`
* **仅在 30m 周期生效**:开/关
* **出场模式**:`Auto(by preset) / Fixed TP/SL / Trailing / Trailing + TP`

> 其余细节参数由预设自动注入,无需手动繁杂调整,**开箱即用**。

---

## 注意事项

* 本脚本为研究与教育用途,不构成投资建议。期货与杠杆交易风险高,请在可承受范围内使用。
* 预设适配历史统计特征,未来表现不保证;建议结合自身风控与账户规模,先小仓/纸面验证。
* 仅做多版本;若需要双向(多空)或加入 RTH(美股盘中)/HTF(更高周期确认)等扩展,请在评论区留言。

---

**作者注**:

* 本策略在 Pine v6 编写,避免了常见的 v6 语法踩坑(如 `strategy.risk.max_position_size()` 仅 1 参、`plot` 标题需常量、追踪需成对参数 `trail_price + trail_offset` 等)。
* 欢迎在评论区反馈你的回测截图(区间、手续费、订单量),我会根据数据给出更贴合你的参数档。

# CoinGpt NQ Strategy (MACD · Multi-Factor · Optional Pyramiding)

## Overview

**CoinGpt NQ Strategy** is a ready-to-trade system for **Nasdaq-100 futures (NQ; recommended: `CME_MINI:NQ1!`) on the 30-minute timeframe**.
It uses **MACD momentum** as the backbone, adds an **EMA trend filter**, optional **pyramiding**, and **three exit modes** (Fixed TP/SL, Trailing, Trailing+TP) with built-in risk caps. Three one-click presets—**Balanced / Trend / Scalper**—cover different regimes and risk appetites.

> Instruments: futures / continuous contract
> Direction: **Long-only** (this script version)
> Timeframe: **30m** (toggleable)

---

## Entry

* **Trigger:** `MACD` line crossing **above** `Signal`.
* **Trend filter (optional):** price above `EMA(p_emaLen)` and `MACD > 0 & Signal > 0`.
* **Timeframe guard:** by default, signals are valid on **30m** only.

## Exit

* **Fixed TP/SL:** percentage-based limit and stop.
* **Trailing:** ATR-based trailing offset (or percent).
* **Trailing + TP:** trailing stop **and** a take-profit cap.
* **Protective flip:** when `MACD` crosses **below** `Signal`, close the long.

> Choose exit mode in **Inputs → “Exit Mode”**:
> `Auto(by preset) / Fixed TP/SL / Trailing / Trailing + TP`.

---

## Pyramiding (optional)

* Adds only **against adverse pullbacks** from the last add price.
* Up to `p_maxAdds` layers; each layer triggers at `p_addStep%` pullback from the **previous add**.
* Goal: **improve average price** with **small steps & limited layers** to keep drawdowns controlled.

---

## Risk Management

* **Daily loss cap:** `strategy.risk.max_intraday_loss(p_maxDailyDD, % of equity)`.
* **Per-trade size cap:** `strategy.risk.max_position_size(p_posCapPct)`.
* **Order size (strategy properties):** default **90% of equity** (for display).

* Practical suggestion: Balanced ≈ **40%**, Trend ≈ **35%**, Scalper ≈ **30%** (set in Strategy Properties → Order size).

---

## Presets (one-click)

| Preset | MACD (fast/slow/signal) | Trend EMA | Pyramiding | Add Step | Fixed TP/SL (%) | Trailing (ATR) | Pos Cap | Daily DD |
| ---------------------- | ----------------------- | --------- | ---------- | -------- | ------------------------- | -------------- | ------- | -------- |
| **Balanced (default)** | 8 / 21 / 5 | 233 | 2 layers | 0.12% | TP **0.22** / SL **0.15** | **1.2×** | **50%** | **1.5%** |
| **Trend** | 10 / 24 / 7 | 200 | 3 layers | 0.10% | TP **0.25** / SL **0.18** | **1.6×** | **45%** | **1.2%** |
| **Scalper** | 6 / 19 / 4 | 100 | Off | — | TP **0.18** / SL **0.12** | **1.3×** | **35%** | **1.0%** |

> **Balanced:** all-weather, stable.
> **Trend:** holds longer and targets higher R multiples.
> **Scalper:** quick in/out, higher hit-rate, no stacking.

---

## Usage Tips

1. **Symbol/TF:** `CME_MINI:NQ1!`, **30m**.
2. **Fees:** default **\$1 per contract** (adjust to your broker in Strategy Properties).
3. **Execution realism:** enable **Bar Magnifier** (Strategy Properties → Advanced) for more accurate limit/trailing fills.
4. **Sizing:** the script defaults to 90% only to showcase behavior—use **30–40%** in realistic tests.
5. **Pyramiding:** keep layers small & capped. In choppy regimes, reduce `p_posCapPct` and `p_maxDailyDD`.

---

## Inputs (right-panel)

* **Param Preset:** `Balanced / Trend / Scalper`
* **30m-only:** on/off
* **Exit Mode:** `Auto(by preset) / Fixed TP/SL / Trailing / Trailing + TP`

> All other parameters are pre-wired by the chosen preset for **plug-and-play** operation.

---

## Notes & Disclaimer

* Educational use only—**not** financial advice. Futures and leverage carry substantial risk.
* Presets reflect historical characteristics; **future performance is not guaranteed**. Start small or paper trade first.
* This version is **long-only**; if you need a two-sided (long & short) variant or extras (RTH/HTF filters), leave a comment.

---

**Author Notes**

* Written in **Pine v6** with common pitfalls avoided (e.g., `strategy.risk.max_position_size()` takes **one** arg, `plot` titles are **const strings**, trailing requires `trail_price + trail_offset`).
* Share your backtest screenshots (period, fees, order size) and I can suggest **tighter, data-driven knobs** for your setup.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.