marketscripters

Study Backtester [MS]

Backtest your study like a strategy with our Study Backtester. Visualize your script's performance directly on the chart.

Simple to use, copy-paste a few lines of code (shown below) into your script, then set your script as input to the Study Backtester.

Visualize how your script performs against buy-and-hold over time, and get a nice print out of stats.

Settings
  • Set your buy and sell signal inputs
  • Add a stop loss
  • Choose normal or trailing stop loss
  • Choose the start date and time for backtesting
  • Set trading commissions
  • Use leverage or not
  • Set carry cost for leveraged trades

Version 1
  • Only supports buy-sell-buy-sell alternating signals. Any non-alternating signals will be ignored.
  • Testing begins with 1 share of the asset at your first buy signal.

Things To Note
  • This cannot enter or exit mid-candle. With the exception of the stop loss feature, which will calculate exits at the exact stop price.
  • Stops are not treated as stop-orders, but as market-exists at the stop (or trailing stop) price.
  • This DOES NOT take into account any loss of funds due to liquidation if price goes against you in a margin position.
  • Short positions are not currently supported.
  • Only `study` scripts are supported

How To Use
1) Add the following to the bottom your study's code.
//------------------------------------------------------------------------------
// FOR BACKTESTER
plot(buy ? 1 : sell ? -1 : na, title="Signals", display=display.none, editable=false)

2) Make sure `buy` and `sell` variables are assigned appropriately according to your strategy.
3) Add both your study and this script to your chart.
4) Set the "Signals Plot" setting of this script to: <your_study_name>: Signals
5) Adjust this script's settings (start date, commission, stoploss, etc) as necessary.

PM us with any questions about this script.

For script access or PineScript questions, please visit our site:
www.marketscripters.com?utm_source=tradingview&utm_medium=signature
Protected script
This script is published closed-source but you may use it freely. You can favorite it to use it on a chart. You cannot view or modify its source code.
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?