Skip to content

[codex] Fix stop-loss price basis#61

Merged
sdcoffey merged 14 commits into
codex/go-1.21from
codex/fix-stop-loss
May 29, 2026
Merged

[codex] Fix stop-loss price basis#61
sdcoffey merged 14 commits into
codex/go-1.21from
codex/fix-stop-loss

Conversation

@sdcoffey

@sdcoffey sdcoffey commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • compare stop-loss movement against the entry unit price instead of total cost basis
  • handle short positions with the inverse price move
  • add regression coverage for non-unit order amounts and shorts

Related issues

Fixes #8.

Validation

  • GOCACHE=/private/tmp/techan-gocache mise x go@1.26.3 -- go test ./...

Stacked on #60.

@sdcoffey sdcoffey marked this pull request as ready for review May 29, 2026 15:28
@sdcoffey

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f1be15cf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rule_stop.go Outdated

loss := currentPrice.Div(entryPrice).Sub(big.ONE)
if entryOrder.Side == SELL {
loss = entryPrice.Div(currentPrice).Sub(big.ONE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Trigger short stop losses at the configured percentage

For short positions, this computes the loss as entryPrice/currentPrice - 1, which uses the current price as the denominator instead of the entry price. With a short entered at 100 and a -5% tolerance, a close at 105 should satisfy the rule because the loss is 5% of entry, but this formula yields about -4.76% and does not trigger until roughly 105.26, delaying stop-loss exits for shorts.

Useful? React with 👍 / 👎.

@sdcoffey sdcoffey force-pushed the codex/fix-stop-loss branch from 1f1be15 to 0abd685 Compare May 29, 2026 15:42
sdcoffey added 5 commits May 29, 2026 08:44
[codex] Make indicator test helper vet-safe
[codex] Document indicator warm-up behavior
[codex] Add indicator cache invalidation
[codex] Guard trendline slope for sparse windows
@sdcoffey sdcoffey merged commit 5ba44cb into codex/go-1.21 May 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant