average_entry_price in Strategy is wrong
See original GitHub issueHello,
while backtesting a long-only strategy I notice there might be something wrong in computing the average_entry_price
Here it a sequence of buy order (1st one made in go_long
, the others in update_position
) and how the average_entry_price
gets updated
buying qty: 3.3426391274712346 price: 150.44
average_entry_price: 150.44
buying 3.1774795305245025 150.33
average_entry_price: 150.33
buying 3.024307255417514 150.03
average_entry_price: 150.03
buying 2.8473431610486517 151.37
average_entry_price: 151.37
buying 2.6811195961259826 152.7
average_entry_price: 152.7
buying 2.5541417738143384 152.26
average_entry_price: 152.26
buying 2.4468974718562766 150.97
average_entry_price: 150.97
buying 2.318153649389877 151.37
average_entry_price: 151.37
buying 2.2468293065477463 148.35
average_entry_price: 148.35
buying 2.1494655325637435 147.3
average_entry_price: 147.3
buying 2.0424598613965914 147.25
average_entry_price: 147.25
buying 1.9870837092479907 143.77
average_entry_price: 143.77
It looks like average_entry_price
always takes the last buying price.
Am I doing something wrong or is it a real bug?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Avg Entry price plot is not correct - NinjaTrader Support Forum
I want to plot average entry (breakeven) price throughout the chart at all times reflecting at all times any position I haven to...
Read more >Get an open order's entry price in TradingView's Pine Script
It's how TradingView strategies get open trade entry prices. ... the average entry price avgEntryPrice = priceSum / strategy.opentrades.
Read more >TradingView Pine Script : check previous strategy.entry price ...
I am trying to build a strategy that will buy multiple times (pyramiding) to average down before closing but I want to check...
Read more >Open TradingView trades with strategy.entry() - Kodify.net
To open a market position our TradingView strategy uses the strategy.entry() function. This function can send market, limit, stop, ...
Read more >Choosing the Wrong Pricing Strategy Can Be a Costly Mistake
Raju and Zhang say devising appropriate pricing strategies is more critical than ever in a world of hyper-competition. Pricing strategies also ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a lot,
self.position.entry_price
was the bad boy I was looking for. I agree with you then… ifself.position
is resuming all info about current position, thenself.average_entry_price
should report only the average entry price of the last order. I am closing the issue. Thanks againNice catch. I’ll fix it. Thank you