Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate on buy/sale logic #180

Closed
14 of 19 tasks
mold opened this issue Jan 13, 2023 · 0 comments · Fixed by #186
Closed
14 of 19 tasks

Iterate on buy/sale logic #180

mold opened this issue Jan 13, 2023 · 0 comments · Fixed by #186
Assignees

Comments

@mold
Copy link
Contributor

mold commented Jan 13, 2023

JAWS - buy and sell

Check [x] means checked, not guaranteed by tests :)

BUY

  • Buy when the ticker hits breakout level (set price) from Sharkster during the current day.
  • Buy up to 10% of total asset value.
  • Buy with Alpaca Stop order

SELL RULES

All sales should be done with a Stop Limit Order. limit_price according to the rules, stop_price = x% (TBD) above limit_price. A position should always have an open order to sell according to our rules.

When transitioning from stop loss 1 => 2 => take profit, we should patch the current Stop Limit Order in Alpaca and let them keep track of the market automatically. We only need to update the limit_price and stop_price according to our rules. EDIT: Not needed since we keep track of this ourselves, i.e. we don't have any long-lived sell orders in Alpaca but check market value and compare to entry price continuously.

Stop loss case (1)

  • If stock is down 0,5%* of total assets (invested + cash balance) => SELL 100% of position
  • check constantly, via Alpaca?

Stop loss case (2)** (#185)

  • If stock is above breakout level (entry price) next day set breakeven (entry price) as stop loss and SELL 100% of position
  • Start checking day after purchase before markets open. Then check constantly, via Alpaca?

Stop loss (3) SELL! Take profit

When ticker price is above breakeven level, set MA 10 as trailing stop loss, meaning check every day before open of market and set stop at MA 10 and SELL 100% of position

  • Start checking day after purchase before markets open
  • When above breakeven level set MA 10 as take-profit (sell level)
  • Sell 100% when stock hits take-profit
  • Allow selling for lower price if needed when stock hits take-profit to make sure we get rid of everything (i.e. sell with Market Order rather than stop limit.

Take partial profit

If stock is up with 10%*** from buy level => sell 50%**** of position. Use SELL! Take profit (1) for the rest of the position, I.e the trailing MA 10 SELL rule and check /change before open every day.

Needs to done manually since Alpaca can't have multiple orders with different quantity.

  • Check continuously during the day (poll Alpaca?)
  • If >10%, cancel current sell order, sell 50% at market price (?)
  • set new sell order according to Take profit (1)

Further improvements


*make this possible to change number of percent
**Make this optional
***Make this dynamic and possible to change percentage or number of days
****Make this possible to change number of percent
*****Make this possible to change how long the order is valid from open of markets (1h, intraday etc)

Check later

  • Start tracking MA 10 on day 1?
@mold mold added this to the Transparent, working algorithm milestone Jan 13, 2023
@mold mold added the more info needed Needs additional information or a description of what's to be done label Jan 13, 2023
@mold mold changed the title Iterate on sale logic Iterate on buy/sale logic Jan 13, 2023
@mold mold self-assigned this Jan 13, 2023
@mold mold removed the more info needed Needs additional information or a description of what's to be done label Jan 13, 2023
@mold mold linked a pull request Jan 20, 2023 that will close this issue
@mold mold closed this as completed in #186 Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant