Comments (5)
Nice catch. I'll fix it. Thank you
from jesse.
Thanks a lot,
self.position.entry_price
was the bad boy I was looking for.
I agree with you then... if self.position
is resuming all info about current position, then self.average_entry_price
should report only the average entry price of the last order.
I am closing the issue.
Thanks again
from jesse.
I worked on this for hours today. Turns out it's harder that I expected. The easy fix is to consider average_entry_price
as average of open orders. But I don't think that would be enough. How would that be in your use case?
from jesse.
For hours!!! I kinda feel sorry for having found the bug now 😅
Well, I'd say that average entry price is the weighted average of all the executed buy (sell) orders; and once the position is liquidate
d the average_entry_price
should be reset.
So let's say I do in sequence:
- in
go_long()
I do
qty = 0.5
self.buy = qty, self.price
- in
update_position
I do
qty = 0.7
self.buy = qty, self.price
- in
update_position
I do
qty = 0.9
self.buy = qty, self.price
Assuming all 3 buy orders are executed at market price, I expect average_entry_price
to be:
0.5 * marketPrice@1. + 0.7 * marketPrice@2. + 0.9 * marketPrice@3. / ( 0.5 + 0.7 + 0.9)
I annotated marketPrice@X.
and not self.price@1.
just so you know that I am aware of the fact that at the moment when jesse executes the order of type "MARKET" the market price can be different from self.price
The real point of average_entry_price
is the weighted average of all the entry prices times the quantities.
I am not sure how the average_entry_price
should be updated when you reduce the position 🤔
from jesse.
I'm sorry for the long delay.
Well, in your example you don't need average_entry_price
! You could simply use self.position.entry_price
.
So I guess I have more time to work on average_entry_price
in the future. The problem I found in it after digging into it, is that, it is currently returning the average of OPEN entry orders only. So if you do:
self.buy = [
(0.5, 6),
(0.5, 8),
]
average_entry_price
gives you 7 which is expected. But if you already have an open position let's say at:
self.buy = 1, 5
And then access in update_position do:
self.buy = [
(0.5, 6),
(0.5, 8),
]
No you might expect the average_entry_price
to be the average of all three prices weighted by their qty
, but it's not. It's only the average of the 2 newly submitted orders.
So since we already have self.position.entry_price
for executed orders, maybe it makes sense to leave it as is. But still, we maybe the name of it is confusing and should point to OPEN orders. What do you think?
from jesse.
Related Issues (20)
- [Live Mode] Session terminated as the result of an uncaught exception HOT 2
- After a position opened using different time window in order to check situation HOT 2
- There is no bitget example HOT 1
- Kraken data HOT 1
- Integrating Forex data from a Oanda API HOT 1
- linux/arm64 docker image HOT 4
- Live-trading plugin cannot be run on ARM platform HOT 1
- fee = config['env']['exchanges'][self.exchange]['fee']. KeyError: None HOT 2
- Add tradingview-webhook HOT 2
- get_cadles for > 1m routes does not work due to some legacy code HOT 1
- when running paper-trade mode, DELETE requests lead to unhandled exception (err 500) HOT 2
- wrong period starts for 45m candles in PAPERTRADE mode HOT 11
- Option Support HOT 2
- circular dependency with python 3.11 HOT 3
- Bug - link not working HOT 4
- Broken link "Why Jesse" on the homepage HOT 1
- binance does not offer 3h candles for 30m extra HOT 1
- Maximum recursion error when gathering historical data HOT 1
- Minor annoyance when gathering data HOT 1
- CandleNotFoundInExchange for any timeframe, with any altcoin using Coinbase Spot HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jesse.