Logo: Guard Trailing Stop

Guard Trailing Stop

Organisatioun
Nunchi-trade
guard-trailing-stop

Guard — two-phase ROE-based trailing stop system for Hyperliquid perps. Phase 1 lets the trade breathe with wide retrace and patient breach counting. Phase 2 locks profit through configurable tier ratcheting with per-tier retrace overrides. Supports LONG and SHORT, hard/soft breach decay, stagnation take-profit, and preset configs. Use when protecting an open position, setting trailing stops, or automating profit-locked exits.

Iwwersiicht

EditeurNunchi-trade
Repositoryagent-cli
Skill-Nummguard-trailing-stop
Stären
521
Forks
136
Matgeliwwert Dateien
1
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 1 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Nunchi-trade huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Guard Trailing Stop an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/Nunchi-trade/agent-cli/tree/main/skills/guard
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Nunchi-trade/agent-cli.git /tmp/agent-cli
mkdir -p .claude/skills
cp -r /tmp/agent-cli/skills/guard .claude/skills/guard-trailing-stop
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Guard Trailing Stop an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Guard Trailing Stop automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Guard Trailing Stop net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Guard Trailing Stop

Two-phase ROE-based trailing stop that protects profits on Hyperliquid perp positions.

How It Works

Phase 1: "Let It Breathe"

  • Wide retrace (3% default) from high-water mark
  • Patient: requires 3 consecutive breach checks before close
  • Absolute price floor caps max loss
  • Goal: don't get shaken out before the trade develops

Phase 2: "Lock the Bag"

  • Tight retrace (1.5% default, per-tier overrides)
  • Quick exit: 1-2 breaches to close
  • ROE-based tier ratcheting — profit floors never go backward
  • Per-tier retrace tightens as profit grows

ROE-Based Tiers

All triggers use ROE (Return on Equity): PnL / margin * 100. At 10x leverage, 1% price move = 10% ROE.

Usage

Standalone — Guard an existing position

bash
hl guard start ETH-PERP \
  --entry 2500.0 \
  --size 1.0 \
  --direction long \
  --leverage 10 \
  --preset tight \
  --tick 5

Composable — Attach to any strategy

yaml
# config.yaml
strategy: avellaneda_mm
instrument: ETH-PERP
tick_interval: 10.0
guard:
  enabled: true
  preset: tight
  leverage: 10.0
bash
hl run avellaneda_mm --config config.yaml

Presets

PresetTiersStagnation TPUse Case
moderate6 (10/20/30/50/75/100% ROE)NoStandard trades
tight4 (10/20/40/75% ROE)Yes (8% ROE, 1hr)Aggressive protection

Module API

python
from modules.trailing_stop import TrailingStopEngine, GuardAction
from modules.guard_config import GuardConfig, PRESETS
from modules.guard_state import GuardState

config = PRESETS["tight"]
config.leverage = 10.0
config.direction = "long"

engine = TrailingStopEngine(config)
state = GuardState.new("ETH-PERP", entry_price=2500.0, position_size=1.0, direction="long")

result = engine.evaluate(price=2520.0, state=state)
# result.action: GuardAction.HOLD | .CLOSE | .TIER_CHANGED
# result.state: updated state (persist this)
# result.roe_pct, result.effective_floor, result.reason

Configuration Reference

ParameterDefaultDescription
directionlongPosition direction: long or short
leverage10.0Position leverage (used in ROE calc)
phase1_retrace0.03Phase 1 retrace from high-water (3%)
phase1_max_breaches3Consecutive breaches before Phase 1 close
phase1_absolute_floor0.0Hard price floor (0 = disabled)
phase2_retrace0.015Default Phase 2 retrace (1.5%)
phase2_max_breaches2Default breaches in Phase 2
breach_decay_modehardhard (reset to 0) or soft (decay by 1)
stagnation_enabledfalseEnable stagnation take-profit
stagnation_min_roe8.0Min ROE% for stagnation trigger
stagnation_timeout_ms3600000HW stale time before stagnation close (1hr)

Tier Format

yaml
tiers:
  - trigger_pct: 10.0    # Activate at 10% ROE
    lock_pct: 5.0         # Lock 5% ROE as floor
  - trigger_pct: 20.0
    lock_pct: 14.0
    retrace: 0.012        # Per-tier retrace override (1.2%)
    max_breaches: 1       # Per-tier breach count override

Direction Reference

ConceptLONGSHORT
ProfitPrice upPrice down
ROE(price-entry)/entry * lev * 100(entry-price)/entry * lev * 100
High waterHighest priceLowest price
Tier floorentry * (1 + lock/100/lev)entry * (1 - lock/100/lev)
Trailing floorhw * (1 - retrace)hw * (1 + retrace)
Effective floormax(tier, trailing)min(tier, trailing)
Breachprice <= floorprice >= floor

Agent Mandate

You are the Guard trailing stop guardian. Your job is to protect profits and limit losses on open positions. You never make entry decisions — you only manage exits via a two-phase trailing stop system.

RULES:

  • ALWAYS attach Guard to every open position — unprotected positions are unacceptable
  • NEVER override a CLOSE signal — if Guard says close, close immediately
  • ALWAYS use the correct direction (long/short) — wrong direction inverts all logic
  • Let Phase 1 breathe — do not panic on early retrace within 3% threshold
  • In Phase 2, trust the tier system — floors only ratchet up, never down
  • ALWAYS verify entry price and leverage are correct before starting

Decision Rules

ConditionAction
Guard returns CLOSEClose position immediately — no hesitation
Guard returns TIER_CHANGEDLog the new tier — no action needed, floors auto-ratchet
Guard returns HOLDDo nothing — position is healthy
ROE > 10% and still Phase 1Normal — Phase 2 triggers at first tier (usually 10% ROE)
Breach count incrementing but no closePhase 1 patience — 3 consecutive breaches needed
Stagnation timer triggeredClose — profit is stale, capital better deployed elsewhere
PresetWhen to Use
moderateStandard trades, medium hold time, balanced protection
tightAggressive protection, short holds, includes stagnation TP
CustomOnly when you understand all tier parameters — test with mock first

Anti-Patterns

  • Using tight preset on trending assets: Tight stops exit too early on strong trends. Use moderate for trend-following strategies.
  • Wrong direction parameter: Setting direction=long on a short position means Guard will hold losses and exit winners. Always double-check.
  • Overriding CLOSE signals: "It'll come back" — it won't. Guard computed the exit. Trust it.
  • Starting Guard after the move: Guard needs accurate entry price. Starting Guard at current price when entry was 2% ago means the trailing is wrong.
  • Running without leverage parameter: Default leverage (10x) may not match your actual leverage — incorrect ROE calculation — wrong tier triggers.

Error Recovery

ErrorCauseFix
No position foundPosition already closed or wrong instrumentCheck hl status for actual positions
Guard state staleProcess crashed mid-tickRestart Guard — state file preserves last known state
Negative ROE but no closeStill in Phase 1 toleranceNormal if within 3% retrace. Hard stop at -5% ROE is separate
Tier jumped from 1 to 4Fast price move between ticksNormal — tiers are checked sequentially but can skip

Composition

Guard is a sub-component of APEX (runs every tick per active slot). Can also be used standalone to guard any position. When used with APEX, Guard states are managed automatically. When used standalone, you must provide entry price, size, direction, and leverage.

Cron Template

bash
# Guard is typically long-running (attached to a position), not cron-scheduled.
# Start manually when opening a position:
hl guard start ETH-PERP --entry 2500 --direction long --leverage 10 --preset moderate --tick 5

Matgeliwwert Dateien

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Guard Trailing Stop?

Guard — two-phase ROE-based trailing stop system for Hyperliquid perps. Phase 1 lets the trade breathe with wide retrace and patient breach counting. Phase 2 locks profit through configurable tier ratcheting with per-tier retrace overrides. Supports LONG and SHORT, hard/soft breach decay, stagnation take-profit, and preset configs. Use when protecting an open position, setting trailing stops, or automating profit-locked exits.

Firwat Guard Trailing Stop op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Guard Trailing Stop besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Guard Trailing Stop an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/Nunchi-trade/agent-cli/tree/main/skills/guard an. TypingMind liest d'Datei SKILL.md, bëndelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Guard Trailing Stop benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Guard Trailing Stop benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Guard Trailing Stop domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Guard Trailing Stop gratis?

Jo. Nunchi-trade huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇