Skip to content

feat: add configurable target and stop-loss percentages#7

Merged
sreerevanth merged 2 commits into
sreerevanth:mainfrom
asgt2408:new_features
Jun 12, 2026
Merged

feat: add configurable target and stop-loss percentages#7
sreerevanth merged 2 commits into
sreerevanth:mainfrom
asgt2408:new_features

Conversation

@asgt2408

@asgt2408 asgt2408 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

feat: make target and stop-loss percentages configurable

Summary

This PR adds configurable Target % and Stop Loss % inputs to the Streamlit sidebar, allowing users to customize risk management settings without modifying source code.

Previously, target and stop-loss values were hardcoded in the ORB strategy:

  • Target = 1%
  • Stop Loss = 0.5%

With this change, users can adjust these values directly from the dashboard.


Changes Made

UI (Streamlit)

Added a new Risk Settings section in the sidebar:

  • Target %
  • Stop Loss %

Analysis Pipeline

Passed risk settings through:

app.py
 ↓
trader.py
 ↓
strategy.py

Strategy Logic

Updated target and stop-loss calculations to use user-defined percentages.

Previous implementation:

target = entry_price * 1.01
stop_loss = entry_price * 0.995

New implementation:

target = entry_price * (1 + target_percent / 100)
stop_loss = entry_price * (1 - stop_percent / 100)

Equivalent logic was applied for SELL signals.


Example

Current Defaults

Entry = 100

Target % = 1

Stop Loss % = 0.5

Result:

Target = 101
Stop = 99.5

Custom Settings

Entry = 100

Target % = 3

Stop Loss % = 1

Result:

Target = 103
Stop = 99
Screenshot 2026-06-11 at 23 02 53 ---

Benefits

  • Improves flexibility for different trading styles
  • Allows experimentation with various risk/reward settings
  • Preserves existing ORB signal generation logic
  • No source code modification required by end users

Testing

Tested with multiple symbols and verified:

  • Sidebar inputs update correctly
  • Signal cards reflect updated target/stop-loss values
  • Signal matrix updates dynamically
  • BUY and SELL calculations use configured percentages
  • Existing strategy flow remains unchanged

Closes #6

Summary by CodeRabbit

  • New Features

    • Added configurable "Target %" and "Stop Loss %" numeric inputs to the sidebar, allowing users to customize trading strategy parameters
    • Trading signal generation now uses user-configured target and stop loss percentages in calculations for each symbol analysis
  • Chores

    • Updated trade records with closed positions, including exit reasons (TARGET or STOP_LOSS) and realized performance metrics

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@asgt2408, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 55 minutes and 53 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 206aeb03-bb7b-4224-8f9d-b9c0e09ef455

📥 Commits

Reviewing files that changed from the base of the PR and between dd993d9 and 020be02.

📒 Files selected for processing (1)
  • app.py
📝 Walkthrough

Walkthrough

This PR implements configurable target and stop-loss risk percentages. Users select values from the Streamlit sidebar, which are passed through the analysis pipeline and used to calculate dynamic target and stop-loss price levels during trade signal generation.

Changes

Configurable Risk Percentages Pipeline

Layer / File(s) Summary
Sidebar risk configuration inputs
app.py
Two numeric input controls added to the sidebar for target_percent and stop_percent, each with bounded min/max ranges and step increments.
Parameter threading through analysis pipeline
app.py, trader.py
User-selected percentages are passed from _analyze_cachedanalyze_symbolscalculate_orb_signal to make them available to signal computation logic.
Percent-based target and stop-loss calculation
strategy.py
calculate_orb_signal and _action_signal now accept the percentage parameters and use them in percent-based formulas to compute dynamic target and stop-loss prices instead of fixed multipliers.
Trade data fixtures
data/trades.json
Existing trades are closed with exit reasons and realized PnL, and new sample trades are appended to reflect system behavior under different risk configurations.

Sequence Diagram

sequenceDiagram
  participant User as User
  participant UI as Sidebar UI
  participant AnalyzeCache as _analyze_cached
  participant AnalyzeSymbols as analyze_symbols
  participant CalcSignal as calculate_orb_signal
  participant ActionSignal as _action_signal
  participant TradeSignal as TradeSignal

  User->>UI: Select target_percent & stop_percent
  UI->>AnalyzeCache: Pass percentages with symbols
  AnalyzeCache->>AnalyzeSymbols: Forward target_percent, stop_percent
  AnalyzeSymbols->>CalcSignal: Call with target_percent, stop_percent
  CalcSignal->>ActionSignal: Forward percentages to BUY/SELL branch
  ActionSignal->>ActionSignal: Calculate target/stop_loss from percentages
  ActionSignal->>TradeSignal: Return configured target and stop_loss
  TradeSignal-->>User: Display dynamic price levels
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • sreerevanth/TRADEX#4: Both PRs thread user-configurable risk percentages through the strategy and signal generation path to compute SL/TP levels from percent inputs.

Suggested labels

VETERAN

Poem

🐰 A rabbit hops through sidebar lanes,
Where percentages now take the reins,
No hardcoding shackles, just numbers so free,
Target and stop-loss, configured with glee! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main feature addition: making target and stop-loss percentages configurable.
Linked Issues check ✅ Passed All requirements from issue #6 are met: sidebar inputs added, values propagated through pipeline, dynamic calculations implemented, and signal logic preserved.
Out of Scope Changes check ✅ Passed All changes directly support the configurable risk parameters feature; data file updates appear to be test/demo data consistent with the feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app.py (1)

98-98: ⚡ Quick win

Add spaces after commas for PEP 8 compliance.

The function call is missing spaces after commas.

📝 Proposed formatting fix
-        signals, charts, errors, trades, stats = _analyze_cached(tuple(symbols),target_percent,stop_percent)
+        signals, charts, errors, trades, stats = _analyze_cached(tuple(symbols), target_percent, stop_percent)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app.py` at line 98, The call to _analyze_cached is missing spaces after
commas (PEP8 formatting); update the call to include spaces after each comma
when passing arguments (symbols, target_percent, stop_percent) so it reads with
normal spacing and matches PEP 8 style around the tuple conversion and
subsequent arguments in the _analyze_cached(...) invocation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app.py`:
- Around line 192-193: The cached helper _analyze_cached currently omits type
hints and has spacing issues; update its signature (the function named
_analyze_cached) to include proper spacing and types for target_percent and
stop_percent (e.g. target_percent: float, stop_percent: float) and add a return
type annotation consistent with analyze_symbols' return (or use -> Any) so the
`@st.cache_data` cache key is generated correctly; keep the function body calling
analyze_symbols(list(symbols), target_percent, stop_percent) unchanged.

---

Nitpick comments:
In `@app.py`:
- Line 98: The call to _analyze_cached is missing spaces after commas (PEP8
formatting); update the call to include spaces after each comma when passing
arguments (symbols, target_percent, stop_percent) so it reads with normal
spacing and matches PEP 8 style around the tuple conversion and subsequent
arguments in the _analyze_cached(...) invocation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cf85bc47-1e2c-44f5-8547-6bc5fae6cbeb

📥 Commits

Reviewing files that changed from the base of the PR and between fb1e639 and dd993d9.

⛔ Files ignored due to path filters (7)
  • __pycache__/data_fetcher.cpython-314.pyc is excluded by !**/*.pyc
  • __pycache__/strategy.cpython-314.pyc is excluded by !**/*.pyc
  • __pycache__/symbol_resolver.cpython-314.pyc is excluded by !**/*.pyc
  • __pycache__/trade_tracker.cpython-314.pyc is excluded by !**/*.pyc
  • __pycache__/trader.cpython-314.pyc is excluded by !**/*.pyc
  • logs/trades.csv is excluded by !**/*.csv
  • logs/tradex.log is excluded by !**/*.log
📒 Files selected for processing (4)
  • app.py
  • data/trades.json
  • strategy.py
  • trader.py

Comment thread app.py
@asgt2408

Copy link
Copy Markdown
Contributor Author

Hi @sreerevanth ,

I've implemented the configurable target and stop-loss percentage feature and tested it locally. The values now update dynamically in the signal cards and signal matrix while keeping the existing ORB signal generation logic unchanged.

I'd appreciate any feedback or review when you have time. Thanks!

@sreerevanth sreerevanth merged commit 4b8cb81 into sreerevanth:main Jun 12, 2026
1 check passed
@asgt2408 asgt2408 deleted the new_features branch June 12, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make target and stop-loss percentages configurable from the sidebar

2 participants