You can also configure which dates you want to backtest, so you can see how this behaves over specific time frames and market cycles.
- Update to Pine v5
- Cleaned up code
- Added a high time frame moving average filter (so you can choose to focus only on the strongest stocks with longer term uptrends).
- Added a table showing the Average Daily Range (ADR - which is equivalent to the Monthly Volatility indicator in the stock screener) to help you see how much a stock moves around on average.
- Added the ability to filter out trades that are outside of a user-defined percentage outside of the ADR to focus on better risk/reward trades.
Note, it has a bug currently - it remembers the value of the DC channel the previous time the filter was true and will make a trade based on this previous (higher) value instead of resetting. Publishing this buggy version to seek help with fixing this and to be able to reset this value when the filter turns false.
- Removed barmerge.lookahead_on from ADR calculation
- Remove resting stop order once buy conditions are no longer met. Previously this was retaining old DC levels as stop orders even when the filters were used and price went below them.
Previously, I had the Donchian channel set to the previous bar's value so that the current bar would react based on the historical bars' data. But it was causing some odd entries and exits that I didn't expect. Using the Replay feature, I realized that the historical bars don't actually update the Donchian Channel values for the current bar until it is finished (unlike in live markets where you'll see the Donchian Channel update in real time). So I've updated this code to refer to current value for the Donchian Channel instead of previous bar value. It should make the historical testing accurate to your settings now.