Skip to content

A single trade wipes out all the cash #1092

Closed
@mrubin01

Description

@mrubin01

Strategy

It's a very simple, naive strategy based on MACD: it returns only one trade over a period of 6 months (BCH-USD).

Trade_1

Screenshot 2023-11-19 at 22 16 56

Actual Behavior

The issue is that, even if the order size is 0.1 that single trade wipes out all my capital (10,000). Indeed, in the stats I see Return=-100%. How can a single trade return -100% with an order size of 0.1? Any idea why this happens?

order_size = 0.1
fastperiod = 12
slowperiod = 26
signalperiod = 9

def init(self):
    close = self.data.Close

    self.macd = self.I(talib.MACD, close, self.fastperiod, self.slowperiod, self.signalperiod)
    self.ema_slow = self.I(talib.EMA, close, self.slowperiod)
    self.ema_fast = self.I(talib.EMA, close, self.fastperiod)

def next(self):
    price = self.data.Close[-1]
     
    if self.macd[0] > 0 and self.macd[1] > 0 and crossover(self.ema_fast, self.ema_slow):
        self.sell()
    elif self.macd[0] < 0 and self.macd[1] < 0 and crossover(self.ema_slow, self.ema_fast):
        self.buy(size=self.order_size, limit=None, stop=None)

full_data_macd = full_data.copy()
bt_macd = Backtest(full_data_macd, MACD_Strategy, cash=10000, commission=.00008, exclusive_orders=True)
stats_macd = bt_macd.run()

Additional info

  • Backtesting version: 0.3.3
  • bokeh.__version__: 3.3.0
  • OS: MacOS Monterey

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis is not a (valid) bug report

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions