Whilst learning to develop algos and strategies I struggled to find examples of profitable backtests to start from. Therefore I am sharing the code from a very simple short-term momentum strategy to hopefully provide others a pace to start.
DISCLAIMER: I am providing this for educational purposes only in order to help others to have a strong starting point. There are many variables that go into a successful trading strategy, and this backtest is not tested or fit for live trading.
The Strategy Logic
Trade E-Mini futures on 1-hour bars. E-Mini futures provide us with a large amount of leverage, allowing over 1,000% returns over a 2 year backtest. The strategy will work on shorter and longer time frames with the adjustment of the variables. (DISCLAIMER: this backtest is very likely overfit and I have not conducted a walk-forward analysis, so the actual returns may be less than shown in the backtest)
Enter a long position when a longer period moving average has risen for a longer set number of bars
- We enter the market when the trend is established and rising
- The long MA allows us to stay out of the market during sharp fall offs
Close a long position when a short period moving average has fallen for a smaller set number of bars
- We close when we see the market take a quick dip
- The short MA allows us to react quickly to get out of the market with a less amount of risk
What’s not built-in:
- Commission – although this is very low per contract depending on your broker and likely will minimally affect the backtest
- Slippage – although E-Mini is the most liquid asset, 2 ticks of slippage can take away hundreds of percent of profit and significantly increase risk and drawdown.

TradingView Pinescript
Run on 1-hour bars of E-Mini (ES1)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
strategy("Short Term Momentum E-Mini", initial_capital=3000)
strategy.risk.max_intraday_filled_orders(2)
// get variables
entermavar = input(title="Enter EMA", type=input.integer, defval=100)
exitmavar = input(title="Exit EMA", type=input.integer, defval=10)
length1 = input(title="Enter Rise Length", type=input.integer, defval=6)
length2 = input(title="Exit Fall Length", type=input.integer, defval=2)
// create mas
enterma = ema(close, entermavar)
exitma = ema(close, exitmavar)
// Plot values
plot(enterma, color=color.black, linewidth=2)
plot(exitma, color=color.red, linewidth=2)
// Plot current close price
enter_trade = rising(enterma, length1)
close_trade = falling(exitma, length2)
if enter_trade and strategy.position_size <= 0
//strategy.entry("buy", strategy.long, 1, when=strategy.position_size <= 0)
strategy.entry("LONG", strategy.long)
if close_trade and strategy.position_size > 0
strategy.close("LONG")
