Backtrader Community

    • 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/

    Stoploss not "working" on first day of trade

    General Discussion
    1
    3
    23
    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.
    • Jakub Jaśkowiec
      Jakub Jaśkowiec last edited by

      Re: Stoploss not "working" on first day of trade

      I have the same problem as in the attached topic: I have a bracket order (buy and stoploss) and the "stoploss" is not executed on the same day as "buy" despite the fact that the lowest price is lower than the stoploss

      I am a software developer excited about backtrader and its possibilities
      https://github.com/qbajas/backtesting

      Jakub Jaśkowiec 1 Reply Last reply Reply Quote 0
      • Jakub Jaśkowiec
        Jakub Jaśkowiec @Jakub Jaśkowiec last edited by

        the bracket orders:

        buy_order = self.buy(
        data=self.datas[self.i], size=self.getsizing(self.datas[self.i]), exectype=bt.Order.Limit, 
        price=price * buy_price_multiplier, 
        transmit=False)
        
        self.stop_loss = self.sell(
        exectype=bt.Order.StopLimit, 
        price=price * stop_price_multiplier, 
        parent=buy_order,
        plimit=price*stop_limit_price_multiplier,
        size=self.getsizing(self.datas[self.i]), 
        data=self.datas[self.i])
        

        log:

        2023-08-07, + BUY 19225 PTF @ 49.30 LIMIT ($934764)
        2023-08-07, + STOP LOSS PTF @ 47.65 LIMIT 47.65
        2023-08-08, Ticker: PTF Order Status: Submitted, Type: Buy, Execution Type: Limit
        2023-08-08, Ticker: PTF Order Status: Submitted, Type: Sell, Execution Type: StopLimit
        2023-08-08, Ticker: PTF Order Status: Accepted, Type: Buy, Execution Type: Limit
        2023-08-08, Ticker: PTF Order Status: Accepted, Type: Sell, Execution Type: StopLimit
        2023-08-08, Ticker: SPY Order Status: Completed, Type: Sell, Execution Type: Limit
        2023-08-08, Ticker: PTF Order Status: Completed, Type: Buy, Execution Type: Limit
        2023-08-08,  BUY PTF EXECUTED at 48.37, cost 929957.63, com 65.10
        

        prices of PTF on that day:

        2023-08-08,48.369999,48.369999,47.480000,48.040001,48.040001,128800
        

        I am a software developer excited about backtrader and its possibilities
        https://github.com/qbajas/backtesting

        1 Reply Last reply Reply Quote 0
        • Jakub Jaśkowiec
          Jakub Jaśkowiec last edited by

          @lampalork @ab_trader were you able to come up with some solution regarding this problem?

          I am a software developer excited about backtrader and its possibilities
          https://github.com/qbajas/backtesting

          1 Reply Last reply Reply Quote 0
          • Referenced by  Jakub Jaśkowiec Jakub Jaśkowiec 
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors