I have recently faced a loss 3 times higher then a defined risk in my copy of the MultiCharts engine implemented in Backtrader engine.
I see 2 causes of this issue:
1.
Stop enter order is used in the strategy
Long enter signal is received
Enter price is 200
Stop loss price is 190
Last close is 220
To calculate size MM uses enter price (200)
Your real order fills around last close price (220)
And you end up with bigger risk then expected if stop loss is hit
When Limit order is used, similar situation can happen too
2.
There is an issue with stop loss and MM in MultiCharts
Stop loss is replaced by new stop loss every bar.
This can lead to bigger losses then expected too.
I know that these changes will lead to a very different results for old strategies.
But I see no way other to fix this.
Description changed:
I have recently faced a loss 3 times higher then a defined risk in my copy of the MultiCharts engine implemented in Backtrader engine.
I see 2 causes of this issue:
1.
Stop enter order is used in the strategy
Long enter signal is received
Enter price is 200
Stop price is 190
Last close is 220
To calculate size MM uses enter price (200)
Your real order fills around last close price (220)
And you end up with bigger risk then expected if stop is hit
When Limit order is used, similar situation can happen too
2.
There is an issue with stop loss and MM in MultiCharts
Stop loss is replaced by new stop loss every bar
So it behaves as trailing stop
This can lead to bigger losses then expected too
Also I don't see benefit of having 2 trailing stop in single strategy
I know that these changes will lead to a very different results for old strategies.
But I see no way other to fix this.
This is how I fixed issue 1 in Backtrader:
For long:
if self.order_type[s]['long']['open'] == bt.Order.Stop \
and d.close[0] > price_open:
price_open = d.close[0]
elif self.order_type[s]['long']['open'] == bt.Order.Limit \
and d.close[0] < price_open:
price_open = d.close[0]
For short:
if self.order_type[s]['short']['open'] == bt.Order.Stop \
and d.close[0] < price_open:
price_open = d.close[0]
elif self.order_type[s]['short']['open'] == bt.Order.Limit \
and d.close[0] > price_open:
price_open = d.close[0]
Status changed from New to Refused
It doesn't work only for special cases, they should be solved specially, not as a part of general SQ.
When you calculate position size and enter at stop/limit, you should check last close price to make sure that you will not get instant fill at close price instead of enter price.
To fix 2:
You need to check loss amount, and override stop loss price if loss amount is bigger than risk amount in mm.