Wash trade error

So I’m getting the wash trade error on my sell order:
"potential wash trade detected. use complex orders","reject_reason":"opposite side market/stop order exists"}

I’m showing my Tradingview pinescript code below and asking if I’m doing the TP and SL sells incorrectly?

// ——— Long Entry ———
if buyCondition and strategy.position_size == 0
strategy.entry(“Long Entry”, strategy.long)

// If in a long trade, define stop/limit exit prices
if strategy.position_size > 0
stopLossPrice = strategy.position_avg_price * (1 - stopLossPerc / 100)
takeProfitPrice = strategy.position_avg_price * (1 + takeProfitPerc / 100)
// Submit exit orders (SL + TP)
strategy.exit(“Exit Long”,
from_entry = “Long Entry”,
stop = stopLossPrice,
limit = takeProfitPrice)

Are you doing live/paper trading?

While doing paper trading, I used to sometimes get this error and the issue was that I was not querying status of current order (and ensuring that it was filled), before sending the next one.

I am not sure if that would apply in your case, but it would be good to check the related discussion.

I’m doing paper trading.

Yes I am checking that I have a filled order before setting up the TP and SL via:
if strategy.position_size > 0

Bumped into this exact error today.
I looked at the web dashboard.
It showed I had a partial filled order… some percent filled and some percent as partially open.
To be clear: I have both a position and an open order.
I’ll try to code around this
Saturday ATM, so working on this with crypto, because I think we cannot put in bracket or trailing stop order on crypto
(Will work on a different strategy with regular U.S. stocks this coming week during market hours).