Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. new_trader
    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 5
    • Posts 11
    • Best 0
    • Groups 0

    new_trader

    @new_trader

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

    new_trader Unfollow Follow

    Latest posts made by new_trader

    • Any way to create point and figure values as a line in backtrader?

      Hello there,
      I don't want to plot point and figure chart. I just require the values as a line in backtrader?
      This is a functionality in tradingview Check it out.

      pnf_tickerid = pointfigure(syminfo.tickerid, "hl", "Traditional", 1, 3)
      pnf_close = security(pnf_tickerid, timeframe.period, close)
      

      Any help is appreciated.

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • RE: Order Price is different from issued price

      @davidavr Yeah, I know it's weird. My strategy requires this functionality. Thanks for your help.

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • RE: Order Price is different from issued price

      @davidavr Hey thanks for the reply. I really appreciate your help.
      I understand what's happening here now. Can you tell me what type of order should I use if I want to buy at a price when the price reaches higher than the current price? For example, issuing the buy order when the price reaches 149, not 49.

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • RE: Order Price is different from issued price

      @new_trader I want the trade to get executed just above the current price but if I use Limit order, the given thing happens. What type of order can I issue then?

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • RE: Order Price is different from issued price

      @davidavr Thanks for the reply.
      I think that I'm misunderstanding something. I thought that limit order was supposed to execute when the desired price p1 was reached and the stop loss gets executed when the stoploss price is reached. I added 100 in p1 because I wanted to set an unachievable price so that it won't get executed but it is still getting executed.

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • Order Price is different from issued price

      Hello everyone,

      I am really new at backtrader so I don't know how to create stops and targets. I saw this post on the docs that used manual bracket orders and I copied my code from this post

      I'm issuing my trades like this

      p1 = 100+d.close[0] *0.99
                  p2 = p1 - 2* std
                  p3 = p1 + 2* std
                  self.log("Buying {} at price {} Stop {} Target {} CurrentPrice {}".format(d._name,p1,p2,p3,d.close[0]))
                  valid=self.datas[0].datetime.datetime(0) + datetime.timedelta(minutes = 2)
      
      mainside = self.buy(d,size=1,price=p1, valid=valid, exectype=bt.Order.Limit, transmit=False)
                  lowside  = self.sell(d,price=p2, size=mainside.size, valid=valid, exectype=bt.Order.Stop,
                                      transmit=False, parent=mainside)
                  highside = self.sell(d,price=p3, size=mainside.size, valid=valid, exectype=bt.Order.Limit,
                                      transmit=True, parent=mainside)
      

      but this is leading to

      2019-07-08T19:08:00, Buying AAPL at price 149.5 Stop 149.47220847072128 Target 149.52779152927872 CurrentPrice 50.0
      2019-07-08T19:09:00, BUY ORDER SUBMITTED for AAPL size 1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, BUY ORDER ACCEPTED for AAPL size 1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, BUY EXECUTED for AAPL, Size 1.000000 Price: 49.997500, Cost: 49.997500, Comm 0.049998
      2019-07-08T19:10:00, SELL EXECUTED for AAPL, Size -1 , Price: 49.992500, Cost: 49.997500, Comm 0.049993
      

      Please help.

      posted in Indicators/Strategies/Analyzers
      N
      new_trader
    • RE: Bracket order discrepancies

      @new_trader I tried using the manual way to create bracket orders using 1 buy and two sell orders. It lead to the same results. I tried to increase the price all the prices by 100 so that they could never get executed but here's the result

      2019-07-08T19:08:00, Buying AAPL at price 149.5 Stop 149.47220847072128 Target 149.52779152927872 CurrentPrice 50.0
      2019-07-08T19:09:00, BUY ORDER SUBMITTED for AAPL size 1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, BUY ORDER ACCEPTED for AAPL size 1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00
      2019-07-08T19:09:00, BUY EXECUTED for AAPL, Size 1.000000 Price: 49.997500, Cost: 49.997500, Comm 0.049998
      2019-07-08T19:10:00, SELL EXECUTED for AAPL, Size -1 , Price: 49.992500, Cost: 49.997500, Comm 0.049993
      
      posted in General Code/Help
      N
      new_trader
    • Bracket order discrepancies

      Here's the log

      2019-07-29T16:11:00, Buying GOOG at price 1241.0930500000002 Stop 1240.0542443892334 Target 1242.131855610767 CurrentPrice 1228.805
      2019-07-29T16:12:00, BUY ORDER SUBMITTED for GOOG size 1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, SELL ORDER SUBMITTED for GOOG size -1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, SELL ORDER SUBMITTED for GOOG size -1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, BUY ORDER ACCEPTED for GOOG size 1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, SELL ORDER ACCEPTED for GOOG size -1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, SELL ORDER ACCEPTED for GOOG size -1 Created on 2019-07-29 16:11:00
      2019-07-29T16:12:00, BUY EXECUTED for GOOG, Size 1.000000 Price: 1228.855000, Cost: 1228.855000, Comm 1.228855
      2019-07-29T16:13:00, SELL EXECUTED for GOOG, Size -1 , Price: 1229.120000, Cost: 1228.855000, Comm 1.229120
      

      and here's the code which executed it

                  p1 = d.close[0] *1.01
                  p2 = d.close[0] *1.01 - 2* std
                  p3 = d.close[0] *1.01 + 2* std
                  self.log("Buying {} at price {} Stop {} Target {} CurrentPrice {}".format(d._name,p1,p2,p3,d.close[0]))
                  valid=self.datas[0].datetime.datetime(0) + datetime.timedelta(minutes = 2)
                  order = self.buy_bracket(d, size=1,
                              exectype=bt.Order.Limit,
                              price=p1, valid=valid,
                              stopprice=p2,
                              limitprice=p3)
      

      As you can see from the logs, the ordered price and the execution price are completely different. Why is this happening?

      posted in General Code/Help
      N
      new_trader
    • Weekly resampling vs daily compression = 5 or 7?

      Hi everyone.
      I was backtesting a strategy but got very different results when I used a weekly resampled data and used timer

      self.notify_timer(args):
        mystrategy()
      

      to trade on Wednesday vs when I used daily data with compression = 5 and used

      self.init():
        self.count=0
      
      self.next():
        self.count+=1
        if self.count%self.p.c!=0:
          return
        mystrategy()
      
      posted in General Code/Help
      N
      new_trader
    • RE: Orders getting executed multiple times

      @ab_trader Hi ab_trader. I did submit it as timeframe=minute. On closed inspection, I noticed that it was submitting more sell requests before the last one was executed. I don't know how this lead to this specific behavior but after changing that, I don't think that it's an issue anymore.

      posted in General Code/Help
      N
      new_trader