Order doesn't auto close (bug or user error?)

Post Reply
martinboye
Posts: 18
Joined: Sun Dec 04, 2022 2:59 pm

Order doesn't auto close (bug or user error?)

Post by martinboye »

Hi,

Can anyone help debugging why orders don't close in my automated backtesting?

I cannot find any errors in my "code", but the auto backtest doesn't behave as expected.

I created an exit rule that should close an order automatically when the current bar low breaks the low of the last 20 bars counting from the previous bar using the Donchian Channel indicator. I've attached a screenshot to illustrate. It also shows the Core rule which is used in the Exit rule.

Any ideas to what is causing my issue?

Cheers!

-Martin
Attachments
01 order should close.png
01 order should close.png (566.74 KiB) Viewed 2621 times
NakedMarkets
Posts: 248
Joined: Tue Feb 22, 2022 11:06 am

Re: Order doesn't auto close (bug or user error?)

Post by NakedMarkets »

Hello,

It looks like your core rule compares the low of the last candle (position 0) with the value of the indicator of the before last candle (position 1).
Thus, this condition is never filled since the positions of the candles are different.
If you try to set the position to 0 (lastbar) in the indicator value, it should work
martinboye
Posts: 18
Joined: Sun Dec 04, 2022 2:59 pm

Re: Order doesn't auto close (bug or user error?)

Post by martinboye »

Hi,

I tried that, but unfortunately, it doesn't help. If I set the indicator to 0, the position never closes.

With my current rule (indicator set to 1), at least the position closes, but later than expected (as illustrated in the second screenshot).

Any ideas?

Cheers!
Attachments
02 closes too late.png
02 closes too late.png (612.82 KiB) Viewed 2608 times
NakedMarkets
Posts: 248
Joined: Tue Feb 22, 2022 11:06 am

Re: Order doesn't auto close (bug or user error?)

Post by NakedMarkets »

You're using the Donchian Channel indicator, which is for the lower band, the lowest value of the candles. So, it's not possible that the low of the last can be lower than the lower Donchian Channel.
If you want to trigger the condition, you can use "less or equal" instead of "less" operator, and set the bar position to 0, not 1. Otherwise the comparison is not consistent.
Thus, this should work
Post Reply