NMFINTECHALL TOOLS ↗App source code ↗
A SIMPLE IDEA. TWO MOVING AVERAGES.

Follow the crossover.

Explore a US stock with AlgoQuant’s SMA2 strategy. Choose your window, set two moving averages, and inspect what happened.

How the strategy works ↓

Your strategy, in perspective.

Run a backtest to see prices, moving averages, portfolio value, and every execution.

POWERED BY ALGOQUANT
UNDER THE HOOD

How the SMA2 strategy works

SMA2 is a trend-following strategy using two simple moving averages of the selected stock’s daily adjusted closing prices. An N-day SMA is the arithmetic mean of the last N trading-session closes. With 10 days vs 30 days, the fast average responds to price changes more quickly than the slow average.

1. Follow the trend and crossovers

When the fast SMA crosses above the slow SMA, the target position becomes 100% of equity long. When it crosses below, the target becomes 100% of equity short. The strategy holds its position between crossovers; it does not place a new order every day. Equality alone produces no order; moving from equality to above or below can trigger one.

2. Trade on the next session

A crossover calculated from Monday’s close is executed at Tuesday’s adjusted close, or the next available trading session. The chart shows each day’s current averages, so a fill appears one session after its signal. This deliberate delay avoids filling at the same close used to discover the signal; it is not a next-open execution model. Fractional order size is calculated at that simulated fill close to reach the target exposure.

3. Size orders to reach the target

The simulation starts with $10,000 equity. At the first selected close, it enters the long/short direction indicated by the previous session’s averages. At entry and each reversal, target shares = direction × current equity ÷ the simulated fill price; fractional shares deploy the whole amount. A reversal closes the old position and opens the new one in one net order. Shares stay fixed between crossovers; there is no daily rebalancing, so exposure can drift, especially while short. Short-sale cash proceeds do not create extra equity. If equity becomes non-positive, the model closes the position and stops trading.

4. Warm up, then mark to market

Prices before the selected start date initialize the averages without making trades. On the first selected session, the pre-existing trend determines the initial entry. If the averages are equal, the account waits until a direction emerges. Subsequent position changes follow crossovers. Start and end dates are inclusive, using available trading sessions. Final open positions remain valued at the last adjusted close rather than being forcibly closed.

5. Read the results with the model’s assumptions

Portfolio value equals cash plus signed share quantity × adjusted price. Profit/loss is final portfolio value minus $10,000; total return divides that profit/loss by $10,000. There are no trading fees, bid–ask spread, slippage, short-borrow charges, margin restrictions, or interest on cash. Adjusted prices incorporate corporate-action adjustments; dividends are not paid again as separate cash flows. There is no stop-loss or take-profit rule. Moving-average strategies can suffer repeated reversals in sideways markets.

The chart’s buy-and-hold comparison invests the full $10,000 at the first selected adjusted close, then holds those fractional shares. Its return equals final adjusted close ÷ first adjusted close − 1. S&P 500 (^GSPC) runs in a separate fully funded account over the same requested dates. Its hypothetical fractional index position tracks the price index, excluding reinvested dividends. It also supplies the market series for benchmark-relative statistics.

Inspect and run the app

SMA2App.java — strategy and backtest implementation ↗

The public repository contains this app’s source. It uses the published AlgoQuant library. This educational simulation does not predict future performance.