TheDrivenTrader

Risk Management: Position Size & Risk Reward

Here is a Risk Management Indicator that calculates stop loss and position sizing based on the volatility of the stock. Most traders use a basic 1 or 2% Risk Rule, where they will not risk more than 1 or 2% of their capital on any one trade. I went further and applied four levels of risk: 0.25%, 0.50%, 1% and 2%. How you apply these different levels of risk is what makes this indicator extremely useful. Here are some common ways to apply this script:
• If the stock is extremely volatile and has a better than 50% chance of hitting the stop loss, then risk only 0.25% of your capital on that trade.
• If a stock has low volatility and has less than 20% change of hitting the stop loss, then risk 2% of your capital on that trade.
• Risking anywhere between 0.25% and 2% is purely based on your intuition and assessment of the market.
• If you are on a losing streak and you want to cut back on your position sizing, then lowering the Risk % can help you weather the storm.
• If you are on a winning streak and your entries are experiencing a higher level of success, then gradually increase the Risk % to reap bigger profits.
• If you want to trade outside the noise of the market or take on more noise/risk, you can adjust the ATR Factor.
• … and whatever else you can imagine using it to benefit your trading.

The position size is calculated using the Capital and Risk % fields, which is the percentage of your total trading capital (a.k.a net liquidity or Capital at Risk). If you instead want to calculate the position size based on a specific amount of money, then enter the amount in the Custom Risk Amt input box. Any amount greater than 0 in the Custom Risk Amt field will override the values in the Capital and Risk % fields.

The stop loss is calculated by using the ATR. The default setting is the 14 RMA, but you can change the length and smoothing of the true range moving average to your liking. Selecting a different length and smoothing affects the stop loss and position size, so choose these values very carefully.

The ATR Factor is a multiplier of the ATR. The ATR Factor can be used to adjust the stop loss and move it outside of the market noise. For the more volatile stock, increase the factor to lower the stop loss and reduce the chance of getting stopped out. For stocks with less volatility , you can lower the factor to raise the stop loss and increase position size. Adjusting the ATR Factor can also be useful when you want the stop loss to be at or below key levels of support.

The Market Session is the hours the market is open. The Market Session only affects the Opening Range Breakout (ORB) option, so it’s important to change these values if you’re trading the ORB and you’re outside of Eastern Standard Time or you’re trading in a foreign exchange.

The ORB is a bonus to the script. When enabled, the indicator will only appear in the first green candle of the day (09:30:00 or 09:30 AM EST or the start time specified in Market Session). When using the ORB, the stop loss is based on the spread of the first candle at the Open. The spread is the difference between the High and Low of the green candle. On 1-day or higher timeframes, the indicator will be the spread of the last (or current) candle.

The output of the indicator is a label overlaying the chart:
1. ATR (14 RMA x2) – This indicated that the stop loss is determined by the ATR. The x2 is the ATR Factor. If ORB is selected, then the first line will show SPREAD, instead of ATR.
2. Capital – This is your total capital or capital at risk.
3. Risk X% of Capital – The amount you’re risking on a % of the Capital. If a Custom Risk Amt is entered, then Risk Amount will be shown in place of Capital and Risk % of Capital.
4. Entry – The current price.
5. Stop Loss – The stop loss price.
6. -1R – The stop loss price and the amount that will be lost of the stop loss is hit.
7. – These are the target prices, or levels where you will want to take profit.

This script is primarily meant for people who are new to active trading and who are looking for a sound risk management strategy based on market volatility . This script can also be used by the more experienced trader who is using a similar system, but also wants to see it applied as an indicator on TradingView. I’m looking forward to maintaining this script and making it better in future revisions. If you want to include or change anything you believe will be a good change or feature, then please contact me in TradingView.
הערות שחרור: You can now enter a specific stop price. The position size will be based on the spread between the close (or entry) and the Stop Price.
הערות שחרור: When trading based on risk/reward, you might prefer to take profit when the stock reaches a certain percentage increase. If you want to make 5% of the money you spent buying the stock (cost basis), then the stock will need to increase by 5% from your entry price. For example, a 1.00 entry will need to hit 1.05 for you to make 5%. If you bought 1000 shares of this 1.00 stock, then you will make 50.00 when the price hits 1.05.

If you prefer to use percentage of your cost basis to determine the price targets, then this update is for you! The updated script will show you price targets set at 1%, 5%, 10% and 20% of the cost basis. The script also allows you to enter a custom percentage, in case you want to know the target price for a specific percentage of the cost basis. If you select 'Show price targets of cost basis' and enter an amount greater than 0.0 in the 'Percentage Of Cost Basis' field, then the label will show the price target for that percentage.

Other changes:
- Renamed Targets to Price Targets.
- Removed the -1R line, since it was the same as the Stop Loss.
הערות שחרור: Major revamp of the dialog box! I've utilized the new features of Pine Script to make the dialog box more intuitive and user friendly. The update includes tooltips to explain the purpose of individual fields, headers to group input fields, and inlining ATR fields to save space. In addition to updating to the dialog box, I've made the following changes:

- Rounded positionSize variable, so that all risk and price target calculations are consistent.
- Added 'Cost Basis' line to the label, in order to show what it will cost if you were to buy using stated position size and current price.
- Changed 'Entry' to 'Current Price' in the label.

Although it wasn't my intention to write this script solely for buyers, I do realize this limitation and I plan to update the script so that it can also be used by short sellers. Keep an eye on the next update!
הערות שחרור: Now short sellers can use the Risk Management script to calculate position size and price targets when going short. When you select 'Are you short selling?' option in the dialog box, the label will change to the following:
  • Label color will turn red
  • Stop loss will be above the current price
  • Price targets will be below the current price

When choosing to short, the Price target can go no lower than 0.00. If that's the case, then the profit at 0.00 will be shown.

Also, the script now has an error condition to check if custom stop loss is greater than the current price for short and less than the current price when long. Price targets will not show when this error condition returns true.

This script is now in its fifth and almost final revision. Pine script doesn't provide the ability to do any unit testing, so adding more functionality will make the script unwieldy and more difficult to maintain. I'm planning to remove the Opening Range Breakout feature in the next revision, in order to improve the maintainability of the code. However, add a comment below to let me know if this is something you would like to keep in the script.
הערות שחרור: Detached Risk Management label from the last price bar and moved it to the bottom right of the chart screen, while will allow you to focus more on the price action and other indicators.
סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר סקריפט זה פרסם אותו עם קוד פתוח, כך שסוחרים יוכלו להבין ולאמת זאת. הידד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום הנו בכפוף ל כללי הבית . אתה יכול להגדירו כמועדף ולהשתמש בו בגרף.

רוצה להשתמש בסקריפ זה בגרף?

תגובות

best risk management indicator
+2 השב
This could be used as a back testing tool if you could add the current price manually too. Thank you for you time and effort, great tool for automated calculations.
+1 השב
great RR indicator, congrats, could you add a short version too?
+1 השב
Kerasi Kerasi
@Kerasi, oops, I just saw the last line!
השב
@Kerasi, Version 5 of the script includes the short version. Let me know if there's something else you think would be a good addition to the script. Thanks!
השב
Kerasi TheDrivenTrader
@TheDrivenTrader, Superb, congratulations and thank you for your work/script.
השב
You saved my portfolio. Thank you. I could not figure out my risk/reward ratio for the life of me. Amd I know how to do it myself with the tools but could not figure out the right settings for weeks til I came across a you miraculous indicator. Thanks man. Cheers!
+1 השב
TheDrivenTrader SuperxSaiyanxSenku
@SuperxSaiyanxSenku, Thank you! I'm glad the script is helping.
השב
it would be great if you could add futures as well. The position size and the levels are different in Futures market.
Thanks in advance
השב
@MAGLN5, I don't trade Futures, but I'll definitely take a look at the difference in position sizing and I'll add it in a future update.
השב