Skip to content

Implementing stop loss and take profit orders #66

Answered by sjhermanek
sjhermanek asked this question in Q&A
Discussion options

You must be logged in to vote

Sounds good. I'm excited for this feature to land in the future! In the meantime, I've decided to give this a bit of a go myself, aka a poor-man's version of it.
The basic premise of my approach is to assemble a book of open positions from most recent trade's, and pass those around in variables. Below, you can find some pseudo-code:

Trades

variables["trades"][state.time] = {DIRECTION_OF_TRADE, symbol, order_size, interface.get_price(symbol))
## DIRECTION_OF_TRADE will be in `BUY`, `SELL`, or `HOLD` in my logic.

Book

variables["book"][state.time] = {symbol, qty_held, last_trade, qty_considered, avg_acquisition_price}
## In here, I process trades from most recent to least recent, increment…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@EmersonDove
Comment options

@sjhermanek
Comment options

@EmersonDove
Comment options

Answer selected by EmersonDove
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants