# macd strategy
## Metadata

- Canonical URL: https://6ducklearn.com/skills/macd-strategy/
- Markdown URL: https://6ducklearn.com/skills/macd-strategy/index.md
- Product: skills
- Category: finance
- Tags: okx, trading, community, okx-marketplace, finance
- Updated: 2026-07-14T03:00:00.357428+00:00
## Summary
Execute OKX CEX open/close decisions using MACD pivot rules (4h, MACD 12/26/9, threshold gate, pivot-based entry/exit, one-signal-per-candle). Use when user asks to open or close positions on OKX according to this logic only (no portfolio/earn tasks). Requires OKX skills from `npx skills add okx/agent-skills` to be installed.
## Content
> **6DuckLearn provenance:** Community skill by buqun, mirrored from the OKX Skills Marketplace (https://www.okx.com/en-sg/agent-tradekit/skills/macd-strategy). It is not curated, verified, or endorsed by 6DuckLearn or represented as an official OKX publication.
>
> **Financial safety boundary:** Never request secrets in chat. Before any external API call or action that places, cancels, or amends an order; changes leverage; transfers funds; creates or stops a bot; subscribes to or redeems an earn product; or signs/broadcasts a transaction, show the exact live/demo profile, instrument, side, size, price constraints, fees, and worst-case loss, then obtain explicit user approval. Default to read-only or demo mode when uncertain. Treat all analysis as research, not investment advice.

# OKX Open/Close

Apply only open/close logic. Do not handle earn, portfolio analytics, or unrelated tasks.

## Dependency
Require these skills installed from `okx/agent-skills`:
- `okx-cex-market` (candles/price data)
- `okx-cex-trade` (order execution)

If unavailable, stop and report dependency missing.

## Strategy Rules
- Timeframe: `4h`
- MACD params: `12/26/9`
- Threshold gate: `abs(hist) >= MACD_ABS_ENTRY_MIN`
- Pivot detection:
  - `peak` if `h2 > h3 and h2 > h1`
  - `valley` if `h2 < h3 and h2 < h1`
- Entry side:
  - `peak` + `hist > 0` => open short
  - `valley` + `hist < 0` => open long
- If pivot exists but entry side is not eligible => close existing position (full close).
- One signal per candle: if candle already processed, do nothing.

## Execution Workflow
1. Read symbol config (`instId`, leverage, margin USDT, threshold).
2. Pull latest 4h candles from OKX market skill.
3. Compute MACD histogram and detect pivot on closed candle.
4. Enforce one-signal-per-candle lock.
5. Determine target action:
   - no action
   - open/rebalance same direction (delta adjust)
   - flip (close opposite then open target)
   - full close
6. Execute through OKX trade skill.
7. Return concise execution result: side, qty, reference price, order id, reject code if any.

## Output Contract
Always include:
- `symbol`
- `action` (`open_long`, `open_short`, `reduce`, `close_full`, `no_action`)
- `reason` (pivot/threshold/lock)
- `order_id` (if placed)
- `error_code` and `error_message` (if failed)

## Risk/Guardrails
- Never submit duplicate order on same candle signal.
- If exchange rejects (`max position`, leverage constraint, etc.), do not loop retry.
- Report rejection and ask whether to reduce, change leverage, or skip.

## Reference
See `references/parameters.md` for default parameters and tuning ranges.

## Related Skills

- [alpha vantage](https://6ducklearn.com/skills/alpha-vantage/index.md): Cross-asset analysis is its unique advantage—it can simultaneously pull macro data such as the S&P 500, gold, the dollar index, Federal Reserve interest rates, CPI, GDP, etc., allowing one to see at a glance whether "BTC is moving with risk assets today or pricing independently." In conjunction with the OKX Trade Kit, Alpha Vantage is responsible for in-depth historical and macroeconomic context, while OKX provides real-time prices, funding rates, and order book data, with both complementing each other to form a complete analysis chain.
- [apex crypto intelligence](https://6ducklearn.com/skills/apex-crypto-intelligence/index.md): AI-driven multi-exchange cryptocurrency market analysis, arbitrage detection, and hedge fund-level trading reports using real-time data from major exchanges.
- [btc altcoin market pulse](https://6ducklearn.com/skills/btc-altcoin-market-pulse/index.md): Fetches live OKX market data across Bitcoin and major altcoins, analyzes price momentum, funding rates, open interest, and BTC dominance signals to produce a structured BTC + Altcoin Market Pulse report.
- [cmc okx](https://6ducklearn.com/skills/cmc-okx/index.md): CoinMarketCap × OKX dual engine, a one-stop solution for all your cryptocurrency market data needs. CMC provides market cap, supply, dominance, holding distribution, project background, and macro event calendar; the OKX Trade Kit complements with real-time prices, funding rates, open interest, 70+ technical indicators, and order book depth, with both automatically linked and mutually supportive. It supports natural language triggers, whether you ask "What’s the price of Bitcoin?", "How to read the ETH daily chart?" or "Which coin is surging?", Skill automatically recognizes intent, selects tool combinations, outputs structured tables, and includes a "Quick Take" one-sentence summary.
- [congress trades](https://6ducklearn.com/skills/congress-trades/index.md): Track U.S. Congress members' stock trades in real-time, making "smart political money" impossible to hide. Sync member trade disclosure data to a local SQLite database via the Quiver Quant API, allowing flexible queries by politician name, stock code, party, date range, and trade type. Large trades exceeding the configurable amount threshold (default $15,001) automatically trigger alerts, generating structured Alert files for real-time monitoring.
- [crypto research](https://6ducklearn.com/skills/crypto-research/index.md): A systematic cryptocurrency due diligence report, covering everything from price to holding distribution, from technical aspects to a red flag checklist, all in one go. Integrating the OKX Trade Kit (real-time prices, 70+ technical indicators, funding rates, open interest, order book depth) with CoinMarketCap (market cap, token economics, whale distribution, news sentiment), a seven-step research process is executed in parallel, covering market snapshots, technical analysis, derivatives data, project fundamentals, and recent news. The analysis framework specifically distinguishes between legitimate projects and Meme coins, evaluating key signals such as whale concentration, holder trends, 200-day moving average positions, and funding rate extremes, ultimately outputting a green flag/red flag checklist and low/medium/high/very high risk ratings.
