text: For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:
  How to close a previous order then open a new one in the same tick?
  - Ahmed Sobhy last edited by
  def next(self): if not self.position: self.order = self.buy() else: self.order = self.close() # I need here to open a sell position in the same tick
  As in the previous code, I need to close the previous buy position then open a new sell one immediately.
  - backtrader administrators last edited by backtrader
  self.close() # close the existing position self.sell() # or self.buy() if you want to go long