Skip to content

wrong logic of buy and sel #49

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

Closed
Realmlai opened this issue Mar 10, 2020 · 4 comments
Closed

wrong logic of buy and sel #49

Realmlai opened this issue Mar 10, 2020 · 4 comments
Labels
invalid This is not a (valid) bug report

Comments

@Realmlai
Copy link

Expected Behavior

I found the buy and sell signal was wrong.
please check out the attachment.

Actual Behavior

wrongly P/L -1.538
because the trade is a win trade

Steps to Reproduce

backtestinglogic
1.
2.
3.

Additional info

  • Backtesting version:
@kernc
Copy link
Owner

kernc commented Mar 10, 2020

The green up arrow is not a buy signal, but rather an end point marker of a market-long (upwards) and profitable (green) trade.

Note, Strategy.sell() implicitly closes the long position and opens a new short one (that'll change in the upcoming version, see #47). If that doesn't answer your concerns, why do you think the last trade is a win?

@Realmlai
Copy link
Author

Great, thank you kernc

@kernc kernc added the invalid This is not a (valid) bug report label Mar 11, 2020
@MattoDemente
Copy link

Then, how do I identify the buy/sell signals in the plot ?

@kernc
Copy link
Owner

kernc commented Jul 28, 2020

The dotted lines indicate duration of trades and the PL triangles closing trades' success. There are no other visual indicators showing trades entering, nor order placing. It's very simple to devise something yourself:

class MyStrategy(Strategy):
    def init(self):
        # Shows buy/sell signal as a scatter plot. Init to all-NaN.
        self.signal = self.I(lambda: np.repeat(np.nan, len(self.data.Close), scatter=True)

    def next(self):
        ...
        # on some condition
        self.buy()

    def buy(self, *args, **kwargs):
        self.signal[-1] = 1  # On buy, input 1 instead of existing NaN
        super().buy(*args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not a (valid) bug report
Projects
None yet
Development

No branches or pull requests

3 participants