How To Set Backtest Date Range

allanster Wizard تم تحديثه   
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.


(Thanks to @Gesundheit "Adeel" for pointing me in the right direction on this!)
ملاحظات الأخبار:
Changed default settings to remove need for setting present date if backtesting up to current moment in time.
ملاحظات الأخبار:
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.
ملاحظات الأخبار:
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.
ملاحظات الأخبار:
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.
ملاحظات الأخبار:
Updated for Pine Script v4.
ملاحظات الأخبار:
Updated for Pine Script v5.
ملاحظات الأخبار:
Merged the individual inputs for year, date, and day which allows for entering of both date and time within a single input, as well as providing the additional ability of interactive selection by clicking on the indicator and then dragging vertical lines horizontally on chart. Added source inputs for the moving averages.

lux ex tenebris • deuro mea umbra absens • Telegram:
نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الكود في منشور تحكمه قواعد الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟