OPEN-SOURCE SCRIPT
Adaptive Risk Management [sgbpulse]

1. Introduction:
Adaptive Risk Management is an advanced indicator designed to provide traders with a comprehensive risk management tool directly on the chart. Instead of relying on complex manual calculations, the indicator automates all critical steps of trade planning. It dynamically calculates the estimated Entry Price, the Stop Loss location, the required Position Size (Quantity) based on your capital and risk limits, and the three Take Profit targets based on your defined Reward/Risk ratios. The indicator displays all these essential data points clearly and visually on the chart, ensuring you always know the potential risk-reward profile of every trade.
2. The Critical Importance of Risk Management
Proper risk management is the cornerstone of successful trading. Consistent profitability in the market is impossible without rigorously defining risk limits.
3. Core Features, Adaptivity, and Customization
The Adaptive Risk Management [sgbpulse] indicator is engineered for use across all major trading styles, including Swing Trading, Intraday Trading, and Scalping, providing consistent risk control regardless of the chosen timeframe.
4. Intuitive Visualization and Real-Time Data
4.1. Data Window Metrics (16 Full Series)
The indicator displays 16 full data series in the TradingView Data Window, allowing precise tracking of every calculation parameter:
4.2. Instant Tracking in the Status Line
The indicator displays 6 critical parameters continuously in the indicator's Status Line: Estimated Entry, Quantity, Estimated Stop Loss, Estimated Take Profit 1/2/3.
5. Detailed Indicator Inputs
5.1 General
5.2 Intraday Session Data Control
Regular Hours Limitation : If enabled, all daily lookback calculations (for Entry/Stop Loss anchor points) will begin strictly from the first Regular Trading Hours (RTH) bar. This limits the lookback range to the current RTH session, excluding preceding Extended Trading Hours (ETH) data. Only relevant for Intraday charts. Default: False (Off)
5.3 Entry Inputs
Entry Method: Selects the entry price calculation method:
Lookback Bars: The number of bars used to calculate the extremes in the ATR-based entry methods (Relevant only for ATR Real Bodies Margin and ATR Bars Margin methods).
ATR Multiplier (Entry): The multiplier applied to the ATR value. The result of the multiplication is the calculated safety margin used to determine the estimated Entry Price.
5.4 Risk Inputs (Stop Loss)
Risk Method: Selects the Stop Loss price calculation method.
Lookback Bars: The lookback period for finding the extreme price used in the 'ATR Bars Margin' calculation.
ATR Multiplier (Risk): The multiplier applied to the ATR value. The result of the multiplication is the calculated safety margin used to place the estimated Stop Loss. Note: If set to 0, the Stop Loss will be placed exactly at the technical anchor point, provided the Minimum Margin Value is also 0.
Minimum Margin Value: The minimum price value (e.g., $0.01) the Stop Loss margin buffer must be.
Pivot (Left / Right): The number of bars required on either side of the pivot bar for confirmation (relevant only for the ATR Pivot Margin method).
5.5 Reward Inputs (Take Profit)
6. Indicator Status/Warning Messages
In situations where the Stop Loss location cannot be calculated logically and validly, often caused by a mismatch between the configured Focused Trend (Uptrend/Downtrend) and the actual price action, the indicator will display a warning message, explaining the reason and suggesting corrective action.
Status Message 1: Pivot reference unavailable
Condition: The Stop Loss is set to the "ATR Pivot Margin" method, but the anchor point (Pivot) is missing or inaccessible.
Message Displayed: "Pivot reference unavailable. Wait for valid price action, or adjust the Regular Hours Limitation setting or Pivot Left/Right inputs."
Status Message 2: Calculated Stop Loss is unsafe
Condition: The calculated Stop Loss is placed illogically or unsafely relative to the trend direction and the Entry price.
Message Displayed: "Calculated Stop Loss is unsafe for current trend. Wait for valid price action or adjust SL Lookback/Multiplier."
7. Summary
The Adaptive Risk Management [sgbpulse] (ARM) indicator provides a seamless and systematic approach to trade execution and risk control. By dynamically automating all critical trade parameters—from Entry Price and Stop Loss placement to Position Sizing and Take Profit targets—ARM removes emotional bias and ensures every trade adheres strictly to your predefined risk profile.
Key Benefits:
ARM [sgbpulse] allows traders to focus on strategy and analysis, confident that their execution complies with the core principles of professional risk management.
Important Note: Trading Risk
This indicator is intended for educational and informational purposes only and does not constitute investment advice or a recommendation for trading in any form whatsoever.
Trading in financial markets involves significant risk of capital loss. It is important to remember that past performance is not indicative of future results. All trading decisions are your sole responsibility. Never trade with money you cannot afford to lose.
Adaptive Risk Management is an advanced indicator designed to provide traders with a comprehensive risk management tool directly on the chart. Instead of relying on complex manual calculations, the indicator automates all critical steps of trade planning. It dynamically calculates the estimated Entry Price, the Stop Loss location, the required Position Size (Quantity) based on your capital and risk limits, and the three Take Profit targets based on your defined Reward/Risk ratios. The indicator displays all these essential data points clearly and visually on the chart, ensuring you always know the potential risk-reward profile of every trade.
ARM: The Adaptive Risk Management every trader needs to ARM themselves with.
2. The Critical Importance of Risk Management
Proper risk management is the cornerstone of successful trading. Consistent profitability in the market is impossible without rigorously defining risk limits.
- Risk Control: This starts by setting the maximum risk amount you are willing to lose in a single trade (Risk per Trade), and limiting the total capital allocated to the position (Max Capital per Trade).
- Defining Boundaries (Stop Loss & Take Profit): It is mandatory to define a technical Stop Loss and a Take Profit target. A fundamental rule of risk management is that the Reward/Risk Ratio (R/R) must be a minimum of 1:1.
3. Core Features, Adaptivity, and Customization
The Adaptive Risk Management [sgbpulse] indicator is engineered for use across all major trading styles, including Swing Trading, Intraday Trading, and Scalping, providing consistent risk control regardless of the chosen timeframe.
- Real-Time Dynamic Adaptivity: The indicator calculates all risk management parameters (Entry, Stop Loss, Quantity) dynamically with every new bar, thus adapting instantly to changing market conditions.
- Trend Direction Adjustment: Define the analysis direction (Long/Uptrend or Short/Downtrend).
- Intraday Session Data Control: Full control over whether lookback calculations will include data from Extended Trading Hours (ETH), or if the daily calculations will start actively only from the first bar of Regular Trading Hours (RTH).
- Status Validation: The indicator performs critical status checks and displays clear Warning Messages if risk conditions are not met.
4. Intuitive Visualization and Real-Time Data
- Dynamic Tracking Lines: The Entry Price and Stop Loss lines are updated with every new bar. Crucially, the length of these lines dynamically reflects the calculation's lookback range (e.g., the extent of Lookback Bars or the location of the confirmed Pivot Point), providing a visual anchor for the calculated price.
- Risk and Reward Zones: The indicator creates a graphical background fill between Entry and Stop Loss (marked with the risk color) and between Entry and the Reward Targets (marked with the reward color).
- Essential Information Labels: Labels are placed at the end of each line, providing critical data: Estimated Entry Price, Stock/Contract Quantity (Quantity), Total Entry Amount, Estimated Stop Loss, Risk per Share, Total Financial Risk (Risk Amount), Exit Amount, Estimated Take Profit 1/2/3, Reward/Risk Ratio 1/2/3, Total Reward 1/2/3, TP Exit Amount 1/2/3.
4.1. Data Window Metrics (16 Full Series)
The indicator displays 16 full data series in the TradingView Data Window, allowing precise tracking of every calculation parameter:
- Entry Data: Estimated Entry, Quantity, Entry Amount.
- Risk Data (Stop Loss): Estimated Stop Loss, Risk per Share, Risk Amount, Exit Amount.
- Reward Data (Take Profit): Estimated Take Profit 1/2/3, Reward/Risk Ratio 1/2/3, Total Reward 1/2/3, TP Exit Amount 1/2/3.
4.2. Instant Tracking in the Status Line
The indicator displays 6 critical parameters continuously in the indicator's Status Line: Estimated Entry, Quantity, Estimated Stop Loss, Estimated Take Profit 1/2/3.
5. Detailed Indicator Inputs
5.1 General
- Focused Trend: Defines the analysis direction (Uptrend / Downtrend).
- Max Capital per Trade: The maximum amount allocated to purchasing stocks/contracts (in account currency).
- Risk per Trade: The maximum amount the user is willing to risk in this single trade (in account currency).
- ATR Length: The lookback period for the Average True Range (ATR) calculation.
5.2 Intraday Session Data Control
Regular Hours Limitation : If enabled, all daily lookback calculations (for Entry/Stop Loss anchor points) will begin strictly from the first Regular Trading Hours (RTH) bar. This limits the lookback range to the current RTH session, excluding preceding Extended Trading Hours (ETH) data. Only relevant for Intraday charts. Default: False (Off)
5.3 Entry Inputs
Entry Method: Selects the entry price calculation method:
- Current Price: Uses the closing price of the current bar as the estimated entry point (Market Entry).
- ATR Real Bodies Margin:
- Uptrend: Calculates the Maximum Real Body over the lookback period + the calculated safety margin.
- Downtrend: Calculates the Minimum Real Body over the lookback period - the calculated safety margin. - ATR Bars Margin:
- Uptrend: Calculates the Maximum High price over the lookback period + the calculated safety margin.
- Downtrend: Calculates the Minimum Low price over the lookback period - the calculated safety margin.
Lookback Bars: The number of bars used to calculate the extremes in the ATR-based entry methods (Relevant only for ATR Real Bodies Margin and ATR Bars Margin methods).
ATR Multiplier (Entry): The multiplier applied to the ATR value. The result of the multiplication is the calculated safety margin used to determine the estimated Entry Price.
5.4 Risk Inputs (Stop Loss)
Risk Method: Selects the Stop Loss price calculation method.
- ATR Current Price Margin:
- Uptrend: Entry Price - the calculated safety margin.
- Downtrend: Entry Price + the calculated safety margin. - ATR Current Bar Margin:
- Uptrend: Current Bar's Low price - the calculated safety margin.
- Downtrend: Current Bar's High price + the calculated safety margin. - ATR Bars Margin:
- Uptrend: Lowest Low over lookback period - the calculated safety margin.
- Downtrend: Highest High over lookback period + the calculated safety margin. - ATR Pivot Margin:
- Uptrend: The first confirmed Pivot Low point - the calculated safety margin.
- Downtrend: The first confirmed Pivot High point + the calculated safety margin.
Lookback Bars: The lookback period for finding the extreme price used in the 'ATR Bars Margin' calculation.
ATR Multiplier (Risk): The multiplier applied to the ATR value. The result of the multiplication is the calculated safety margin used to place the estimated Stop Loss. Note: If set to 0, the Stop Loss will be placed exactly at the technical anchor point, provided the Minimum Margin Value is also 0.
Minimum Margin Value: The minimum price value (e.g., $0.01) the Stop Loss margin buffer must be.
Pivot (Left / Right): The number of bars required on either side of the pivot bar for confirmation (relevant only for the ATR Pivot Margin method).
5.5 Reward Inputs (Take Profit)
- Show Take Profit 1/2/3: ON/OFF switch to control the visibility of each Take Profit target.
- Reward/Risk Ratio 1/ 2/ 3: Defines the R/R ratio for the profit target. Must be ≥1.0.
6. Indicator Status/Warning Messages
In situations where the Stop Loss location cannot be calculated logically and validly, often caused by a mismatch between the configured Focused Trend (Uptrend/Downtrend) and the actual price action, the indicator will display a warning message, explaining the reason and suggesting corrective action.
Status Message 1: Pivot reference unavailable
Condition: The Stop Loss is set to the "ATR Pivot Margin" method, but the anchor point (Pivot) is missing or inaccessible.
Message Displayed: "Pivot reference unavailable. Wait for valid price action, or adjust the Regular Hours Limitation setting or Pivot Left/Right inputs."
Status Message 2: Calculated Stop Loss is unsafe
Condition: The calculated Stop Loss is placed illogically or unsafely relative to the trend direction and the Entry price.
Message Displayed: "Calculated Stop Loss is unsafe for current trend. Wait for valid price action or adjust SL Lookback/Multiplier."
7. Summary
The Adaptive Risk Management [sgbpulse] (ARM) indicator provides a seamless and systematic approach to trade execution and risk control. By dynamically automating all critical trade parameters—from Entry Price and Stop Loss placement to Position Sizing and Take Profit targets—ARM removes emotional bias and ensures every trade adheres strictly to your predefined risk profile.
Key Benefits:
- Systematic Risk Control: Strict enforcement of maximum capital allocation and risk per trade limits.
- Adaptivity: Dynamic calculation of prices and quantities based on real-time market data (ATR and Lookback).
- Clarity and Trust: Clear on-chart visualization, precise data metrics (16 series), and unambiguous Status/Warning Messages ensure transparency and reliability.
ARM [sgbpulse] allows traders to focus on strategy and analysis, confident that their execution complies with the core principles of professional risk management.
Important Note: Trading Risk
This indicator is intended for educational and informational purposes only and does not constitute investment advice or a recommendation for trading in any form whatsoever.
Trading in financial markets involves significant risk of capital loss. It is important to remember that past performance is not indicative of future results. All trading decisions are your sole responsibility. Never trade with money you cannot afford to lose.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.