logo
Developers

Backtest Engine

Script from: TradingViewLongTermTrend followingBotPullbackMomentumVolume

This is a simple backtest engine script designed to make testing new strategies effortless. You can customize key parameters like take profit, stop loss, and the backtest period directly in the settings. The only coding required is defining your long and short entry/exit conditions. It features an anti-duplicate system to prevent multiple entries on the same signal and allows toggling long/short orders on or off. Simply plug in your conditions and go.

Fetch.AI / TetherUS (FETUSDT)

+ Backtest Engine

@ 4 h

1.82

Risk Reward

47,789.24 %

Total ROI

80

Total Trades

BONK / TetherUS (BONKUSDT)

+ Backtest Engine

@ 4 h

1.38

Risk Reward

238.55 %

Total ROI

27

Total Trades

AVAX / TetherUS (AVAXUSDT)

+ Backtest Engine

@ 2 h

1.34

Risk Reward

1,288.00 %

Total ROI

136

Total Trades

CAKE / TetherUS (CAKEUSDT)

+ Backtest Engine

@ 15 min

1.28

Risk Reward

44.62 %

Total ROI

131

Total Trades

Cronos/Tether (CROUSDT)

+ Backtest Engine

@ 2 h

1.27

Risk Reward

891.74 %

Total ROI

155

Total Trades

Premium users only

Premium users can access all backtests with a Risk/Reward Ratio > 3

@ 4 h

3.82

Risk Reward

351.73 %

Total ROI

22

Total Trades

Premium users only

Premium users can access all backtests with a Risk/Reward Ratio > 3

@ 4 h

3.30

Risk Reward

362.66 %

Total ROI

22

Total Trades

Netflix, Inc. (NFLX)

+ Backtest Engine

@ 4 h

2.36

Risk Reward

237.09 %

Total ROI

24

Total Trades

Boeing Company (The) (BA)

+ Backtest Engine

@ 15 min

1.83

Risk Reward

233.51 %

Total ROI

104

Total Trades

Adobe Inc. (ADBE)

+ Backtest Engine

@ 15 min

1.65

Risk Reward

137.40 %

Total ROI

105

Total Trades

IREN LIMITED (IREN)

+ Backtest Engine

@ 1 h

1.46

Risk Reward

607.69 %

Total ROI

37

Total Trades

Spotify Technology S.A. (SPOT)

+ Backtest Engine

@ 2 h

1.24

Risk Reward

202.69 %

Total ROI

41

Total Trades
Create your account for free to see all 42+ backtests

Access filters, details, best timeframes, explore 100K+ backtests and more

Active Trades

Create your account to see on which symbols Backtest Engine is currently trading on.

Guide

How does the Backtest Engine strategy work ?

This script is a powerful template designed to speed up the process of backtesting your trading ideas. Instead of building a full strategy from scratch, you only need to define your specific entry and exit conditions in the code. The engine handles all the complex parts for you.

It comes with several built-in, customizable features:

  • Take Profit & Stop Loss: Set your TP and SL targets as percentages directly in the settings menu.
  • Custom Timeframe: Define the exact start date and duration for your backtest period.
  • Signal Management: Prevents opening multiple positions if your entry condition remains true over several bars, ensuring one trade per signal.

The code uses a 50/200 SMA crossover as a placeholder to demonstrate functionality. Your job is to replace these example conditions with your own custom strategy logic to see how it performs.

How to use the Backtest Engine strategy ?

This trading strategy is a classic trend-following system using a 50-period and a 200-period Simple Moving Average (SMA). It enters a long position when the faster 50 SMA crosses above the slower 200 SMA, a signal known as a "Golden Cross". Conversely, it enters a short position on a "Death Cross", when the 50 SMA crosses below the 200 SMA.

To trade this strategy manually :

  • Indicators Setup: Add two 'Moving Average, Simple' indicators to your TradingView chart. Set the length of the first one to 50 and the second one to 200.
  • Long Entry: Enter a buy order at the close of the candle where the 50 SMA line crosses above the 200 SMA line.
  • Long Exit: Close the long position when the 50 SMA crosses back below the 200 SMA.
  • Short Entry: Enter a sell (short) order at the close of the candle where the 50 SMA line crosses below the 200 SMA line.
  • Short Exit: Close the short position when the 50 SMA crosses back above the 200 SMA.

How to optimize the Backtest Engine trading strategy ?

The 50/200 SMA crossover is a classic trend-following strategy, but its primary weakness is its lagging nature, causing late entries and exits, especially in choppy, non-trending markets. To sharpen its performance for manual trading, you must add filters to improve signal quality and adopt more dynamic trade management techniques.

Here is a plan to enhance the base strategy:

  • Add a Momentum Filter: Use the Relative Strength Index (RSI) with a period of 14. For a long entry (50 SMA crosses above 200 SMA), confirm the signal by ensuring the RSI is above 50. For a short entry (50 SMA crosses below 200 SMA), the RSI should be below 50. This helps you avoid taking trades when momentum doesn't support the new trend direction.
  • Incorporate Volume Analysis: A crossover on high volume is far more significant than one on low volume. Add a 20-period moving average to your volume indicator. A valid entry signal should occur on a volume spike that is clearly above this moving average, indicating strong conviction behind the move.
  • Optimize Your Entry Point: Instead of entering immediately on the crossover, exercise patience. After a golden cross (long signal), wait for the price to pull back to the 50 SMA, which now often acts as dynamic support. Entering on this retest can provide a much better risk-to-reward ratio than chasing the initial move.
  • Use Market Structure for Stops and Targets: Do not wait for a reverse crossover to exit. For a long trade, place your stop-loss below the most recent significant swing low. For profit targets, identify upcoming resistance levels or use a measured move from a previous price swing rather than relying on a lagging exit signal. This allows you to protect capital more effectively and secure profits proactively.
  • Apply Multi-Timeframe Analysis: Before taking a trade, check the trend on a higher timeframe (e.g., if trading on the 1-hour chart, check the 4-hour or daily chart). Only take long signals if the higher timeframe is also in an uptrend (price is above its 200 SMA). This ensures you are trading in harmony with the larger market sentiment.

For which kind of traders is the Backtest Engine strategy suitable ?

This strategy is fundamentally a trend-following system, making it ideal for traders who aim to capture large, sustained market movements rather than small, quick profits. It is best suited for specific types of traders and styles:

  • Swing Traders and Position Traders: The use of long-period moving averages (50 and 200) generates infrequent signals. This aligns perfectly with trading styles that involve holding positions for several days, weeks, or even months to ride a major trend.
  • Patient and Disciplined Traders: Success requires waiting patiently for a clear crossover signal and having the discipline to stay in a trade through minor pullbacks as the larger trend unfolds.
  • Beginner Traders: Its simple, rule-based nature makes it an excellent tool for learning the principles of trend identification and disciplined execution without the complexity of faster-paced strategies.

It is not suitable for day traders or scalpers who thrive on high-frequency trading and market volatility.

Key Takeaways of Backtest Engine

Here are the key takeaways for the SMA Crossover strategy:

  • How it works: The strategy uses a 50-period and 200-period Simple Moving Average (SMA). A long signal is generated on a "Golden Cross" (50 SMA crosses above 200), and a short signal on a "Death Cross" (50 SMA crosses below 200).
  • How to use it: The provided script is a backtest engine. You can automate it, use it to generate alerts for manual confirmation, or trade the signals purely manually by placing the indicators on your chart.
  • How to enhance it: Filter signals by adding a momentum indicator like the RSI (trade only when it's above 50 for longs, below 50 for shorts) and confirming crossovers with a spike in volume.
  • How to optimize entries: For a better risk/reward ratio, wait for a pullback to the 50 SMA after a crossover before entering a trade, rather than entering immediately.
  • How to manage risk: Instead of waiting for a reverse crossover to exit, set your stop-loss below recent swing lows (for longs) or above swing highs (for shorts) and define profit targets at key price structure levels.
Explore the best Trading & TradingView strategies

Stop trading blindly. Explore the best strategies among 100K+ backtests and improve your trading skills with data.

Start for free