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/

    Stop orders are generating Margin error

    General Code/Help
    1
    2
    100
    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.
    • R
      RandomTrader88 last edited by

      Lets say that i have $1000 in cash and I want to short a stock that is currently at trading at 90. i want to short at 100 and stop loss at 110 if the trade goes against me (just an example).

      I set the following trade:

      1. limit order to sell 10 stocks at 100.
      2. limit stop order to buy 10 stocks at 110.

      if this trade goes against me, i should lose $100 and have $900 cash remaining.

      BUT when i send these orders to backtrader, I get margin error (order.status == order.Margin) on the stop loss because the engine is thinking that i will need $1100 in order to buy 10 stocks at 110...
      I know that until the price will hit the stop loss, i will have more cash from short selling... but the program cant calculate it and returns an error...

      What is the right way to solve it?
      how can i set stop loss, without getting margin called on me?

      1 Reply Last reply Reply Quote 0
      • R
        RandomTrader88 last edited by

        I found a solution...

        cerebro.broker.set_checksubmit(checksubmit=False)

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