Inputs are the intended entry price, desired risk (expressed as % of account at risk), account value, and leverage factor.
To use the script;
1. Identify and update the entry price (yellow line on the chart)
2. Update with desired risk
3. Update with account size
4. Adjust the leverage value until the stop loss (red line on chart for long positions, green line for short positions) reaches the desired value/location on the chart
The label will then update to show the required position size for the trade.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.