allanster

How To Set Backtest Date Range

Example how to select and set date range window to be backtested. Normally when you change chart period it changes the number of days being backtested which means as you increas the chart period (for example from 5min to 15min) you also increase the number of days traded, so you can not compare apples to apples for which period would yield best returns for your strategy. Now you can. Incorporate this code replacing buy and sell with your strategy, then simply input the From and To dates in Format -> Inputs, and then change the chart period to view updated results.

NOTE: There is a limit in backtesting to 2000 orders, so please be aware of this when setting your date ranges. If you set your range too high, you may be exceeding this limit on some periods and not on others, so this would yield incorrect comparison of returns per period. If you see in your backtesting results that you are nearing this limit for one of your periods you are testing, then reduce the date range to a smaller number of days.

Enjoy!

(Thanks to @Gesundheit "Adeel" for pointing me in the right direction on this!)
Nov 04
Phát hành các Ghi chú: Changed default settings to remove need for setting present date if backtesting up to current moment in time.
Apr 27
Phát hành các Ghi chú: Per requests added examples of:

- Using input statements for MA lengths.

- Using date range condition within execution.

- BONUS example of creating a function for date range.

Also added simple error checking to input statements for month and day.
Apr 27
Phát hành các Ghi chú: Added "max_bars_back=2000" in top strategy line to prevent possibility of exceeding 2000 event limit. This will prevent that error from possibly occurring.
Sep 18
Phát hành các Ghi chú: Statement in "Release Notes" immediately above is incorrect. Setting "max_bars_back=2000" in top strategy line does not prevent possibility of exceeding 2000 order limit. It instead is used to manually define how many historical bars are preloaded for indicator calculations. If you receive an ‘out of depth at index’ error this means something in your script calculations requires a certain number of historical bars and for some reason those bars were not automatically allocated. Raising this setting may help prevent that error from occurring.

For preventing the error on exceeding 2000 orders you must take steps to reduce the number of trades. Various means to do this include changing the range you are backtesting, changing the period, changing the frequency of how often your strategy trades, etc.
Gỡ bỏ khỏi Script Ưa thích Thêm vào Script Ưa thích
If you find something useful enough that you would like to buy me a refreshing beverage :)...

LTC (preferred): LTDaAe7nPzbpBhZVT9o5f9f8M3aZSPa46Y

BTC: 13LhkeXBYrRomVAqbXcoLXHuqMk6Mf7G6N

Fabulous...Thanks so much !!!
Phản hồi
Awesome, thanks, helped me a lot!
Phản hồi
allanster millioneuroman
@millioneuroman, great to hear it helped. I have a more recent example which adds the ability to also automatically set the date range back by a certain duration from the present. You can see it here...

Phản hồi
@allanster, even better, thanks a million ;)
Phản hồi
Thanks this is awesome, in v4 remove "when =" from "when = window()"
Phản hồi
allanster IsThatACat
@IsThatACat, perhaps I misunderstand your comment, but "when =" is necessary in this script regardless of whether or not you are using Pine v4. Removing 'when =" would result in a compilation error.
Phản hồi
great job it works .
Phản hồi
nice job thx
Phản hồi
Thanks so much!
You made my day <8-)
Phản hồi
doesn't work, i tried to select january to february as period but it shows nothing.
Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Shows Cách thức hoạt động Tính năng Biểu đồ Giá Quy tắc Áp dụng Người điều hành Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Trung tâm Trợ giúp Giới thiệu bạn Yêu cầu tính năng Blog & Tin tức Câu hỏi thường gặp Wiki Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Các ý tưởng đã đăng Người theo dõi Đang theo dõi Tin nhắn riêng Trò chuyện Đăng xuất