Page 1 of 1

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

Posted: Tue Feb 14, 2023 12:33 pm
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

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

Posted: Tue Feb 14, 2023 2:08 pm
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

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

Posted: Tue Feb 14, 2023 5:04 pm
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!

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

Posted: Fri Feb 17, 2023 9:52 am
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