Giter VIP home page Giter VIP logo

Comments (4)

bigbenbeer avatar bigbenbeer commented on May 27, 2024

I suspect the error is in the following lines of code, specifically your indexes:

    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)

An index of -1 denotes the current candle, so by setting an index of 0 and 1 you are trying to ``look forward''.

from backtesting.py.

mrubin01 avatar mrubin01 commented on May 27, 2024

Thanks for your reply. Initially I thought you were right, but then I've checked better: self.macd[0] and self.macd[1] refer to the first two values in the MACD indicator, the MACD line and the signal line. It's correct what I copied. Indeed, if I need the current candle I use self.data.Close[-1].
Anyway, even if I replace [0] and [1] with [-1] and [-2] nothing really changes, there is still 1 trade that wipes all the cash out:

Screenshot 2023-12-07 at 19 24 46

from backtesting.py.

Chichostyle avatar Chichostyle commented on May 27, 2024

i believe thats still an index problem for example using your original code with index 0 and 1 i get (low # trades with and maybe too long of a trade):

imagen

but when i use -1 and 0 i get this (more trades):

like this:

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

imagen

from backtesting.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.