Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. nullpy
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    N
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 7
    • Best 0
    • Controversial 0
    • Groups 0

    nullpy

    @nullpy

    0
    Reputation
    307
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    nullpy Unfollow Follow

    Latest posts made by nullpy

    • RE: Is an excuted price the following opening price?

      @backtrader
      I have found the option and how it converts the other fields. I appreciate your help!

      posted in General Code/Help
      N
      nullpy
    • RE: Is an excuted price the following opening price?

      @backtrader
      Thank you for the answer! Could you tell me which *.py file does the work and what I should look at?

      posted in General Code/Help
      N
      nullpy
    • Is an excuted price the following opening price?

      Hello. I'm working on Quickstart manual. The manual says that when the broker executes an order, it uses the opening price of the next bar.

      orcl-1995-2014
      Date,      Open, High, Low,  Close,  Volume, Adj Close
      2000-12-20,28.06,29.81,27.50,28.50,54440500, 26.88
      2000-12-21,27.81,30.25,27.31,29.50,46719700, 27.82
      2000-12-22,30.38,31.98,30.00,31.88,35568200, 30.06
      2000-12-26,31.50,32.19,30.00,30.94,20589500, 29.17
      2000-12-27,30.38,31.06,29.38,30.69,26437500, 28.94
      2000-12-28,30.56,31.62,30.38,31.06,25053600, 29.29
      2000-12-29,30.88,31.31,28.69,29.06,31702200, 27.41
      

      So, in my understanding, if an order is created on 20 Dec from the data above, the following execution price should be 27.81 on 21 Dec, however, this is the result:

      2000-12-20, Close, 26.88
      2000-12-20, BUY CREATE, 26.88
      2000-12-21, BUY EXECUTED, 26.23  -> ???
      2000-12-21, Close, 27.82
      2000-12-22, Close, 30.06
      2000-12-26, Close, 29.17
      2000-12-27, Close, 28.94
      2000-12-28, Close, 29.29
      2000-12-29, Close, 27.41
      2000-12-29, SELL CREATE, 27.41
      

      Please point me out my misunderstandings.

      posted in General Code/Help
      N
      nullpy
    • RE: How can I get the price at which buy executed?

      @backtrader
      Yes, I think I should study more on the language. Thank you for your recommendation. I will try to find ou how the program works!

      posted in General Code/Help
      N
      nullpy
    • RE: How can I get the price at which buy executed?

      @backtrader
      I'm sorry. I'm new to Object Oriented Programming and Python. Do you mean that I need to add order to next as a method parameter? I wonder why def notify_order(self, order): can get order.executed.price when it occurs error in def next(self, order):
      I would appreciate it if you could give me an example code, if it doesn't take too much of your time.

      posted in General Code/Help
      N
      nullpy
    • RE: How can I get the price at which buy executed?

      @backtrader

      Thank you for your answer! I'm following the QuickStart and now I understand that the command shows executed prices, but I actually don't understand how to use it in the function to compare the two prices. Here's the error I get and what I tried.

          Traceback (most recent call last):
      File "D:\PYTHON_SOURCE\temp.py", line 159, in <module>
        cerebro.run()
      File "D:\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 794, in run
        runstrat = self.runstrategies(iterstrat)
      File "D:\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 919, in runstrategies
        self._runonce(runstrats)
      File "D:\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1294, in _runonce
        strat._oncepost(dt0)
      File "D:\Anaconda3\lib\site-packages\backtrader\strategy.py", line 267, in _oncepost
        self.next()
      File "D:\PYTHON_SOURCE\temp.py", line 108, in next
        if order.executed.price < self.dataclose[0]:
      NameError: name 'order' is not defined
      
      
      
      def next(self): 
          self.log('Close, %.2f' % self.dataclose[0])
      
          if self.order:
              return
      
          if not self.position:
              if self.stoch[0] > 80:
                  self.log('BUY CREATE, %.2f' % self.dataclose[0])
                  self.order = self.buy()
          else:
              if order.executed.price < self.dataclose[0]:    #ERROR OCCURS HERE
                  self.log('SELL CREATE, %.2f' % self.dataclose[0])
                  self.order = self.sell()
      
      posted in General Code/Help
      N
      nullpy
    • How can I get the price at which buy executed?

      Hello. I'm trying to make a exit strategy that clears a position if the current price is lower than the price at which buy executed for the last time, for example, like the below.

      if self.price_executed < self.dataclose[0]:
      self.order = self.sell()

      I wonder how I can get the price of the last buy execution .

      Thank you for reading this!

      posted in General Code/Help
      N
      nullpy