# Wash trade error

**URL:** <https://forum.alpaca.markets/t/wash-trade-error/16659>\
**Category:** Alpaca Trading\
**Created:** [April 4, 2025, 9:51am UTC](https://forum.alpaca.markets/t/wash-trade-error/16659 "2025-04-04T09:51:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralph\_Freshour](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/ralph_freshour/32/7124_2.png) [@Ralph\_Freshour](https://forum.alpaca.markets/u/Ralph_Freshour)\
**Post date:** [April 4, 2025, 9:51am UTC](https://forum.alpaca.markets/t/wash-trade-error/16659/1 "2025-04-04T09:51:46Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![sarahvignale](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sarahvignale](https://forum.alpaca.markets/u/sarahvignale)\
**Post date:** [April 4, 2025, 1:35pm UTC](https://forum.alpaca.markets/t/wash-trade-error/16659/2 "2025-04-04T13:35:55Z")

</div>

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](https://forum.alpaca.markets/t/protocol-for-sending-multi-legged-option-orders/16594).

---

<div class="post-metadata">

**Author:** ![Ralph\_Freshour](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/ralph_freshour/32/7124_2.png) [@Ralph\_Freshour](https://forum.alpaca.markets/u/Ralph_Freshour)\
**Post date:** [April 4, 2025, 1:52pm UTC](https://forum.alpaca.markets/t/wash-trade-error/16659/3 "2025-04-04T13:52:38Z")

</div>

> [@Ralph\_Freshour](#):
>
> if strategy.position\_size \> 0

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

---

<div class="post-metadata">

**Author:** ![StatsGuy](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@StatsGuy](https://forum.alpaca.markets/u/StatsGuy)\
**Post date:** [April 5, 2025, 2:21pm UTC](https://forum.alpaca.markets/t/wash-trade-error/16659/4 "2025-04-05T14:21:41Z")

</div>

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).
