Description It's nice to quickly be able to set the backtesting period when writing strategies. To make this process faster I wrote a simple 'component'. So this is not a strategy but rather code you can plug-into your strategy and use if you need that specific functionality.
Then it's just a matter of selecting which dates you want to backtest. You can also chose to color the background to visually show the testing period. Unfortunately, the background color is fixed at 'blue' for now.
Ps. I like the idea of writing small components to be pluged into other strategies I'll try to develop this idea a bit further and see how small pieces of code can easily provide specific functionality to assist and make deving strategies a bit less 'Pineful'.
Usage First copy the instructed part of the component code over to your strategy. Next, use the testPeriod() function to limit strategies to the specified backtesting period.
Example usage: if testPeriod() strategy.entry("LE", strategy.long)
Todo / Improvements There are many ways to improve this component and I'm not a very good coder so this is a very crude solutions. Anyway, here are some things which would be nice to improve: 1. Enable color selection so that the user can choose the background color of his own liking. 2. Improve naming of variables. 3. Test for ilogical choices, such as test period start being at a later date, than test period stop. 4. Account for time zones.
As always, any feedback, corrections or thoughts are very much welcome! /pbergden
В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.
Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.