OPEN-SOURCE SCRIPT
تم تحديثه Global Position Sizing (R Based)

Description:
Managing risk across different global markets, currencies, and timeframes can be a mathematical headache. The Global Position Sizing (R Based) indicator is designed to streamline this process, allowing you to focus on the trade setup rather than the calculator.
Built for traders who use fixed fractional risk (R-multiples), this open-source tool automatically calculates exactly how many shares you should buy based on your predefined risk, current exchange rates, and the specific stop-loss distance of your setup.
Whether you are trading US tech stocks, Indian equities, or Japanese indices, this indicator will automatically detect the active ticker's currency, pull live conversion rates, and seamlessly adjust your risk profile.




Key Features:
• Auto-Currency Detection & Conversion: No manual input is needed when switching between international assets. The script reads the chart's native currency automatically and uses native request.currency_rate logic to instantly convert your Base Risk (USD) into the Target Currency.
• Global Currency Support: The UI features custom symbol formatting for major markets, natively displaying USD (), CNY (¥), JPY (¥), KRW (₩), TWD (NT), and INR (₹). For all other global markets (such as EUR, GBP, AUD, CAD, etc.), the script features a smart fallback that simply displays the standard 3-letter currency code.
• Dynamic Timeframe Multipliers: Automatically scales your risk based on the chart timeframe. By default, it applies a 1.0x multiplier for Daily setups and scales up to a 2.5x multiplier for higher-conviction Weekly or Monthly setups. You can also easily override this with a custom multiplier in the settings.
• Smart Entry & Stop Loss Detection: If left at 0.0, the script automatically detects the current price (close) as your Entry and the current candle's low (low) as your Stop Loss. You can override these with specific manual price points for pending setups.
• Volatility Warning System (SL vs. ATR): The script calculates your Stop Loss distance as a percentage and compares it against the Average True Range (ATR %) of the asset. If your proposed SL % is wider than the ATR %, the row will highlight RED, warning you that your risk parameter is unusually wide for the asset's current volatility. ATR length is fully customizable (default 14 days).
• Modular & Clean UI: A highly customizable display widget that doesn't clutter your chart. • Toggle individual rows on or off (e.g., hide the exchange rate or ATR if you only want to see the final share count). • Anchor the widget to any of the 9 standard chart positions. • Adjust the custom "Margin Offset (%)" to push the widget away from the edges of your screen for a perfectly clean layout.
How to Use:
1. Open the indicator settings and set your Daily R (Base USD). This is your standard risk unit per trade.
2. When evaluating a setup, either let the script auto-detect the current price/low, or enter your specific Entry and Stop Loss prices.
3. The widget will instantly calculate your risk in the local currency, compare your stop distance to the ATR, and output the exact number of shares to buy.
Note: This script is open-source and intended for educational and workflow optimization purposes. Always double-check position sizes and exchange rates before executing live trades.
Managing risk across different global markets, currencies, and timeframes can be a mathematical headache. The Global Position Sizing (R Based) indicator is designed to streamline this process, allowing you to focus on the trade setup rather than the calculator.
Built for traders who use fixed fractional risk (R-multiples), this open-source tool automatically calculates exactly how many shares you should buy based on your predefined risk, current exchange rates, and the specific stop-loss distance of your setup.
Whether you are trading US tech stocks, Indian equities, or Japanese indices, this indicator will automatically detect the active ticker's currency, pull live conversion rates, and seamlessly adjust your risk profile.
Key Features:
• Auto-Currency Detection & Conversion: No manual input is needed when switching between international assets. The script reads the chart's native currency automatically and uses native request.currency_rate logic to instantly convert your Base Risk (USD) into the Target Currency.
• Global Currency Support: The UI features custom symbol formatting for major markets, natively displaying USD (), CNY (¥), JPY (¥), KRW (₩), TWD (NT), and INR (₹). For all other global markets (such as EUR, GBP, AUD, CAD, etc.), the script features a smart fallback that simply displays the standard 3-letter currency code.
• Dynamic Timeframe Multipliers: Automatically scales your risk based on the chart timeframe. By default, it applies a 1.0x multiplier for Daily setups and scales up to a 2.5x multiplier for higher-conviction Weekly or Monthly setups. You can also easily override this with a custom multiplier in the settings.
• Smart Entry & Stop Loss Detection: If left at 0.0, the script automatically detects the current price (close) as your Entry and the current candle's low (low) as your Stop Loss. You can override these with specific manual price points for pending setups.
• Volatility Warning System (SL vs. ATR): The script calculates your Stop Loss distance as a percentage and compares it against the Average True Range (ATR %) of the asset. If your proposed SL % is wider than the ATR %, the row will highlight RED, warning you that your risk parameter is unusually wide for the asset's current volatility. ATR length is fully customizable (default 14 days).
• Modular & Clean UI: A highly customizable display widget that doesn't clutter your chart. • Toggle individual rows on or off (e.g., hide the exchange rate or ATR if you only want to see the final share count). • Anchor the widget to any of the 9 standard chart positions. • Adjust the custom "Margin Offset (%)" to push the widget away from the edges of your screen for a perfectly clean layout.
How to Use:
1. Open the indicator settings and set your Daily R (Base USD). This is your standard risk unit per trade.
2. When evaluating a setup, either let the script auto-detect the current price/low, or enter your specific Entry and Stop Loss prices.
3. The widget will instantly calculate your risk in the local currency, compare your stop distance to the ATR, and output the exact number of shares to buy.
Note: This script is open-source and intended for educational and workflow optimization purposes. Always double-check position sizes and exchange rates before executing live trades.
ملاحظات الأخبار
Rewrote some parts of the indicator for performance improvement and added more settings for widget display, color customizations.ملاحظات الأخبار
Added the below enhancements:1. Display position size in both base and target currencies
2. Display the Entry and SL lines with labels for more intuitive screenshotting purposes.
3. Dynamic ATR% calculation for various timeframes.
ملاحظات الأخبار
Added sector and industry to the tableملاحظات الأخبار
Added support for more currencies and default location is now bottom center.ملاحظات الأخبار
Added logic to allow user to choose various SL types: Candle's low, Day's Low, 20 MA, Smart Algo that selects appropriate SL based on threshold percentage.ملاحظات الأخبار
Defaulting to Smart SL Algoملاحظات الأخبار
Added options to set SL on Low of previous bar or previous day.ملاحظات الأخبار
Added option to select the recent swing low as SL value. Uses a rolling window (default to 10 previous bars) to find the correct anchor point.ملاحظات الأخبار
Added the below enhancements:- Extended default daily R values till 5K USD
- Ability to specify custom daily R value (if value is not part of default options)
- Reordered Entry and SL options to be more intuitive
- Ability to specify entry price options (Auto (Current Price), High of Day, High of Bar, etc).
ملاحظات الأخبار
Added "Recent Swing High" as a new entry price modeAdded "Low of Previous Day" as a new stop price mode
ملاحظات الأخبار
Cosmetic updateملاحظات الأخبار
Changes & Updates implemented today:1. Generalized Moving Average (MA) Stop Loss Support
- Replaced the static 20 SMA options with a dynamic, generic MA system.
- Added Stop Loss MA Type input to select between SMA and EMA.
- Added Stop Loss MA Length input to specify any lookback period (default 20).
- Optimized the calculation structure so both SMA and EMA are computed on every bar, avoiding calculation gaps in Pine Script's historical series state.
- 2. Added Detailed Tooltips & Explanations
- Entry Price Mode Tooltip: Added context explaining the default Current Close (immediate market orders) versus conditional stop orders (Current Bar High, HOD, Recent Swing High) designed for planning breakout entries.
- Stop Loss Mode Tooltip: Summarizes each stop loss option including Current Bar Low, LOD, LOPD, Recent Swing Low, MA, and LOD or MA (Smart).
- MA Type & MA Length Tooltips: Explains how these fields govern the stop loss moving average type and period.
ملاحظات الأخبار
Dummy checkin to update chartملاحظات الأخبار
TradingView Global Position Sizing Indicator - Daily Changes SummaryToday's updates introduce support for adaptive multi-timeframe stop losses, resolve intraday session calculation anomalies, and correct the conditional selection logic in the Smart Stop Loss feature to guarantee a safety-first wider stop.
Major Updates & Bug Fixes
1. Dynamic "Previous Candle Low" & Intraday Calculation Fixes
- Timeframe-Adaptive Stop Loss: Renamed the stop loss option to "Previous Candle Low" in the indicator script. The stop loss price now automatically adapts to the chart's timeframe, dynamically shifting to the Previous Week's Low (LOPW) on weekly charts, Previous Month's Low (LOPM) on monthly charts, and Previous Daily Low (LOPD) on daily/intraday charts.
- Lookahead-Free Intraday Session Tracking: Replaced standard security calls for intraday High/Low tracking with dynamic time-check session calculations to prevent chart lookahead/lag anomalies.
- Lookahead-Safe LOPD Security Request: Fixed the intraday Previous Daily Low lookup by requesting the daily low of the previous day with lookahead explicitly enabled, ensuring safe historical values are fetched without future-data leaks.
- Tooltip and Documentation Alignment: Refreshed input option descriptions and indicator tooltips in the code settings and user documentation to reflect the new dynamic logic.
2. Smart Stop Loss Logic Correction
- Safety-First Stop Loss Selection: Corrected the selection logic in the "LOD or MA (Smart)" Stop Loss Mode. Previously, the moving average was selected unconditionally if it fell within the proximity threshold. We added a check to verify that the moving average price is actually lower (wider) than the Low of Day before choosing it over the LOD.
- Updated Formulas in Documentation: Updated mathematical formulas in the repository documentation to reflect the corrected conditional algorithm.
ملاحظات الأخبار
TradingView Global Position Sizing Indicator - Recent Changes Summary (Last 2 Hours)The updates completed over the last two hours introduce an advanced risk management tracker to the indicator's dashboard and resolve type-safety compilation issues:
Major Updates & Bug Fixes
- Dynamic Final R Value Dashboard Row: Added a permanent "Final R Value" row to the statistics table. This row provides real-time visibility into the exact risk in local currency, target currency exceedance over planned risk, and the extra R-multiple.
- Configurable Risk Tolerance Warning: Introduced an "R Risk Tolerance (%)" input field. If a user's custom stop-loss or entry deviates from the auto-calculated level beyond this tolerance percentage, the dashboard row highlights in warning red with bold white text.
- Compiler Error Resolution: Fixed several Pine Script compilation errors (CE10222, CE10173, and CE10272) related to mismatched parameter names, constants, and type checks to ensure smooth deployment.
- Formulas and Documentation Update: Documented the mathematical formulas for the stop-loss deviation percentage and the warning threshold trigger conditions in the reference files.
ملاحظات الأخبار
Global Position Sizing Indicator - Volatility-Based Stops and Input ReorganizationOverview of Changes
Today's updates introduce new volatility-based Stop Loss options (ATR% and ADR%) and complete a major clean-up and reorganization of the indicator settings menu.
New Features and Enhancements
- Volatility-Based Stop Loss Options: Added support for ATR% and ADR% as Stop Loss price modes.
- ADR% Formula Update: The Average Daily Range percentage (ADR%) is now calculated dynamically from the daily timeframe using the high/low ratio formula:
Pine Script® - ATR/ADR SL Multiplier: Renamed the volatility multiplier to ATR/ADR SL Multiplier for clearer context.
- Logical Settings Reorganization: Regrouped the entire input menu into specific, logical sections:
- Risk Management (Base Risk, daily R selection)
- Trade Entry Settings (Entry modes and lookback)
- Stop Loss Settings (Stop loss mode and lookback)
- Volatility Stop Settings (ATR/ADR lengths and multiplier)
- Moving Average Stop Settings (MA type, length, and Smart tolerance)
- Dashboard Updates: Added an ADR % toggle and row in the dashboard table widget, positioned directly adjacent to ATR % to keep volatility metrics together.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.