Price Momentum Tracking Strategy
This strategy uses price momentum indicators to determine the trading direction. Specifically, it calculates the moving average and mean price respectively. When the price crosses above the moving average and mean…

Overview
This strategy uses price momentum indicators to determine the trading direction. Specifically, it calculates the moving average and mean price respectively. When the price crosses above the moving average and mean price, a buy signal is generated. To filter out false signals, it requires no similar previous signals. Then it saves the signal status and generates the final opening position signal in combination with the moving average. The strategy also contains stop loss and take profit settings.
Strategy Principle
The strategy mainly relies on price momentum indicators to judge the trend direction. First it calculates the moving average and mean price of the price:
swmaClose = swma(close)
vwapClose = vwap(close)
Where swma is the smoothed moving average and vwap is volume weighted average price. Both can reflect the average price level.
Then compare the price with the average to see if the price crosses above the moving average and mean price, to judge if it is a bullish signal:
swmaLong = close > swmaClose
vwapLong = close > vwapClose
To filter out false signals, it requires no previous signals from these two indicators:
triggerLong = vwapLong and not vwapLong[1] and not swmaLong and not swmaLong[1]
Next, save the bullish signal:
saveLong = false, saveLong := triggerLong ? true : not vwapLong ? false : saveLong[1]
Finally, when the saved crossing signal and the price crosses above the moving average again, generate the opening position signal:
startLong = saveLong and swmaLong
This can filter out some false signals and make the signals more reliable.
The strategy also contains stop loss and take profit settings. The stop loss distance is configurable, and the take profit is set to a certain multiple of the stop loss.
Advantage Analysis
The strategy has the following advantages:
- Using price momentum indicators can better judge the trend direction
- The combination of dual indicators and multi-step verification can filter false signals and make the strategy more reliable
- The stop loss and take profit settings are reasonable to control single trade risk
- The strategy parameters are configurable to adapt to different market environments
- The strategy logic is simple and straightforward, easy to understand and implement
Risk Analysis
The strategy also has some risks:
- The moving average indicator has a lag and may miss some price fluctuations
- The effect relies on parameter settings, and different parameter combinations can make big differences
- There are relatively few buy signals, with some missed trade risks
- Multi-step verification will filter some opportunities, which may impact profit level
Countermeasures:
- Test different moving average parameters for parameter optimization
- Slightly simplify the logical judgment to increase buy signals
- Adjust the stop loss and take profit ratio to control single loss
Optimization Directions
The strategy can also be optimized in the following directions:
- Test more price momentum indicators such as MACD, DMI, etc.
- Add sell signal judgments to implement dual-direction trading
- Incorporate trading volume indicators to avoid potential false breakouts
- Optimize parameter settings based on backtest results
- Consider automatically adjusting parameters based on market conditions
- Add machine learning algorithms to achieve parameter self-adaptive optimization
These optimizations can improve strategy flexibility, robustness and profitability.
Summary
Overall, this price momentum tracking strategy is a simple, straightforward and logical trend tracking strategy. The strategy uses price moving averages and mean prices to determine price momentum direction, and designs a multi-step verification mechanism to improve signal quality. The strategy also contains reasonable stop loss and take profit settings. In terms of code, the strategy logic is very concise, requiring only 20+ lines of Pine script to implement. In summary, this strategy is a very good learning example, beginners can use it as a very good starting point to understand quantitative trading strategies. Of course, the strategy itself also has practical trading value. Through parameter optimization and function expansion, it can become a practical trading system to avoid noise and track trends.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | false | Consecutive Orders |
| v_input_2 | 250 | Stop Loss |
| v_input_3 | 10 | Reward/Risk |
Source Pine Script
/*backtest
start: 2023-12-03 00:00:00
end: 2024-01-02 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title = "Simple Price Momentum", shorttitle = "SPM", overlay = true, initial_capital = 20000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value = 0.025)
// How To Create A Simple Trading Strategy With TradingView
// https://docs.google.com/document/d/1fXxCtPuGgTXb-RuBJNbwlfgkeiLTK5060LfTrzRlr5k/view
swmaClose = swma(close)
vwapClose = vwap(close)
swmaLong = close > swmaClose
vwapLong = close > vwapClose
triggerLong = vwapLong and not vwapLong[1] and not swmaLong and not swmaLong[1]
saveLong = false, saveLong := triggerLong ? true : not vwapLong ? false : saveLong[1]
startLong = saveLong and swmaLong
startLong := input(false, "Consecutive Orders") ? startLong : startLong and not startLong[1]
stopLoss = input(250, "Stop Loss", step = 50)
takeProfit = input(10, "Reward/Risk") * stopLoss
strategy.entry("Open Long", strategy.long, when = startLong)
strategy.exit("Exit Long", "Open Long", profit = stopLoss, loss = takeProfit)
// bgcolor(swmaLong ? color.blue : na)
// bgcolor(vwapLong ? color.orange : na)
// bgcolor(triggerLong ? color.purple : na)
// bgcolor(saveLong ? color.yellow : na)
bgcolor(startLong[1] ? color.green : na)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-03. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Price-Momentum-Tracking-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Advanced Multi Indicator Trend Following and Momentum Quantitative Trading StrategyPine Script · Momentum · 1h
- Intelligent Momentum Mixed Indicator Zero Day Options Strategy ModelPine Script · Momentum · 1d
- Multi Timeframe Exponential Moving Average Momentum Trading Strategy with Volume Weighted Average Price and RSI ConfirmationPine Script · Momentum · 1h
- Multi Volume Momentum Combined Trading StrategyPine Script · Momentum · 1d
- Trend Following Strategy Based on Support Resistance and Momentum Indicators Across Multiple TimeframesPine Script · Momentum · 1d
- Dynamic Trend Momentum Trading StrategyPine Script · Momentum · 4h