Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Stop Loss value being (still sometimes) erased when reached #1340

Copy link
Copy link
@DannyIbo

Description

@DannyIbo
Issue body actions

Expected behavior

The SLs should be displayed in the trade list (within the result stats) whenever they are set (according to the strategy).
Image

Code sample

from backtesting import Backtest, Strategy
from backtesting.test import GOOG
from backtesting.lib import crossover

class Strat(Strategy):
    def init(self):
        pass
    def next(self):
        if self.position:
            pass
        else:
            price = self.data.Close[-1]
            self.buy(size = 1, sl = price - 10, tp = price + 20)
        
bt = Backtest(GOOG, Strat, cash=10_000)
output = bt.run()
display(output._trades.iloc[30:33])
bt.plot()

Actual behavior

When I get the list of the trades, some of them are unprovided with the SL. This seems to happen only for the trades being closed BELOW the set SL.

This issue seems to be an unfixed part of the bug report #1288 by @xyffar.

Additional info, steps to reproduce, full crash traceback, screenshots

Image

Software versions

  • backtesting.__version__: 0.6.5
  • pandas.__version__: 2.3.3
  • numpy.__version__: 1.26.2
  • bokeh.__version__: 3.8.1
  • OS: Linux 6.14.0-36-generic x86_64
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.