Tradingview: Code Snippet – Default Strategy Inputs

The code in this post contains a set of default strategy inputs I use in new projects / backtests in Tradingview. As you develop more scripts, I am sure you will notice that there are features/functions you add time and time again. I am no different in that regard. There are certain things I will always want in my strategy, either for exploration (such as testing the effect of various stops) or to limit the strategy in some way (such as setting a date range).

Default Strategy Inputs

The complete code is below. You can also find a copy of on Backtest-Rookies’ Tradingview profile here:

Code Commentary

Once you load the script and add it to the chart, you will see that there are inputs for:

  1. Trade Direction: So that you can limit the strategy for long only, short only or trade in both directions. It is important to note that when you select “Long Only”, you will still see Short signals on the chart. However, they are only used to close a position rather than reverse it. This is the default behaviour for strategies. The same applies to “Short Only”.
  2. Date Ranges: So that you can isolate backtesting to specific periods of interest such as bull or bear markets.
  3. Sessions: So you can easily get an idea of the expected results during your own session. You may also notice that performance of the strategy varies depending on which session it is deployed in.
  4. Some example stop losses: It is not an exhaustive list but it should be enough to provide some inspiration for different types of stops that you can experiment with.

When adding your strategy code, you will need to editlong_conditionandshort_conditionto meet your criterea. In addition to this, you also need to include checks for time and session using the can_trade, startandendvariables.


If you copy and paste the code, then place it on your charts, you will be able to see the inputs as follows.

I hope this can help you save some time on the mundane stuff when testing a new strategy. If you find it useful, and expand on it, please share your results with the community!

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.