Skip to content
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

Access the first candle of the session. next() always give the 2nd element #1179

Open
Shishir-Bondre opened this issue Oct 24, 2024 · 2 comments

Comments

@Shishir-Bondre
Copy link

Expected Behavior

  • How can I access the first candle of the session ? I want to test the strategy which takes the trade on first candle.

Actual Behavior

           class Scalping(Strategy):
                     def init(self):
                           pass

                     def next(self):
                           if len(self.data) == 1:
                                self..buy()

Steps to Reproduce

  1. Currently I cannot access the 1st price points
           class Scalping(Strategy):
                     def init(self):
                           pass

                     def next(self):
                           if len(self.data) == 1:
                                self..buy()
                                # not executed currently
@bhargavyagnik
Copy link

self..buy() is not a correct python syntax, try self.buy()

@ferromariano
Copy link

Si lo que queres es ejecutar en la primera llamada de next podes hacer esto

from backtesting import Strategy

class Scalping(Strategy):
      _order_Scalping = None
      def init(self):
            pass

      def next(self):
            if self._order_Scalping is None:
                  self._order_Scalping = self.buy()

recorda que segun los indicadores que allas configurado, el primer llamado a next puede ser en la fila posterior a los datos que allas proporcionado. Pero el codigo alli te sirve :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants