@dasch Ok, I looked into this more.
Say I have the open position:
USD/CHF 2359 Sell
But I am seeing logs like:
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 4 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0522, 06-04 01:05:00, O 0.961700, H 0.961730, L 0.961550, C 0.961560, ema_fast 0.961758, ema_mid 0.961704, ema_slow 0.961619, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, -9.999999999998899e-05 🔴, PnL -1.431505
trend=0
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 5 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0523, 06-04 01:10:00, O 0.961520, H 0.961600, L 0.961500, C 0.961530, ema_fast 0.961708, ema_mid 0.961679, ema_slow 0.961611, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, -2.999999999997449e-05 🟢, PnL -1.139425
trend=0
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 6 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0524, 06-04 01:15:00, O 0.961570, H 0.961720, L 0.961550, C 0.961720, ema_fast 0.961710, ema_mid 0.961685, ema_slow 0.961621, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, +0.00019000000000002348 🟢, PnL -2.989265
trend=0
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 7 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0525, 06-04 01:20:00, O 0.961680, H 0.961720, L 0.961600, C 0.961700, ema_fast 0.961708, ema_mid 0.961687, ema_slow 0.961628, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, -2.0000000000020002e-05 🟢, PnL -2.794545
trend=0
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 8 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0526, 06-04 01:25:00, O 0.961740, H 0.961750, L 0.961700, C 0.961750, ema_fast 0.961717, ema_mid 0.961696, ema_slow 0.961639, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, +4.999999999999449e-05 🟢, PnL -3.281345
trend=0
NO DOWNTREND, CLOSE SELL => BUY
2020-06-04: Order ref: 9 / Type Buy / Status Submitted / ExecType Market / Size 9736.0 / Alive True / Price 0.0 / Position -9736.0
LIVE, 4, Data0, 0527, 06-04 01:30:00, O 0.961700, H 0.961910, L 0.961670, C 0.961890, ema_fast 0.961756, ema_mid 0.961724, ema_slow 0.961662, C[1] 0.961660, ema_anchor_fast 0.961527, ema_anchor_slow 0.961770, ema_anchor_baseline 0.964495, +0.000140000000000029 🟢, PnL -4.644385
trend=0
NO DOWNTREND, CLOSE SELL => BUY
This is wrong because backtrader thinks I have a position -9736.0
, so it tries to buy 9736
. In reality, I have position -2359
, so it should be trying to buy 2359
.
In addition, all of these orders get canceled.
USD/CHF 9 736 Buy Market 0.96189 Cancelled 6043
USD/CHF 9 736 Buy Market 0.96190 Cancelled 6057
USD/CHF 9 736 Buy Market 0.96189 Cancelled 6063
USD/CHF 9 736 Buy Market 0.96208 Cancelled 6073
USD/CHF 9 736 Buy Market 0.96216 Cancelled 6085
So it seems I am unable to properly close positions. Backtrader appears to be storing the wrong size and the close orders get canceled.