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

Migrate 0.1.8 -> 0.2.0 position.open_time vs trade.entry_time #117

Closed
Benouare opened this issue Jul 24, 2020 · 1 comment
Closed

Migrate 0.1.8 -> 0.2.0 position.open_time vs trade.entry_time #117

Benouare opened this issue Jul 24, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@Benouare
Copy link
Contributor

Benouare commented Jul 24, 2020

Hi guys,
Am i missing something or trade.entry_time does not exists?
'Trade' object has no attribute 'entry_time'

Expected Behavior

I would like to know when did i "open" my position. I was using the position.open_time in 0.1.8.

Actual Behavior

In 0.1.8, this is working :

if self.position: 
[....]
      if next_marketday(self.position.open_time, 35) <= self.data.index[-1]:

In 0.2.0, this is not working :

if self.position: 
[....]
      if next_marketday(self.trades[-1].entry_time, 35) <= self.data.index[-1]:

In backtesting.py line 502 looks like there is no property entry_time...

class Trade:
    """
    When an `Order` is filled, it results in an active `Trade`.
    Find active trades in `Strategy.trades` and closed, settled trades in `Strategy.closed_trades`.
    """
    def __init__(self, broker: '_Broker', size: int, entry_price: float, entry_bar):
        self.__broker = broker
        self.__size = size
        self.__entry_price = entry_price
        self.__entry_bar = entry_bar
        self.__exit_price = None
        self.__exit_bar = None
        self.__sl_order = None  # type: Optional[Order]
        self.__tp_order = None  # type: Optional[Order]

EDIT :
Is this the good way ?
self.data.index[self.trades[-1].entry_bar]
to get the entry date?

@kernc kernc closed this as completed in 0363e88 Jul 26, 2020
kernc added a commit that referenced this issue Jul 26, 2020
@kernc
Copy link
Owner

kernc commented Jul 26, 2020

Thanks for the report! Trade.{entry,exit}_time added in 3cc33b8; be in a patch release shortly. Yours was the correct alternative. 👍

@kernc kernc added the bug Something isn't working label Jul 27, 2020
Goblincomet pushed a commit to Goblincomet/forex-trading-backtest that referenced this issue Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants