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/

    notify_trade is not correctly recognize trade close when a trade is closed by stop loss or stop trail

    General Discussion
    2
    2
    492
    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.
    • S
      sanmao last edited by

      guys, I have two trades in my back test, the first is long, and the second is short. Both closed by stop trail and get profits. Buy notify_trade just recognize the two as one trade and loss money.
      I don't know how to fix it.

          def notify_trade(self, trade):
              if not trade.isclosed:
                  return
              
              self.log('OPERATION PROFIT, GROSS %.2f, NET %.2f' %
                       (trade.pnl, trade.pnlcomm))
      

      Here is log

      Starting Portfolio Value: 10000.00
      2015-03-18, BUY @price: 2.55
      2015-03-25, stopTrail @price: 2.60
      2015-06-24, SELL @price: 2.99
      2015-06-29, stopTrail @price: 2.77
      2015-06-29, OPERATION PROFIT, GROSS -176.28, NET -176.28
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        This wall all discussed and clarified in this other post by the same author: https://community.backtrader.com/topic/1362/stop-trail-order-executed-but-position-not-change

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }