Strategy vault / Trend following
SMA Based Dual Thrust Strategy
This strategy builds a simple dual thrust strategy based on the SMA indicator. It goes long when the price crosses above the 20-period highest SMA and goes short when the price crosses below the 20-period lowest SMA…

Overview
This strategy builds a simple dual thrust strategy based on the SMA indicator. It goes long when the price crosses above the 20-period highest SMA and goes short when the price crosses below the 20-period lowest SMA. Stop loss exits are also set.
Strategy Logic
This strategy uses the 20-period SMA of highest high price and lowest low price to determine the direction for trading. When price crosses above the highest SMA, it is considered as an uptrend, so go long. When price crosses below the lowest SMA, it is considered as a downtrend, so go short.
Specifically, the strategy first calculates the 20-period SMA of highest high and lowest low prices, and plots the indicator lines. The following trading logic is then set:
Long entry: Close price crosses above highest SMA
Long exit: Close price crosses below 0.99 * highest SMA
Short entry: Close price crosses below lowest SMA
Short exit: Close price crosses above 1.01 * lowest SMA
So an trend following dual thrust strategy is built.
Advantage Analysis
This strategy has the following advantages:
- Using SMA to determine trend direction is simple and practical
- Highest SMA and Lowest SMA act as support/resistance lines
- Reasonable stop loss design to maximize protection from huge losses
- Good adaptability, can be used on different products and timeframes
Risk Analysis
There are also some risks with this strategy:
- SMA has lagging effect, may miss trend turning points
- No protection from market sudden events
- Trading cost impact not considered
These risks can be controlled and reduced in ways like combining other indicators, setting stop loss, parameter tuning etc.
Improvement Directions
This strategy can also be improved in the following aspects:
- Combine other indicators like MACD, KDJ to determine trend
- Add protection for sudden events like suspension, price limiting etc
- Optimize SMA periods, find the best parameter combination
- Find best parameters for different products and timeframes
- Estimate trading cost impact, set optimal stop loss and take profit
Conclusion
The overall logic of this strategy is clear and easy to implement. By using SMA to determine trend direction, and setting reasonable entry/exit rules, good results can be achieved. There is room for further optimization, and by combining with other techniques, it can become a promising strategy worth long term tracking.
Source Pine Script
/*backtest
start: 2023-11-14 00:00:00
end: 2023-11-21 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlanAntony
//@version=4
strategy("ma 20 high-low",overlay=true)
//compute the indicators
smaH = sma(high, 20)
smaL = sma(low, 20)
//plot the indicators
plot(smaH,title="smaHigh", color=color.green, linewidth=2)
plot(smaL,title="smaLow", color=color.red, linewidth=2)
//trading logic
enterlong = crossover(close,smaH) //positive ema crossover
exitlong = crossunder(close,0.99*smaH) //exiting long
entershort = crossunder(close,smaL) //negative EMA Crossover
exitshort = crossover(close,1.01*smaH) //exiting shorts
notintrade = strategy.position_size<=0
bgcolor(notintrade ? color.red:color.green)
//execution logic
start = timestamp(2015,6,1,0,0)
//end = timestamp(2022,6,1,0,0)
if time >= start
strategy.entry( "long", strategy.long,1, when = enterlong)
strategy.entry( "short", strategy.short,1, when = entershort)
strategy.close("long", when = exitlong)
strategy.close("short", when = exitshort)
//if time >= end
// strategy.close_all()Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-22. 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/SMA-Based-Dual-Thrust-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
- Fixed Range Volume Profile And Anchored VWAP Trend Identification Strategy With Dynamic Stop LossPine Script · Trend following · 1h
- Multi Indicator Dynamic Trend Following Strategy Based on EMA and SMAPine Script · Trend following · 1d
- Trend Following Strategy Based on Moving Average CrossoverPine Script · Trend following · 1d
- Trend and Moving Average Crossover Based Multi Functional Algorithmic Trading StrategyPine Script · Trend following · 1d
- High Frequency Cryptocurrency Trading Strategy Combining TrippleMACD Crossover and Relative Strength IndexPine Script · Trend following · 1h
- Trend Confirmation Tracking StrategyPine Script · Trend following · 1h