I’m working on a Pine Script strategy for TradingView, and I’m encountering an error with my strategy.exit function. The error message is:
Here’s the relevant portion of my code:
[“`
// Execute trades based on the buy conditions for long and short positions if startLongTrade strategy.entry("Buy Long", strategy.long) strategy.exit("Take Profit Long", from_entry="Buy Long", limit=strategy.position_avg_price * (1 + takeProfitPercent), stop=strategy.position_avg_price * (1 - stopLossPercent)) strategy.exit("Trailing Stop Long", from_entry="Buy Long", trail_offset=strategy.position_avg_price * trailingStopPercent)
The issue is on the line with strategy.exit("Trailing Stop Long", from_entry="Buy Long", trail_offset=strategy.position_avg_price * trailingStopPercent).
My intention is to implement both a take profit and a trailing stop. How can I properly set up my strategy.exit calls to resolve this error and achieve the desired functionality?
Thank you for your help!
هاجر الى ربك is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.