Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. ines broto clemente
    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 1
    • Best 0
    • Controversial 0
    • Groups 0

    ines broto clemente

    @ines broto clemente

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

    ines broto clemente Unfollow Follow

    Latest posts made by ines broto clemente

    • sell order completed even though not enough cash to cover value

      Hello! I am new to using backtrader and I do not have a strong technical analysis background, so I am having some difficulty understanding what is happening behind the code. I am currently attempting to implement a simple Moving Average Crossover strategy with some additional conditions.

      As far as I am aware, the signals are appearing when I want them to and they are triggering bracket orders correctly (as can be seen in the attached screenshot). However, I am struggling to understand why the second trade, of the ones defined below, is being triggered.

      In this case, the first signal attempts to open a short position of size 139 at a price of 175.67 (139175.67 =24418.13). Since the available cash is lower than the trade value (22780.51), the position is not opened. On the next step, we attempt to open a position of size 135 at 175.48 (135175.48 =23689.8). This number is still greater than the available cash, yet the order is still being accepted and executed.

      2022-12-19 -> order margin
      current cash: 22780.51
      openPositions : 360
      value: 86021.714
      close price: 175.67
      stopPrice: 181.13
      target: 2.8
      targetPrice: 160.3833454
      size = 139

      2022-12-20 -> order completed
      current cash: 22780.51
      openPositions: 360
      value: 85953.31461826575
      close price: 175.48
      stopPrice: 181.13
      target: 2.8
      targetPrice: 159.6613454
      size = 135

      As far as I am aware, the leverage is set to 1 (default value) and no specific margin has been set. I am currently using a simple commission scheme, which is defined as follows:

      cerebro.broker.setcommission(commission=0.002)

      Additionally, I have also set cerebro.broker.set_coc(True).

      In general, I am curious about the default logic that determines whether a Short trade is accepted or rejected based on the available cash.

      I would appreciate it if you could help me understand what is happening. Thank you very much in advance!

      Screenshot from 2023-04-19 17-13-47.png

      posted in General Code/Help
      ines broto clemente
      ines broto clemente