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:
peakifh2 > h3 and h2 > h1valleyifh2 < h3 and h2 < h1
- Entry side:
peak+hist > 0=> open shortvalley+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
- Read symbol config (
instId, leverage, margin USDT, threshold). - Pull latest 4h candles from OKX market skill.
- Compute MACD histogram and detect pivot on closed candle.
- Enforce one-signal-per-candle lock.
- Determine target action:
- no action
- open/rebalance same direction (delta adjust)
- flip (close opposite then open target)
- full close
- Execute through OKX trade skill.
- Return concise execution result: side, qty, reference price, order id, reject code if any.
Output Contract
Always include:
symbolaction(open_long,open_short,reduce,close_full,no_action)reason(pivot/threshold/lock)order_id(if placed)error_codeanderror_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.