Sizing Trades by Stop Distance and Canceling Limit Orders
Summary
This strategy test explores two implementation problems in TradingView Pine Script: canceling a pending limit order and calculating position size from a chosen dollar risk amount, leverage, and prospective entry and stop prices. The described example uses an inside-bar setup. Its sizing logic starts with the distance between entry and stop, expresses that distance as a percentage, then uses the risk and leverage inputs to derive an order quantity for later use in the script.
The author presents the work as a troubleshooting exercise and a collection of potentially reusable code approaches, not as a finished strategy. An earlier version did not meet the author's setup requirements, and the revised approach was still awaiting further testing. The document provides no performance results or validation of the sizing method across instruments, fee structures, or execution conditions, so its practical value is chiefly as an implementation concept to review and test.
Key ideas
- The example investigates how to cancel an unfilled limit order in a strategy script.
- Position size is derived from the planned entry-to-stop distance and a user-selected dollar risk amount.
- The described setup uses an inside-bar candle pattern to define possible entry and stop levels.
- Leverage is included as an input to the quantity calculation.
- The author describes the code as unfinished and provides no performance evidence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.