longPosition
The Long Position tool is a risk–reward projection used when you expect the market to move upward. It marks your entry, stop-loss, and take-profit zones on the chart. This helps you visualize trade management and backtest position sizing.
Syntax
longPosition(time, price, styles?)
Parameters
time (number) · The bar time where the position starts.
price (number) · The entry price for the long trade.
styles (PositionToolOverrides) · Visual and risk management settings:
stopLevel(number) · Distance from entry down to stop-loss (in price units).targetLevel(number) · Distance from entry up to take-profit (in price units).riskReward(boolean) · Show the risk/reward ratio on chart.fillBackground(boolean) · Fill the long position area.transparency(number) · Background transparency (0–100).line(LinesLevels without coeff) · Style for borders (linestyle,linewidth,color).background(RGBAColor | BaseColors) · Fill color for the projection zone.
Return Value
(string) · The drawing ID of the created Long Position.
Example
Every 50 candles, place a long position starting at a recent low with defined stop-loss and target.
Tips
Use recent swing lows as logical stops for your long entries.
Adjust
targetLevelandstopLevelto maintain a good risk/reward ratio (e.g., 2:1 or higher).Great for backtesting trade management strategies.
Warning
Don’t set stop or target levels too close to the entry; natural price noise might trigger them prematurely.
Good Practice
Keep consistent color schemes for long (green) and short (red) positions so they’re easy to identify.
Always validate your risk/reward settings against historical volatility.
Last updated