Skip to content

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

Closed
@Benouare

Description

@Benouare

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions