APIError: trade denied due to pattern day trading protection

I have a program that buys a stock at market open and sells it at market close daily. When I ran it today, I get an error when I sell a stock with the API. It says

APIError: trade denied due to pattern day trading protection

Where can I get more detail of this error? Is there a reference doc?

I found that this is related to " Pattern Day Trader (PDT) Protection".

Alpaca Trading platform monitors the number of day trades for the account for the past 5 business days and rejects a newly submitted orders on exit of a position if it could potentially result in the account being flagged for PDT. This protection triggers only when the previous day’s closing account equity is less than $25,000 at the time of order submission.

More details here - https://docs.alpaca.markets/user-protections/

2 Likes

It’s a legal restriction that all brokers have to check for, though some seem to implement it differently. IB will still let you close positions if you’ve been flagged for PDT, even if your account balance is below $25k. If you’re funded above that, it’s a non-issue regardless.

2 Likes

I accidentally triggered the PDT rule and I can’t buy anything. I get the error: “Failed to submit order,
entry denied due to pattern day trading.” How long will this restriction last?

1 Like

Let us look into your case. Seems like there was invalid day trader call.

Could you look into my case as well please? I think I’ve also been hit with an invalid day trader call

Thanks

Hello, I am receiving this error when trying to sell a stock. It still lets me buy stocks over the API but not sell any and getting the error APIError: trade denied due to pattern day trading protection. Could someone please take a look at my account and confirm? Thank you :slight_smile:

@Dan_Whitnable_Alpaca according to the Pattern Day Trader (PDT) Protection at Alpaca, the rule only applies if the account equity is less than $25,000 at the time of order submission.

What is meant by account equity? Is this the “Buying Power” shown in my Alpaca dashboard? Is there an endpoint to check my account equity so I can query that before making my order?

@bennycode You are correct that only accounts with a previous end of day equity less than $25,000 have the PDT protections applied. It’s not at the time of order submission but rather at market close the previous day.

Equity is effectively the cash one would have if one liquidated all their holdings and paid back any funds borrowed on margin. It’s the current net value of one’s account. The previous EOD equity can be fetched in the account object as the attribute account.last_equity. For the purposes the PDT check, this is also reduced by the value of any crypto holdings (which aren’t marginable) so the check is really the “previous EOD securities equity” which needs to be greater than $25,000.

Does that help?

Thanks, Dan! The info about account.last_equity is very helpful. I just queried it and now I’m trying to match this number by checking Alpaca’s Dashboard. It seems that if I take the previous day’s “Market Value” of all my assets and subtract the “Cash” balance (which is negative in my case), I arrive at the same number. Is that correct?

@bennycode The calculation which you did is shown below:

equity = market_value + cash

This works if you do not hold any short positions. That’s because negative cash reflects the amount you have borrowed on margin. Equity is effectively the cash one would have if one liquidated all their holdings and paid back any funds borrowed on margin, which is what the formula is doing.

The reason it doesn’t work if any positions are short is because, when shorting, one sells before one buys. Sells always increase cash and buys always decrease cash. So, if one sells a stock short for $10,000 the account cash will increase by $10,000. That messes up the equity calculation. Because of this, there isn’t any general way to calculate equity. Simply use the equity provided by the API.

1 Like

Thanks for this very clear and detailed answer. I will use the exposed API value from now on. :pray:

I am getting the same error , while i am using paper trading and I am afraid the same might happen when I apply code to live trading .
I am buying and selling a stock , below are the specification:

I am trading only Buy and sell only (No short selling at all)

Trading parameters

STOP_LOSS_PERCENTAGE = 7.0 # 1% stop loss
TAKE_PROFIT_PERCENTAGE = 5.0 # 1% take profit
TRADE_AMOUNT = 100 # Fixed trade amount in USD
CHECK_INTERVAL = 15 # Interval to check and execute trading logic in seconds

allocated_budget = 500 # Allocated budget for trading

here is my paper trading ID
image

Dear Whitnable and Alpaca users

Hi doings well

Kindly help me with a sorrow and permanent technical problem with my trading I facing a very panic issue that more than 4 to 5 months my trading is with all investment platforms is stopping I can’t work with investment platform due to having a technical issue I sent email to islamicly application informed me the issue can’t buying and selling and exact issue with error in confirming orders not happen from islamicly site and I sent to Alpaca also saying this issue happening from islamicly believe me due to this problem I don’t know what Iam to do so please help when I go to the islamicly platform I want sell or buy any stocks it saying me error in confirming orders