Backtrader Community

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

    Nael Shichida

    @Nael Shichida

    0
    Reputation
    1
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Nael Shichida Unfollow Follow

    Latest posts made by Nael Shichida

    • RE: Bracket order take profit within open candle

      I'm in the same space, it seems to take daily closes as opposed to if high or lows are hit.

      I'll let you know if i find something in the documentation.

      Cheers

      posted in General Discussion
      Nael Shichida
      Nael Shichida
    • RE: Bracketorder : Order gets executed at open instead of limit price.

      @nael-shichida said in Bracketorder : Order gets executed at open instead of limit price.:

      38506

      Apologies, I copied using a tested version of my code, I was hardcoding the price [38506] just to see if it takes it or not but still executing on the open of the day the logic was found

      posted in General Code/Help
      Nael Shichida
      Nael Shichida
    • RE: Bracketorder : Order gets executed at open instead of limit price.

      Hey Devang

      I am facing a similar issue as well. I've tried using both bracket orders using the code below:

      self.order = self.buy_bracket(exectype=bt.Order.Limit,limitprice=target, price=self.dataopen[-2], stopprice=self.dataclose[-2])

      Also tried manually creating self.buy and assigning a parent order

                      o1 = self.buy(exectype=bt.Order.Limit,
                                    price=38506.38,
                                    transmit=False)
      
                      print('{}: Oref {} / Buy at {}'.format(
                          self.datetime.date(), o1.ref, self.dataopen[-2]))
      
                      o2 = self.sell(exectype=bt.Order.Stop,
                                     price=self.dataclose[-2],
                                     parent=o1,
                                     transmit=False)
      
                      print('{}: Oref {} / Sell Stop at {}'.format(
                          self.datetime.date(), o2.ref, self.dataclose[-2]))
      
                      o3 = self.sell(exectype=bt.Order.Limit,
                                     price=target,
                                     parent=o1,
                                     transmit=True)
      
                      print("printing o1", o1.price,o1.exectype)
                      print("printing o2", o2.price,o2.exectype)
                      print("printing o3", o3.price,o3.exectype)
      

      However in both cases I an buying the dataopen[0] of when my logic hits, essentially I wait for 2 days before creating a limit order but for some reason it will always buys on when the logic was found despite assigning a limit order of dataopen[-2]

      If you found a solution would be very appreciative. Will respond as well when I find out myself!

      Cheers

      posted in General Code/Help
      Nael Shichida
      Nael Shichida
    • Multiple trades Long/Short Support?

      Hey everyone

      Newly enlisted backtrader here, I have been looking at youtube tutorials and the documentation. A lot of the examples cover 1 position at a time such as SMA crossover.

      However I am trying to have multiple buy orders using 1R/R of my portfolio for each trade, regardless of whether I am in a trade or not I want each one to be individually dealt with. The logic for entering long trades is working, however I am using a buy bracket since I need a log to see if the order is executed and if it has been executed, to set a close long either at target or stop price.

      If anyone can help guide me, would be extremely grateful as to how I should formulate the logic in Python?

      class TestStrategy(bt.Strategy):

      def log(self, txt, dt=None):
          ''' Logging function fot this strategy'''
          dt = dt or self.datas[0].datetime.date(0)
          print('%s, %s' % (dt.isoformat(), txt))
      
      def __init__(self):
          # Keep a reference to the "close" line in the data[0] dataseries
          self.order = None
          self.dataclose = self.datas[0].close
          self.dataopen = self.datas[0].open
          self.zone = self.datas[0].close - self.datas[0].open
      
      
      def next(self):
          # Simply log the closing price of the series from the reference
          self.log('Close, %.2f' % self.dataclose[0])
          self.log('Open, %.2f' % self.dataopen[0])
          self.log('Zone, %.2f' % self.zone[0])
          self.log('shift, %.2f' % self.zone[-1])
      
          print(len(self))
          print(self.order)
          print(self.position)
          #
          """Enters Long position if below conditions are met"""
          if self.zone[0] < 0:
              print("Bar is red")
              # current close less than previous close
      
              if self.zone[1] > 0:
                  print("Next candle is green")
                  # Next close less than the previous close
                  if 1.5*abs(self.zone[0]) < abs(self.zone[1]):
                      print("Buy Zone found")
      
                      # BUY, BUY, BUY!!! (with all possible default parameters)
                      self.log('BUY CREATE, %.2f' % self.dataclose[0])
                      # self.buy()
      
                      self.order = self.buy_bracket(limitprice=self.dataopen[0], price=self.dataopen[0],
                                                    stopprice=self.dataclose[0])
                      # print(self.order)
                      print(type(self.order.ref))
      
      posted in General Code/Help
      Nael Shichida
      Nael Shichida
    • RE: No such file or directory: orcl....txt

      You can also add 'r' before feeding the path, if you are using a string as input. It basically converts it into Raw string.

      datapath = r"C:\Users\XXX\PycharmProjects\BackTesting\venv\datas\orcl-1995-2014.txt"

      posted in General Code/Help
      Nael Shichida
      Nael Shichida