Stop orders are generating Margin error
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:
- limit order to sell 10 stocks at 100.
- 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?
I found a solution...