Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Question regarding trade prices

    General Code/Help
    2
    3
    583
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • bb2
      bb2 last edited by

      Hello,

      I am having a problem with the trade prices for the example below.
      The line before order begins shows the datetime and the price at that candle. the order begins in the next candle and in the first line after --ORDER BEGIN you can see the ohlc of that candle.

      The buy occurs at price 1.01643, which is the opening price of the next candle as expected.
      According to the log the sell price is 1.01643, though I was expecting to sell for 1.0144 which is the opening price of that candle. What might have gone wrong here?

      I am buying with self.buy() and selling with self.sell().

      2017-04-26 22:35:00 2017-04-26 22:35:00 entry: 1.01635
      -------------------------------------------------- ORDER BEGIN 2017-04-26 22:36:00
      1.01643 1.01695 1.01594 1.01597
      Ref: 1
      OrdType: 0
      OrdType: Buy
      Status: 4
      Status: Completed
      Size: 10
      Price: None
      Price Limit: None
      TrailAmount: None
      TrailPercent: None
      ExecType: 0
      ExecType: Market
      CommInfo: <backtrader.comminfo.CommInfoBase object at 0x113c64be0>
      End of Session: 736445.9999999999
      Info: AutoOrderedDict()
      Broker: None
      Alive: False
      -------------------------------------------------- ORDER END
      -------------------------------------------------- TRADE BEGIN 2017-04-26 22:36:00
      1.01643 1.01695 1.01594 1.01597
      ref:1
      data:<utils.customcsv.HistData object at 0x113c1a630>
      tradeid:0
      size:10
      price:1.01643
      value:10.164299999999999
      commission:0.0
      pnl:0.0
      pnlcomm:0.0
      justopened:True
      isopen:True
      isclosed:False
      baropen:18462
      dtopen:736445.9416666667
      barclose:0
      dtclose:0.0
      barlen:0
      historyon:False
      history:[]
      status:1
      -------------------------------------------------- TRADE END
      
      2017-04-26 23:01:00 2017-04-26 23:01:00 stop loss: 1.01438
      
      -------------------------------------------------- ORDER BEGIN 2017-04-26 23:02:00
      1.0144 1.01446 1.01384 1.01417
      Ref: 2
      OrdType: 1
      OrdType: Sell
      Status: 4
      Status: Completed
      Size: -10
      Price: None
      Price Limit: None
      TrailAmount: None
      TrailPercent: None
      ExecType: 0
      ExecType: Market
      CommInfo: <backtrader.comminfo.CommInfoBase object at 0x113c64be0>
      End of Session: 736445.9999999999
      Info: AutoOrderedDict()
      Broker: None
      Alive: False
      -------------------------------------------------- ORDER END
      -------------------------------------------------- TRADE BEGIN 2017-04-26 23:02:00
      1.0144 1.01446 1.01384 1.01417
      ref:1
      data:<utils.customcsv.HistData object at 0x113c1a630>
      tradeid:0
      size:0
      price:1.01643
      value:0.0
      commission:0.0
      pnl:-0.020299999999999763
      pnlcomm:-0.020299999999999763
      justopened:False
      isopen:False
      isclosed:True
      baropen:18462
      dtopen:736445.9416666667
      barclose:18488
      dtclose:736445.9597222222
      barlen:26
      historyon:False
      history:[]
      status:2
      -------------------------------------------------- TRADE END
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        You are not printing order execution prices. That's what's wrong. Use the available information in order.executed

        bb2 1 Reply Last reply Reply Quote 0
        • bb2
          bb2 @backtrader last edited by

          @backtrader thanks :)

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors